68 lines
2.3 KiB
JavaScript
68 lines
2.3 KiB
JavaScript
/*
|
|
* ISC License
|
|
*
|
|
* Copyright (c) 2024 idnovate.com
|
|
* idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
|
|
*
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
*
|
|
* @author idnovate
|
|
* @copyright 2024 idnovate
|
|
* @license https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
|
|
*/
|
|
|
|
// Depends on coffeelint.js from http://www.coffeelint.org/js/coffeelint.js
|
|
|
|
// declare global: coffeelint
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
CodeMirror.registerHelper("lint", "coffeescript", function(text) {
|
|
var found = [];
|
|
if (!window.coffeelint) {
|
|
if (window.console) {
|
|
window.console.error("Error: window.coffeelint not defined, CodeMirror CoffeeScript linting cannot run.");
|
|
}
|
|
return found;
|
|
}
|
|
var parseError = function(err) {
|
|
var loc = err.lineNumber;
|
|
found.push({from: CodeMirror.Pos(loc-1, 0),
|
|
to: CodeMirror.Pos(loc, 0),
|
|
severity: err.level,
|
|
message: err.message});
|
|
};
|
|
try {
|
|
var res = coffeelint.lint(text);
|
|
for(var i = 0; i < res.length; i++) {
|
|
parseError(res[i]);
|
|
}
|
|
} catch(e) {
|
|
found.push({from: CodeMirror.Pos(e.location.first_line, 0),
|
|
to: CodeMirror.Pos(e.location.last_line, e.location.last_column),
|
|
severity: 'error',
|
|
message: e.message});
|
|
}
|
|
return found;
|
|
});
|
|
|
|
});
|