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.

47 lines
1.4 KiB

7 months ago
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/5/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. if (!window.coffeelint) {
  17. if (window.console) {
  18. window.console.error("Error: window.coffeelint not defined, CodeMirror CoffeeScript linting cannot run.");
  19. }
  20. return found;
  21. }
  22. var parseError = function(err) {
  23. var loc = err.lineNumber;
  24. found.push({from: CodeMirror.Pos(loc-1, 0),
  25. to: CodeMirror.Pos(loc, 0),
  26. severity: err.level,
  27. message: err.message});
  28. };
  29. try {
  30. var res = coffeelint.lint(text);
  31. for(var i = 0; i < res.length; i++) {
  32. parseError(res[i]);
  33. }
  34. } catch(e) {
  35. found.push({from: CodeMirror.Pos(e.location.first_line, 0),
  36. to: CodeMirror.Pos(e.location.last_line, e.location.last_column),
  37. severity: 'error',
  38. message: e.message});
  39. }
  40. return found;
  41. });
  42. });