LaravelTest
65 строк · 2.1 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4// Depends on jshint.js from https://github.com/jshint/jshint
5
6(function(mod) {7if (typeof exports == "object" && typeof module == "object") // CommonJS8mod(require("../../lib/codemirror"));9else if (typeof define == "function" && define.amd) // AMD10define(["../../lib/codemirror"], mod);11else // Plain browser env12mod(CodeMirror);13})(function(CodeMirror) {14"use strict";15// declare global: JSHINT16
17function validator(text, options) {18if (!window.JSHINT) {19if (window.console) {20window.console.error("Error: window.JSHINT not defined, CodeMirror JavaScript linting cannot run.");21}22return [];23}24if (!options.indent) // JSHint error.character actually is a column index, this fixes underlining on lines using tabs for indentation25options.indent = 1; // JSHint default value is 426JSHINT(text, options, options.globals);27var errors = JSHINT.data().errors, result = [];28if (errors) parseErrors(errors, result);29return result;30}31
32CodeMirror.registerHelper("lint", "javascript", validator);33
34function parseErrors(errors, output) {35for ( var i = 0; i < errors.length; i++) {36var error = errors[i];37if (error) {38if (error.line <= 0) {39if (window.console) {40window.console.warn("Cannot display JSHint error (invalid line " + error.line + ")", error);41}42continue;43}44
45var start = error.character - 1, end = start + 1;46if (error.evidence) {47var index = error.evidence.substring(start).search(/.\b/);48if (index > -1) {49end += index;50}51}52
53// Convert to format expected by validation service54var hint = {55message: error.reason,56severity: error.code ? (error.code.startsWith('W') ? "warning" : "error") : "error",57from: CodeMirror.Pos(error.line - 1, start),58to: CodeMirror.Pos(error.line - 1, end)59};60
61output.push(hint);62}63}64}65});66