You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

css-lint.js 1.3KB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. // Depends on csslint.js from https://github.com/stubbornella/csslint
  4. // declare global: CSSLint
  5. (function(mod) {
  6. if (typeof exports == "object" && typeof module == "object") // CommonJS
  7. mod(require("../../lib/codemirror"));
  8. else if (typeof define == "function" && define.amd) // AMD
  9. define(["../../lib/codemirror"], mod);
  10. else // Plain browser env
  11. mod(CodeMirror);
  12. })(function(CodeMirror) {
  13. "use strict";
  14. CodeMirror.registerHelper("lint", "css", function(text, options) {
  15. var found = [];
  16. if (!window.CSSLint) {
  17. if (window.console) {
  18. window.console.error("Error: window.CSSLint not defined, CodeMirror CSS linting cannot run.");
  19. }
  20. return found;
  21. }
  22. var results = CSSLint.verify(text, options), messages = results.messages, message = null;
  23. for ( var i = 0; i < messages.length; i++) {
  24. message = messages[i];
  25. var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col;
  26. found.push({
  27. from: CodeMirror.Pos(startLine, startCol),
  28. to: CodeMirror.Pos(endLine, endCol),
  29. message: message.message,
  30. severity : message.type
  31. });
  32. }
  33. return found;
  34. });
  35. });