forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjavascript-lint.js
More file actions
1 lines (1 loc) · 1.16 KB
/
Copy pathjavascript-lint.js
File metadata and controls
1 lines (1 loc) · 1.16 KB
1
!function(mod){"object"==typeof exports&&"object"==typeof module?mod(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],mod):mod(CodeMirror)}(function(CodeMirror){"use strict";function validator(text,options){if(!window.JSHINT)return window.console&&window.console.error("Error: window.JSHINT not defined, CodeMirror JavaScript linting cannot run."),[];options.indent||(options.indent=1),JSHINT(text,options,options.globals);var errors=JSHINT.data().errors,result=[];return errors&&parseErrors(errors,result),result}function parseErrors(errors,output){for(var i=0;i<errors.length;i++){var error=errors[i];if(error){if(error.line<=0){window.console&&window.console.warn("Cannot display JSHint error (invalid line "+error.line+")",error);continue}var start=error.character-1,end=start+1;if(error.evidence){var index=error.evidence.substring(start).search(/.\b/);index>-1&&(end+=index)}var hint={message:error.reason,severity:error.code&&error.code.startsWith("W")?"warning":"error",from:CodeMirror.Pos(error.line-1,start),to:CodeMirror.Pos(error.line-1,end)};output.push(hint)}}}CodeMirror.registerHelper("lint","javascript",validator)});