[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/vendor/codemirror/addon/lint/ -> javascript-lint.js (source)

   1  // CodeMirror, copyright (c) by Marijn Haverbeke and others
   2  // Distributed under an MIT license: https://codemirror.net/5/LICENSE
   3  
   4  // Depends on jshint.js from https://github.com/jshint/jshint
   5  
   6  (function(mod) {
   7    if (typeof exports == "object" && typeof module == "object") // CommonJS
   8      mod(require("../../lib/codemirror"));
   9    else if (typeof define == "function" && define.amd) // AMD
  10      define(["../../lib/codemirror"], mod);
  11    else // Plain browser env
  12      mod(CodeMirror);
  13  })(function(CodeMirror) {
  14    "use strict";
  15    // declare global: JSHINT
  16  
  17    function validator(text, options) {
  18      if (!window.JSHINT) {
  19        if (window.console) {
  20          window.console.error("Error: window.JSHINT not defined, CodeMirror JavaScript linting cannot run.");
  21        }
  22        return [];
  23      }
  24      if (!options.indent) // JSHint error.character actually is a column index, this fixes underlining on lines using tabs for indentation
  25        options.indent = 1; // JSHint default value is 4
  26      JSHINT(text, options, options.globals);
  27      var errors = JSHINT.data().errors, result = [];
  28      if (errors) parseErrors(errors, result);
  29      return result;
  30    }
  31  
  32    CodeMirror.registerHelper("lint", "javascript", validator);
  33  
  34    function parseErrors(errors, output) {
  35      for ( var i = 0; i < errors.length; i++) {
  36        var error = errors[i];
  37        if (error) {
  38          if (error.line <= 0) {
  39            if (window.console) {
  40              window.console.warn("Cannot display JSHint error (invalid line " + error.line + ")", error);
  41            }
  42            continue;
  43          }
  44  
  45          var start = error.character - 1, end = start + 1;
  46          if (error.evidence) {
  47            var index = error.evidence.substring(start).search(/.\b/);
  48            if (index > -1) {
  49              end += index;
  50            }
  51          }
  52  
  53          // Convert to format expected by validation service
  54          var hint = {
  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)
  59          };
  60  
  61          output.push(hint);
  62        }
  63      }
  64    }
  65  });


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer