7
if (typeof exports == "object" && typeof module == "object")
8
mod(require("../../lib/codemirror"));
9
else if (typeof define == "function" && define.amd)
10
define(["../../lib/codemirror"], mod);
13
})(function(CodeMirror) {
17
function validator(text, options) {
20
window.console.error("Error: window.JSHINT not defined, CodeMirror JavaScript linting cannot run.");
26
JSHINT(text, options, options.globals);
27
var errors = JSHINT.data().errors, result = [];
28
if (errors) parseErrors(errors, result);
32
CodeMirror.registerHelper("lint", "javascript", validator);
34
function parseErrors(errors, output) {
35
for ( var i = 0; i < errors.length; i++) {
36
var error = errors[i];
38
if (error.line <= 0) {
40
window.console.warn("Cannot display JSHint error (invalid line " + error.line + ")", error);
45
var start = error.character - 1, end = start + 1;
47
var index = error.evidence.substring(start).search(/.\b/);
55
message: error.reason,
56
severity: error.code ? (error.code.startsWith('W') ? "warning" : "error") : "error",
57
from: CodeMirror.Pos(error.line - 1, start),
58
to: CodeMirror.Pos(error.line - 1, end)