Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/addon/lint/javascript-lint.js
1293 views
(function() {1"use strict";2// declare global: JSHINT34var bogus = [ "Dangerous comment" ];56var warnings = [ [ "Expected '{'",7"Statement body should be inside '{ }' braces." ] ];89var errors = [ "Missing semicolon", "Extra comma", "Missing property name",10"Unmatched ", " and instead saw", " is not defined",11"Unclosed string", "Stopping, unable to continue" ];1213function validator(text, options) {14JSHINT(text, options);15var errors = JSHINT.data().errors, result = [];16if (errors) parseErrors(errors, result);17return result;18}1920CodeMirror.registerHelper("lint", "javascript", validator);21CodeMirror.javascriptValidator = CodeMirror.lint.javascript; // deprecated2223function cleanup(error) {24// All problems are warnings by default25fixWith(error, warnings, "warning", true);26fixWith(error, errors, "error");2728return isBogus(error) ? null : error;29}3031function fixWith(error, fixes, severity, force) {32var description, fix, find, replace, found;3334description = error.description;3536for ( var i = 0; i < fixes.length; i++) {37fix = fixes[i];38find = (typeof fix === "string" ? fix : fix[0]);39replace = (typeof fix === "string" ? null : fix[1]);40found = description.indexOf(find) !== -1;4142if (force || found) {43error.severity = severity;44}45if (found && replace) {46error.description = replace;47}48}49}5051function isBogus(error) {52var description = error.description;53for ( var i = 0; i < bogus.length; i++) {54if (description.indexOf(bogus[i]) !== -1) {55return true;56}57}58return false;59}6061function parseErrors(errors, output) {62for ( var i = 0; i < errors.length; i++) {63var error = errors[i];64if (error) {65var linetabpositions, index;6667linetabpositions = [];6869// This next block is to fix a problem in jshint. Jshint70// replaces71// all tabs with spaces then performs some checks. The error72// positions (character/space) are then reported incorrectly,73// not taking the replacement step into account. Here we look74// at the evidence line and try to adjust the character position75// to the correct value.76if (error.evidence) {77// Tab positions are computed once per line and cached78var tabpositions = linetabpositions[error.line];79if (!tabpositions) {80var evidence = error.evidence;81tabpositions = [];82// ugggh phantomjs does not like this83// forEachChar(evidence, function(item, index) {84Array.prototype.forEach.call(evidence, function(item,85index) {86if (item === '\t') {87// First col is 1 (not 0) to match error88// positions89tabpositions.push(index + 1);90}91});92linetabpositions[error.line] = tabpositions;93}94if (tabpositions.length > 0) {95var pos = error.character;96tabpositions.forEach(function(tabposition) {97if (pos > tabposition) pos -= 1;98});99error.character = pos;100}101}102103var start = error.character - 1, end = start + 1;104if (error.evidence) {105index = error.evidence.substring(start).search(/.\b/);106if (index > -1) {107end += index;108}109}110111// Convert to format expected by validation service112error.description = error.reason;// + "(jshint)";113error.start = error.character;114error.end = end;115error = cleanup(error);116117if (error)118output.push({message: error.description,119severity: error.severity,120from: CodeMirror.Pos(error.line - 1, start),121to: CodeMirror.Pos(error.line - 1, end)});122}123}124}125})();126127128