Help making my old wrapper.js work with the latest jslint.mjs #367
-
Can someone who knows a lot more about JavaScript than I do help me make this old wrapper (which worked with jslint.js) work with the latest jslint.mjs? Here is the current wrapper.js: It's usually called like this (to test file jstest.js): Much appreciated. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
here's a new #!/usr/bin/env node
/*
* wrapper2.js
*
* CommonJS command-line wrapper for jslint.mjs
*
* Example usage:
node wrapper2.js --for --long --globals=caches,indexedDb --maxerr=20 jquery.js
*/
/*jslint beta, indent2, node*/
(async function () {
var file;
var globals = [];
var jslint;
var maxerr = Infinity;
var options = {};
var result;
var source;
// Import JSLint.
jslint = await import("./jslint.mjs");
jslint = jslint.default;
// Parse process.argv.
process.argv.slice(2).forEach(function (arg) {
// Parse globals=xxx,xxx,...
if (arg.startsWith("--globals=")) {
globals = arg.replace("--globals=", "").split(",");
return;
}
// Parse maxerr=xxx.
if (arg.startsWith("--maxerr=")) {
maxerr = Number(arg.split("=")[1]);
return;
}
// Parse regular jslint options.
if (arg.startsWith("--")) {
options[arg.slice(2)] = true;
return;
}
// Parse file.
file = arg;
});
// Read file.
source = await require("fs").promises.readFile(file, "utf8");
// JSLint source.
result = jslint.jslint(source, options, globals);
// Print warnings.
result.warnings.slice(0, maxerr).forEach(function ({
column,
line,
line_source, // optional evidence
message
}, ii) {
console.error(`${ii + 1}. error, line ${line}, char ${column}:${message}`);
console.error(` evidence: ${line_source.trim().slice(0, 80)}`);
console.error();
});
}()); |
Beta Was this translation helpful? Give feedback.
here's a new
wrapper2.js
that does mostly what you want. note the old optionsindent, maxerr, maxlen, predef
were removed from jslint (since ~2015). please goto https://www.jslint.com to checkup on the latest options.