Skip to content

Commit

Permalink
- bugfix - warnings that should be ignored sometimes suppress legitim…
Browse files Browse the repository at this point in the history
…ate warnings (#409)
  • Loading branch information
kaizhu256 committed Jul 10, 2022
1 parent c25145b commit 05dc02d
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .ci.sh
Expand Up @@ -434,7 +434,7 @@ import moduleFs from "fs";
"type": "git",
"url": "https://github.com/jslint-org/jslint.git"
},
"version": "2022.7.1"
"version": "2022.7.2"
}, undefined, 4)
}
].map(async function ({
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -13,7 +13,8 @@
- jslint - add new warning "Expected Object.create(null) instead of {}"
- node - after node-v14 is deprecated, remove shell-code `export "NODE_OPTIONS=--unhandled-rejections=strict"`.

# v2022.7.1-beta
# v2022.7.2-beta
- bugfix - warnings that should be ignored sometimes suppress legitimate warnings
- doc - document jslint directives
- vscode - add extra contextmenu commands "JSLint - Do Not Lint Selected Region", "JSLint - Ignore Current Line"

Expand Down
71 changes: 63 additions & 8 deletions help.html
Expand Up @@ -381,10 +381,41 @@ <h1><code>/*jslint*/</code></h1>
globals as this directive:
<blockquote><code>/*global </code>
<div><code>
clearInterval, clearTimeout, document, event, FileReader,
FormData, history, localStorage, location, name, navigator,
screen, sessionStorage, setInterval, setTimeout, Storage,
URL, window, XMLHttpRequest
AbortController,
Blob,
Event,
EventTarget,
FileReader,
FormData,
IntersectionObserver,
MessageChannel,
MessageEvent,
MessagePort,
MutationObserver,
TextDecoder,
TextEncoder,
URL,
URLSearchParams,
WebAssembly,
Worker,
XMLHttpRequest,
clearInterval,
clearTimeout,
document,
fetch,
importScripts,
indexedDb,
localStorage,
location,
navigator,
performance,
postMessage,
queueMicrotask,
sessionStorage,
setInterval,
setTimeout,
structuredClone,
window
</code></div>
<code>*/</code></blockquote>
</td>
Expand Down Expand Up @@ -463,10 +494,34 @@ <h1><code>/*jslint*/</code></h1>
It adds the same globals as this directive:
<blockquote><code>/*global </code>
<div><code>
Buffer, clearImmediate, clearInterval, clearTimeout,
console, exports, module, process, require,
setImmediate, setInterval, setTimeout, TextDecoder,
TextEncoder, URL, URLSearchParams, __dirname, __filename
AbortController,
Buffer,
Event,
EventTarget,
MessageChannel,
MessageEvent,
MessagePort,
TextDecoder,
TextEncoder,
URL,
URLSearchParams,
WebAssembly,
__dirname,
__filename,
clearImmediate,
clearInterval,
clearTimeout,
console,
exports,
global,
module,
performance,
process,
queueMicrotask,
require,
setImmediate,
setInterval,
setTimeout
</code></div>
<code>*/</code></blockquote></td>
</tr>
Expand Down
50 changes: 39 additions & 11 deletions jslint.mjs
Expand Up @@ -153,7 +153,7 @@ let debugInline = (function () {
return argv[0];
}
debug(); // Coverage-hack.
__consoleError = console.error;
__consoleError = console.error; //jslint-ignore-line
return debug;
}());
let jslint_charset_ascii = (
Expand All @@ -165,7 +165,7 @@ let jslint_charset_ascii = (
+ "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
+ "`abcdefghijklmnopqrstuvwxyz{|}~\u007f"
);
let jslint_edition = "v2022.7.1-beta";
let jslint_edition = "v2022.7.2-beta";
let jslint_export; // The jslint object to be exported.
let jslint_fudge = 1; // Fudge starting line and starting
// ... column to 1.
Expand Down Expand Up @@ -860,11 +860,22 @@ function jslint(
c,
d
);
if (the_token.warning === undefined) {
the_token.warning = the_warning;
} else {

// Issue #408
// Warnings that should be ignored sometimes suppress legitimate warnings.

if (the_warning.directive_ignore_line) {
return the_warning;
}

// If there is already a warning on this token, suppress the new one. It is
// likely that the first warning will be the most meaningful.

if (the_token.warning) {
warning_list.pop();
return the_warning;
}
the_token.warning = the_warning;
return the_warning;
}

Expand Down Expand Up @@ -1014,6 +1025,7 @@ function jslint(
break;

// PR-347 - Disable warning "missing_browser".
//
// case "missing_browser":
// mm = `/*global*/ requires the Assume a browser option.`;
// break;
Expand Down Expand Up @@ -1098,6 +1110,7 @@ function jslint(
break;

// PR-347 - Disable warning "unexpected_directive_a".
//
// case "unexpected_directive_a":
// mm = `When using modules, don't use directive '/\u002a${a}'.`;
// break;
Expand Down Expand Up @@ -1328,6 +1341,7 @@ function jslint(
);

// PR-347 - Disable warning "missing_browser".
//
// if (!option_dict.browser) {
// directive_list.forEach(function (comment) {
// if (comment.directive === "global") {
Expand Down Expand Up @@ -2700,6 +2714,7 @@ function jslint_phase2_lex(state) {
return char_after("]");

// PR-362 - Relax regexp-warning against using <space>.
//
// case " ":
//
// // test_cause:
Expand Down Expand Up @@ -2780,6 +2795,7 @@ function jslint_phase2_lex(state) {
return;

// PR-362 - Relax regexp-warning against using <space>.
//
// case " ":
//
// // test_cause:
Expand Down Expand Up @@ -3336,12 +3352,16 @@ console.log(JSON.stringify(Object.keys(window).sort(), undefined, 4));

"AbortController",
// "Buffer",
"DOMException",
// "Crypto",
// "CryptoKey",
"Event",
"EventTarget",
"MessageChannel",
"MessageEvent",
"MessagePort",
// "Request",
// "Response",
// "SubtleCrypto",
"TextDecoder",
"TextEncoder",
"URL",
Expand All @@ -3355,7 +3375,9 @@ console.log(JSON.stringify(Object.keys(window).sort(), undefined, 4));
"clearInterval",
"clearTimeout",
// "console",
// "crypto",
// "exports",
// "fetch",
// "global",
// "module",
"performance",
Expand All @@ -3365,7 +3387,6 @@ console.log(JSON.stringify(Object.keys(window).sort(), undefined, 4));
// "setImmediate",
"setInterval",
"setTimeout",
"structuredClone",

// Web worker only.
// https://github.com/mdn/content/blob/main/files/en-us/web/api
Expand Down Expand Up @@ -3408,6 +3429,7 @@ console.log(JSON.stringify(Object.keys(window).sort(), undefined, 4));
"sessionStorage",
// "setInterval",
// "setTimeout",
"structuredClone",
"window"
], "browser");
break;
Expand Down Expand Up @@ -3469,6 +3491,7 @@ import https from "https";

case "ecma":
object_assign_from_list(global_dict, [
"AggregateError",
"Array",
"ArrayBuffer",
"Atomics",
Expand Down Expand Up @@ -3539,7 +3562,7 @@ import moduleHttps from "https";
let result = "";
await new Promise(function (resolve) {
moduleHttps.get((
"https://raw.githubusercontent.com/nodejs/node/master/doc/api"
"https://raw.githubusercontent.com/nodejs/node/v16.x/doc/api"
+ "/globals.md"
), function (res) {
res.on("data", function (chunk) {
Expand All @@ -3562,12 +3585,16 @@ import moduleHttps from "https";
object_assign_from_list(global_dict, [
"AbortController",
"Buffer",
"DOMException",
// "Crypto",
// "CryptoKey",
"Event",
"EventTarget",
"MessageChannel",
"MessageEvent",
"MessagePort",
// "Request",
// "Response",
// "SubtleCrypto",
"TextDecoder",
"TextEncoder",
"URL",
Expand All @@ -3581,7 +3608,9 @@ import moduleHttps from "https";
"clearInterval",
"clearTimeout",
"console",
// "crypto",
"exports",
// "fetch",
"global",
"module",
"performance",
Expand All @@ -3590,8 +3619,7 @@ import moduleHttps from "https";
"require",
"setImmediate",
"setInterval",
"setTimeout",
"structuredClone"
"setTimeout"
], "Node.js");
break;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -33,5 +33,5 @@
"test2": "sh jslint_ci.sh shCiBase"
},
"type": "module",
"version": "2022.7.1-beta"
"version": "2022.7.2-beta"
}

0 comments on commit 05dc02d

Please sign in to comment.