coffeescript-lint.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/LICENSE
  3. // Depends on coffeelint.js from http://www.coffeelint.org/js/coffeelint.js
  4. // declare global: coffeelint
  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", "coffeescript", function(text) {
  15. var found = [];
  16. var parseError = function(err) {
  17. var loc = err.lineNumber;
  18. found.push({from: CodeMirror.Pos(loc-1, 0),
  19. to: CodeMirror.Pos(loc, 0),
  20. severity: err.level,
  21. message: err.message});
  22. };
  23. try {
  24. var res = coffeelint.lint(text);
  25. for(var i = 0; i < res.length; i++) {
  26. parseError(res[i]);
  27. }
  28. } catch(e) {
  29. found.push({from: CodeMirror.Pos(e.location.first_line, 0),
  30. to: CodeMirror.Pos(e.location.last_line, e.location.last_column),
  31. severity: 'error',
  32. message: e.message});
  33. }
  34. return found;
  35. });
  36. });