Merge branch '2.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / codemirror / addon / lint / coffeescript-lint.js
1 // Depends on coffeelint.js from http://www.coffeelint.org/js/coffeelint.js
2
3 // declare global: coffeelint
4
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
15 CodeMirror.registerHelper("lint", "coffeescript", function(text) {
16 var found = [];
17 var parseError = function(err) {
18 var loc = err.lineNumber;
19 found.push({from: CodeMirror.Pos(loc-1, 0),
20 to: CodeMirror.Pos(loc, 0),
21 severity: err.level,
22 message: err.message});
23 };
24 try {
25 var res = coffeelint.lint(text);
26 for(var i = 0; i < res.length; i++) {
27 parseError(res[i]);
28 }
29 } catch(e) {
30 found.push({from: CodeMirror.Pos(e.location.first_line, 0),
31 to: CodeMirror.Pos(e.location.last_line, e.location.last_column),
32 severity: 'error',
33 message: e.message});
34 }
35 return found;
36 });
37
38 });