coffeescript-lint.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Depends on coffeelint.js from http://www.coffeelint.org/js/coffeelint.js
  2. // declare global: coffeelint
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. CodeMirror.registerHelper("lint", "coffeescript", function(text) {
  13. var found = [];
  14. var parseError = function(err) {
  15. var loc = err.lineNumber;
  16. found.push({from: CodeMirror.Pos(loc-1, 0),
  17. to: CodeMirror.Pos(loc, 0),
  18. severity: err.level,
  19. message: err.message});
  20. };
  21. try {
  22. var res = coffeelint.lint(text);
  23. for(var i = 0; i < res.length; i++) {
  24. parseError(res[i]);
  25. }
  26. } catch(e) {
  27. found.push({from: CodeMirror.Pos(e.location.first_line, 0),
  28. to: CodeMirror.Pos(e.location.last_line, e.location.last_column),
  29. severity: 'error',
  30. message: e.message});
  31. }
  32. return found;
  33. });
  34. });