css-lint.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://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) {
  15. var found = [];
  16. if (!window.CSSLint) return found;
  17. var results = CSSLint.verify(text), messages = results.messages, message = null;
  18. for ( var i = 0; i < messages.length; i++) {
  19. message = messages[i];
  20. var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col;
  21. found.push({
  22. from: CodeMirror.Pos(startLine, startCol),
  23. to: CodeMirror.Pos(endLine, endCol),
  24. message: message.message,
  25. severity : message.type
  26. });
  27. }
  28. return found;
  29. });
  30. });