@jslint-org/jslint 2021.10.20 → 2021.11.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +6 -0
- package/CHANGELOG.md +14 -4
- package/README.md +69 -22
- package/jslint.mjs +264 -201
- package/package.json +13 -2
- package/.gitconfig +0 -25
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -23
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -18
- package/.github/ISSUE_TEMPLATE/website_issue.md +0 -12
- package/.github/workflows/ci.yml +0 -68
- package/.github/workflows/on_pull_request.yml +0 -39
- package/.github/workflows/publish.yml +0 -68
- package/.gitignore +0 -18
- package/asset_codemirror_rollup.js +0 -11329
- package/asset_font_daley_bold.woff2 +0 -0
- package/asset_image_folder_open_solid.svg +0 -1
- package/asset_image_github_brands.svg +0 -1
- package/asset_image_jslint_vim_plugin.png +0 -0
- package/asset_image_json_160.svg +0 -104
- package/asset_image_logo_512.svg +0 -39
- package/help.html +0 -1232
- package/index.html +0 -1512
- package/jslint_ci.sh +0 -2749
- package/test.mjs +0 -937
- package/test_coverage_merge_data.json +0 -17877
package/test.mjs
DELETED
|
@@ -1,937 +0,0 @@
|
|
|
1
|
-
/*jslint beta, node*/
|
|
2
|
-
import moduleFs from "fs";
|
|
3
|
-
import jslint from "./jslint.mjs";
|
|
4
|
-
|
|
5
|
-
let {
|
|
6
|
-
assertErrorThrownAsync,
|
|
7
|
-
assertJsonEqual,
|
|
8
|
-
assertOrThrow,
|
|
9
|
-
debugInline,
|
|
10
|
-
fsRmRecursive,
|
|
11
|
-
fsWriteFileWithParents,
|
|
12
|
-
jstestDescribe,
|
|
13
|
-
jstestIt,
|
|
14
|
-
jstestOnExit,
|
|
15
|
-
noop,
|
|
16
|
-
v8CoverageListMerge,
|
|
17
|
-
v8CoverageReportCreate
|
|
18
|
-
} = jslint;
|
|
19
|
-
|
|
20
|
-
function processExit0(exitCode) {
|
|
21
|
-
assertOrThrow(exitCode === 0, exitCode);
|
|
22
|
-
}
|
|
23
|
-
function processExit1(exitCode) {
|
|
24
|
-
assertOrThrow(exitCode === 1, exitCode);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
(function testCaseFsXxx() {
|
|
28
|
-
/*
|
|
29
|
-
* this function will test fsXxx's handling-behavior
|
|
30
|
-
*/
|
|
31
|
-
// test fsRmRecursive handling-behavior
|
|
32
|
-
fsRmRecursive(".artifact/fsRmRecursive");
|
|
33
|
-
fsRmRecursive(".artifact/fsRmRecursive", {
|
|
34
|
-
process_version: "v12"
|
|
35
|
-
});
|
|
36
|
-
// test fsWriteFileWithParents handling-behavior
|
|
37
|
-
(async function () {
|
|
38
|
-
await fsRmRecursive(".tmp/fsWriteFileWithParents");
|
|
39
|
-
await fsWriteFileWithParents(
|
|
40
|
-
".tmp/fsWriteFileWithParents/aa/bb/cc",
|
|
41
|
-
"aa"
|
|
42
|
-
);
|
|
43
|
-
}());
|
|
44
|
-
}());
|
|
45
|
-
|
|
46
|
-
(function testCaseJslintCli() {
|
|
47
|
-
/*
|
|
48
|
-
* this function will test jslint's cli handling-behavior
|
|
49
|
-
*/
|
|
50
|
-
// test null-case handling-behavior
|
|
51
|
-
jslint.jslint_cli({
|
|
52
|
-
mode_noop: true,
|
|
53
|
-
process_exit: processExit0
|
|
54
|
-
});
|
|
55
|
-
[
|
|
56
|
-
".", // test dir handling-behavior
|
|
57
|
-
"jslint.mjs", // test file handling-behavior
|
|
58
|
-
undefined // test file-undefined handling-behavior
|
|
59
|
-
].forEach(function (file) {
|
|
60
|
-
jslint.jslint_cli({
|
|
61
|
-
console_error: noop, // suppress error
|
|
62
|
-
file,
|
|
63
|
-
mode_cli: true,
|
|
64
|
-
process_env: {
|
|
65
|
-
JSLINT_BETA: "1"
|
|
66
|
-
},
|
|
67
|
-
process_exit: processExit0
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
// test apidoc handling-behavior
|
|
71
|
-
jslint.jslint_cli({
|
|
72
|
-
mode_cli: true,
|
|
73
|
-
process_argv: [
|
|
74
|
-
"node",
|
|
75
|
-
"jslint.mjs",
|
|
76
|
-
"jslint_apidoc=.artifact/apidoc.html",
|
|
77
|
-
JSON.stringify({
|
|
78
|
-
example_list: [
|
|
79
|
-
"README.md",
|
|
80
|
-
"test.mjs",
|
|
81
|
-
"jslint.mjs"
|
|
82
|
-
],
|
|
83
|
-
github_repo: "https://github.com/jslint-org/jslint",
|
|
84
|
-
module_list: [
|
|
85
|
-
{
|
|
86
|
-
pathname: "./jslint.mjs"
|
|
87
|
-
}
|
|
88
|
-
],
|
|
89
|
-
package_name: "JSLint",
|
|
90
|
-
version: jslint.jslint_edition
|
|
91
|
-
})
|
|
92
|
-
],
|
|
93
|
-
process_exit: processExit0
|
|
94
|
-
});
|
|
95
|
-
// test cjs handling-behavior
|
|
96
|
-
jslint.jslint_cli({
|
|
97
|
-
cjs_module: {
|
|
98
|
-
exports: {}
|
|
99
|
-
},
|
|
100
|
-
cjs_require: {},
|
|
101
|
-
process_exit: processExit0
|
|
102
|
-
});
|
|
103
|
-
// test file-error handling-behavior
|
|
104
|
-
jslint.jslint_cli({
|
|
105
|
-
// suppress error
|
|
106
|
-
console_error: noop,
|
|
107
|
-
file: "undefined",
|
|
108
|
-
mode_cli: true,
|
|
109
|
-
process_exit: processExit1
|
|
110
|
-
});
|
|
111
|
-
// test syntax-error handling-behavior
|
|
112
|
-
jslint.jslint_cli({
|
|
113
|
-
// suppress error
|
|
114
|
-
console_error: noop,
|
|
115
|
-
file: "syntax-error.js",
|
|
116
|
-
mode_cli: true,
|
|
117
|
-
option: {
|
|
118
|
-
trace: true
|
|
119
|
-
},
|
|
120
|
-
process_exit: processExit1,
|
|
121
|
-
source: "syntax error"
|
|
122
|
-
});
|
|
123
|
-
// test report handling-behavior
|
|
124
|
-
jslint.jslint_cli({
|
|
125
|
-
// suppress error
|
|
126
|
-
console_error: noop,
|
|
127
|
-
mode_cli: true,
|
|
128
|
-
process_argv: [
|
|
129
|
-
"node",
|
|
130
|
-
"jslint.mjs",
|
|
131
|
-
"jslint_report=.tmp/jslint_report.html",
|
|
132
|
-
"jslint.mjs"
|
|
133
|
-
],
|
|
134
|
-
process_exit: processExit0
|
|
135
|
-
});
|
|
136
|
-
// test report-error handling-behavior
|
|
137
|
-
jslint.jslint_cli({
|
|
138
|
-
// suppress error
|
|
139
|
-
console_error: noop,
|
|
140
|
-
mode_cli: true,
|
|
141
|
-
process_argv: [
|
|
142
|
-
"node",
|
|
143
|
-
"jslint.mjs",
|
|
144
|
-
"jslint_report=.tmp/jslint_report.html",
|
|
145
|
-
"syntax-error.js"
|
|
146
|
-
],
|
|
147
|
-
process_exit: processExit1,
|
|
148
|
-
source: "syntax error"
|
|
149
|
-
});
|
|
150
|
-
// test report-json handling-behavior
|
|
151
|
-
jslint.jslint_cli({
|
|
152
|
-
// suppress error
|
|
153
|
-
console_error: noop,
|
|
154
|
-
mode_cli: true,
|
|
155
|
-
process_argv: [
|
|
156
|
-
"node",
|
|
157
|
-
"jslint.mjs",
|
|
158
|
-
"jslint_report=.tmp/jslint_report.html",
|
|
159
|
-
"aa.json"
|
|
160
|
-
],
|
|
161
|
-
process_exit: processExit0,
|
|
162
|
-
source: "[]"
|
|
163
|
-
});
|
|
164
|
-
// test report-misc handling-behavior
|
|
165
|
-
jslint.jslint_cli({
|
|
166
|
-
// suppress error
|
|
167
|
-
console_error: noop,
|
|
168
|
-
mode_cli: true,
|
|
169
|
-
process_argv: [
|
|
170
|
-
"node",
|
|
171
|
-
"jslint.mjs",
|
|
172
|
-
"jslint_report=.tmp/jslint_report.html",
|
|
173
|
-
"aa.js"
|
|
174
|
-
],
|
|
175
|
-
process_exit: processExit1,
|
|
176
|
-
source: "(aa)=>aa; function aa([aa]){}"
|
|
177
|
-
});
|
|
178
|
-
// test report-json-error handling-behavior
|
|
179
|
-
jslint.jslint_cli({
|
|
180
|
-
// suppress error
|
|
181
|
-
console_error: noop,
|
|
182
|
-
mode_cli: true,
|
|
183
|
-
process_argv: [
|
|
184
|
-
"node",
|
|
185
|
-
"jslint.mjs",
|
|
186
|
-
"jslint_report=.tmp/jslint_report.html",
|
|
187
|
-
"aa.json"
|
|
188
|
-
],
|
|
189
|
-
process_exit: processExit1,
|
|
190
|
-
source: "["
|
|
191
|
-
});
|
|
192
|
-
// test plugin-vim handling-behavior
|
|
193
|
-
jslint.jslint_cli({
|
|
194
|
-
// suppress error
|
|
195
|
-
console_error: noop,
|
|
196
|
-
mode_cli: true,
|
|
197
|
-
process_argv: [
|
|
198
|
-
"node",
|
|
199
|
-
"jslint.mjs",
|
|
200
|
-
"jslint_plugin_vim",
|
|
201
|
-
"syntax-error.js"
|
|
202
|
-
],
|
|
203
|
-
process_exit: processExit1,
|
|
204
|
-
source: "syntax error"
|
|
205
|
-
});
|
|
206
|
-
}());
|
|
207
|
-
|
|
208
|
-
(function testCaseJslintCodeValidate() {
|
|
209
|
-
/*
|
|
210
|
-
* this function will validate each code is valid in jslint
|
|
211
|
-
*/
|
|
212
|
-
Object.values({
|
|
213
|
-
array: [
|
|
214
|
-
"new Array(0);"
|
|
215
|
-
],
|
|
216
|
-
async_await: [
|
|
217
|
-
"async function aa() {\n await aa();\n}",
|
|
218
|
-
(
|
|
219
|
-
"async function aa() {\n"
|
|
220
|
-
+ " try {\n"
|
|
221
|
-
+ " aa();\n"
|
|
222
|
-
+ " } catch (err) {\n"
|
|
223
|
-
+ " await err();\n"
|
|
224
|
-
+ " }\n"
|
|
225
|
-
+ "}\n"
|
|
226
|
-
), (
|
|
227
|
-
"async function aa() {\n"
|
|
228
|
-
+ " try {\n"
|
|
229
|
-
+ " await aa();\n"
|
|
230
|
-
+ " } catch (err) {\n"
|
|
231
|
-
+ " await err();\n"
|
|
232
|
-
+ " }\n"
|
|
233
|
-
+ "}\n"
|
|
234
|
-
)
|
|
235
|
-
],
|
|
236
|
-
|
|
237
|
-
// PR-351 - Add BigInt support.
|
|
238
|
-
|
|
239
|
-
bigint: [
|
|
240
|
-
"let aa = 0b0n;\n",
|
|
241
|
-
"let aa = 0o0n;\n",
|
|
242
|
-
"let aa = 0x0n;\n",
|
|
243
|
-
"let aa = BigInt(0n);\n",
|
|
244
|
-
"let aa = typeof aa === \"bigint\";\n"
|
|
245
|
-
],
|
|
246
|
-
date: [
|
|
247
|
-
"Date.getTime();",
|
|
248
|
-
"let aa = aa().getTime();",
|
|
249
|
-
"let aa = aa.aa().getTime();"
|
|
250
|
-
],
|
|
251
|
-
directive: [
|
|
252
|
-
"#!\n/*jslint browser:false, node*/\n\"use strict\";",
|
|
253
|
-
"/*property aa bb*/"
|
|
254
|
-
],
|
|
255
|
-
fart: [
|
|
256
|
-
"function aa() {\n return () => 0;\n}"
|
|
257
|
-
],
|
|
258
|
-
for: [
|
|
259
|
-
(
|
|
260
|
-
"/*jslint for*/\n"
|
|
261
|
-
+ "function aa(bb) {\n"
|
|
262
|
-
+ " for (bb = 0; bb < 0; bb += 1) {\n"
|
|
263
|
-
+ " bb();\n"
|
|
264
|
-
+ " }\n"
|
|
265
|
-
+ "}\n"
|
|
266
|
-
)
|
|
267
|
-
],
|
|
268
|
-
jslint_disable: [
|
|
269
|
-
"/*jslint-disable*/\n0\n/*jslint-enable*/"
|
|
270
|
-
],
|
|
271
|
-
jslint_quiet: [
|
|
272
|
-
"0 //jslint-quiet"
|
|
273
|
-
],
|
|
274
|
-
json: [
|
|
275
|
-
"{\"aa\":[[],-0,null]}"
|
|
276
|
-
],
|
|
277
|
-
label: [
|
|
278
|
-
(
|
|
279
|
-
"function aa() {\n"
|
|
280
|
-
+ "bb:\n"
|
|
281
|
-
+ " while (true) {\n"
|
|
282
|
-
+ " if (true) {\n"
|
|
283
|
-
+ " break bb;\n"
|
|
284
|
-
+ " }\n"
|
|
285
|
-
+ " }\n"
|
|
286
|
-
+ "}\n"
|
|
287
|
-
)
|
|
288
|
-
],
|
|
289
|
-
loop: [
|
|
290
|
-
"function aa() {\n do {\n aa();\n } while (aa());\n}"
|
|
291
|
-
],
|
|
292
|
-
module: [
|
|
293
|
-
"export default Object.freeze();",
|
|
294
|
-
"import {aa, bb} from \"aa\";\naa(bb);",
|
|
295
|
-
"import {} from \"aa\";",
|
|
296
|
-
"import(\"aa\").then(function () {\n return;\n});",
|
|
297
|
-
"let aa = 0;\nimport(aa).then(aa).then(aa).catch(aa).finally(aa);"
|
|
298
|
-
],
|
|
299
|
-
number: [
|
|
300
|
-
"let aa = 0.0e0;",
|
|
301
|
-
"let aa = 0b0;",
|
|
302
|
-
"let aa = 0o0;",
|
|
303
|
-
"let aa = 0x0;"
|
|
304
|
-
],
|
|
305
|
-
optional_chaining: [
|
|
306
|
-
"let aa = aa?.bb?.cc;"
|
|
307
|
-
],
|
|
308
|
-
param: [
|
|
309
|
-
(
|
|
310
|
-
"function aa({aa, bb}) {\n"
|
|
311
|
-
+ " return {aa, bb};\n"
|
|
312
|
-
+ "}\n"
|
|
313
|
-
), (
|
|
314
|
-
"function aa({constructor}) {\n"
|
|
315
|
-
+ " return {constructor};\n"
|
|
316
|
-
+ "}\n"
|
|
317
|
-
)
|
|
318
|
-
],
|
|
319
|
-
property: [
|
|
320
|
-
"let aa = aa[`!`];"
|
|
321
|
-
],
|
|
322
|
-
regexp: [
|
|
323
|
-
"function aa() {\n return /./;\n}",
|
|
324
|
-
"let aa = /(?!.)(?:.)(?=.)/;",
|
|
325
|
-
"let aa = /./gimuy;",
|
|
326
|
-
"let aa = /[\\--\\-]/;"
|
|
327
|
-
],
|
|
328
|
-
ternary: [
|
|
329
|
-
(
|
|
330
|
-
"let aa = (\n aa()\n ? 0\n : 1\n) "
|
|
331
|
-
+ "&& (\n aa()\n ? 0\n : 1\n);"
|
|
332
|
-
),
|
|
333
|
-
"let aa = (\n aa()\n ? `${0}`\n : `${1}`\n);"
|
|
334
|
-
],
|
|
335
|
-
try_catch: [
|
|
336
|
-
(
|
|
337
|
-
"let aa = 0;\n"
|
|
338
|
-
+ "try {\n"
|
|
339
|
-
+ " aa();\n"
|
|
340
|
-
+ "} catch (err) {\n"
|
|
341
|
-
+ " aa = err;\n"
|
|
342
|
-
+ "}\n"
|
|
343
|
-
+ "try {\n"
|
|
344
|
-
+ " aa();\n"
|
|
345
|
-
+ "} catch (err) {\n"
|
|
346
|
-
+ " aa = err;\n"
|
|
347
|
-
+ "}\n"
|
|
348
|
-
+ "aa();\n"
|
|
349
|
-
)
|
|
350
|
-
],
|
|
351
|
-
use_strict: [
|
|
352
|
-
(
|
|
353
|
-
"\"use strict\";\n"
|
|
354
|
-
+ "let aa = 0;\n"
|
|
355
|
-
+ "function bb() {\n"
|
|
356
|
-
+ " \"use strict\";\n"
|
|
357
|
-
+ " return aa;\n"
|
|
358
|
-
+ "}\n"
|
|
359
|
-
)
|
|
360
|
-
],
|
|
361
|
-
var: [
|
|
362
|
-
|
|
363
|
-
// PR-363 - Bugfix - add test against false-warning
|
|
364
|
-
// <uninitialized 'bb'> in code '/*jslint node*/\nlet {aa:bb} = {}; bb();'
|
|
365
|
-
|
|
366
|
-
"/*jslint node*/\n",
|
|
367
|
-
""
|
|
368
|
-
].map(function (directive) {
|
|
369
|
-
return [
|
|
370
|
-
"let [\n aa, bb = 0\n] = 0;\naa();\nbb();",
|
|
371
|
-
"let [...aa] = [...aa];\naa();",
|
|
372
|
-
"let constructor = 0;\nconstructor();",
|
|
373
|
-
"let {\n aa: bb\n} = 0;\nbb();",
|
|
374
|
-
"let {\n aa: bb,\n bb: cc\n} = 0;\nbb();\ncc();",
|
|
375
|
-
"let {aa, bb} = 0;\naa();\nbb();",
|
|
376
|
-
"let {constructor} = 0;\nconstructor();"
|
|
377
|
-
].map(function (code) {
|
|
378
|
-
return directive + code;
|
|
379
|
-
});
|
|
380
|
-
}).flat()
|
|
381
|
-
}).forEach(function (codeList) {
|
|
382
|
-
let elemPrv = "";
|
|
383
|
-
codeList.forEach(function (code) {
|
|
384
|
-
let warnings;
|
|
385
|
-
// Assert codeList is sorted.
|
|
386
|
-
assertOrThrow(elemPrv < code, JSON.stringify([
|
|
387
|
-
elemPrv, code
|
|
388
|
-
], undefined, 4));
|
|
389
|
-
elemPrv = code;
|
|
390
|
-
warnings = jslint.jslint(code, {
|
|
391
|
-
beta: true
|
|
392
|
-
}).warnings;
|
|
393
|
-
assertOrThrow(
|
|
394
|
-
warnings.length === 0,
|
|
395
|
-
JSON.stringify([code, warnings])
|
|
396
|
-
);
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
}());
|
|
400
|
-
|
|
401
|
-
(async function testCaseJslintOption() {
|
|
402
|
-
/*
|
|
403
|
-
* this function will test jslint's option handling-behavior
|
|
404
|
-
*/
|
|
405
|
-
let elemPrv = "";
|
|
406
|
-
[
|
|
407
|
-
[
|
|
408
|
-
"let aa = aa | 0;", {bitwise: true}, []
|
|
409
|
-
], [
|
|
410
|
-
";\naa(new XMLHttpRequest());", {browser: true}, ["aa"]
|
|
411
|
-
], [
|
|
412
|
-
"let aa = \"aa\" + 0;", {convert: true}, []
|
|
413
|
-
], [
|
|
414
|
-
"registerType();", {couch: true}, []
|
|
415
|
-
], [
|
|
416
|
-
"debugger;", {devel: true}, []
|
|
417
|
-
], [
|
|
418
|
-
"new Function();\neval();", {eval: true}, []
|
|
419
|
-
], [
|
|
420
|
-
(
|
|
421
|
-
"function aa(aa) {\n"
|
|
422
|
-
+ " for (aa = 0; aa < 0; aa += 1) {\n"
|
|
423
|
-
+ " aa();\n"
|
|
424
|
-
+ " }\n"
|
|
425
|
-
+ "}\n"
|
|
426
|
-
), {for: true}, []
|
|
427
|
-
], [
|
|
428
|
-
"let aa = {get aa() {\n return;\n}};", {getset: true}, []
|
|
429
|
-
], [
|
|
430
|
-
"let aa = {set aa(aa) {\n return aa;\n}};", {getset: true}, []
|
|
431
|
-
], [
|
|
432
|
-
String(
|
|
433
|
-
await moduleFs.promises.readFile("jslint.mjs", "utf8")
|
|
434
|
-
).replace((
|
|
435
|
-
/ /g
|
|
436
|
-
), " "),
|
|
437
|
-
{indent2: true},
|
|
438
|
-
[]
|
|
439
|
-
], [
|
|
440
|
-
"function aa() {\n return;\n}", {indent2: true}, []
|
|
441
|
-
], [
|
|
442
|
-
"/".repeat(100), {long: true}, []
|
|
443
|
-
], [
|
|
444
|
-
"let aa = aa._;", {name: true}, []
|
|
445
|
-
], [
|
|
446
|
-
"require();", {node: true}, []
|
|
447
|
-
], [
|
|
448
|
-
"let aa = 'aa';", {single: true}, []
|
|
449
|
-
], [
|
|
450
|
-
"let aa = this;", {this: true}, []
|
|
451
|
-
], [
|
|
452
|
-
"", {trace: true}, []
|
|
453
|
-
], [
|
|
454
|
-
(
|
|
455
|
-
"function aa({bb, aa}) {\n"
|
|
456
|
-
+ " switch (aa) {\n"
|
|
457
|
-
+ " case 1:\n"
|
|
458
|
-
+ " break;\n"
|
|
459
|
-
+ " case 0:\n"
|
|
460
|
-
+ " break;\n"
|
|
461
|
-
+ " default:\n"
|
|
462
|
-
+ " return {bb, aa};\n"
|
|
463
|
-
+ " }\n"
|
|
464
|
-
+ "}\n"
|
|
465
|
-
), {unordered: true}, []
|
|
466
|
-
], [
|
|
467
|
-
"let {bb, aa} = 0;", {unordered: true}, []
|
|
468
|
-
], [
|
|
469
|
-
(
|
|
470
|
-
"function aa() {\n"
|
|
471
|
-
+ " if (aa) {\n"
|
|
472
|
-
+ " let bb = 0;\n"
|
|
473
|
-
+ " return bb;\n"
|
|
474
|
-
+ " }\n"
|
|
475
|
-
+ "}\n"
|
|
476
|
-
), {variable: true}, []
|
|
477
|
-
], [
|
|
478
|
-
"let bb = 0;\nlet aa = 0;", {variable: true}, []
|
|
479
|
-
], [
|
|
480
|
-
"\t", {white: true}, []
|
|
481
|
-
]
|
|
482
|
-
].forEach(function ([
|
|
483
|
-
source, option_dict, global_list
|
|
484
|
-
]) {
|
|
485
|
-
let elemNow = JSON.stringify([
|
|
486
|
-
option_dict, source, global_list
|
|
487
|
-
]);
|
|
488
|
-
// Assert list is sorted.
|
|
489
|
-
assertOrThrow(elemPrv < elemNow, JSON.stringify([
|
|
490
|
-
elemPrv, elemNow
|
|
491
|
-
], undefined, 4));
|
|
492
|
-
elemPrv = elemNow;
|
|
493
|
-
option_dict.beta = true;
|
|
494
|
-
// test jslint's option handling-behavior
|
|
495
|
-
assertOrThrow(
|
|
496
|
-
jslint.jslint(
|
|
497
|
-
source,
|
|
498
|
-
option_dict,
|
|
499
|
-
global_list
|
|
500
|
-
).warnings.length === 0,
|
|
501
|
-
"jslint.jslint(" + JSON.stringify([
|
|
502
|
-
source, option_dict, global_list
|
|
503
|
-
]) + ")"
|
|
504
|
-
);
|
|
505
|
-
// test jslint's directive handling-behavior
|
|
506
|
-
source = (
|
|
507
|
-
"/*jslint " + JSON.stringify(option_dict).slice(1, -1).replace((
|
|
508
|
-
/"/g
|
|
509
|
-
), "") + "*/\n"
|
|
510
|
-
+ (
|
|
511
|
-
global_list.length === 0
|
|
512
|
-
? ""
|
|
513
|
-
: "/*global " + global_list.join(",") + "*/\n"
|
|
514
|
-
)
|
|
515
|
-
+ source.replace((
|
|
516
|
-
/^#!/
|
|
517
|
-
), "//")
|
|
518
|
-
);
|
|
519
|
-
assertOrThrow(jslint.jslint(source).warnings.length === 0, source);
|
|
520
|
-
});
|
|
521
|
-
assertOrThrow(jslint.jslint("", {
|
|
522
|
-
test_internal_error: true
|
|
523
|
-
}).warnings.length === 1);
|
|
524
|
-
}());
|
|
525
|
-
|
|
526
|
-
(async function testCaseJslintWarningsValidate() {
|
|
527
|
-
/*
|
|
528
|
-
* this function will validate each jslint <warning> is raised with given
|
|
529
|
-
* malformed <code>
|
|
530
|
-
*/
|
|
531
|
-
String(
|
|
532
|
-
await moduleFs.promises.readFile("jslint.mjs", "utf8")
|
|
533
|
-
).replace((
|
|
534
|
-
/(\n\s*?\/\/\s*?test_cause:\s*?)(\S[\S\s]*?\S)(\n\n\s*?) *?\S/g
|
|
535
|
-
), function (match0, header, causeList, footer) {
|
|
536
|
-
let tmp;
|
|
537
|
-
// console.error(match0);
|
|
538
|
-
// Validate header.
|
|
539
|
-
assertOrThrow(header === "\n\n// test_cause:\n", match0);
|
|
540
|
-
// Validate footer.
|
|
541
|
-
assertOrThrow(footer === "\n\n", match0);
|
|
542
|
-
// Validate causeList.
|
|
543
|
-
causeList = causeList.replace((
|
|
544
|
-
/^\/\/ /gm
|
|
545
|
-
), "").replace((
|
|
546
|
-
/^\["\n([\S\s]*?)\n"(,.*?)$/gm
|
|
547
|
-
), function (ignore, source, param) {
|
|
548
|
-
source = "[" + JSON.stringify(source) + param;
|
|
549
|
-
assertOrThrow(source.length > (80 - 3), source);
|
|
550
|
-
return source;
|
|
551
|
-
}).replace((
|
|
552
|
-
/ \/\/jslint-quiet$/gm
|
|
553
|
-
), "");
|
|
554
|
-
tmp = causeList.split("\n").map(function (cause) {
|
|
555
|
-
return (
|
|
556
|
-
"["
|
|
557
|
-
+ JSON.parse(cause).map(function (elem) {
|
|
558
|
-
return JSON.stringify(elem);
|
|
559
|
-
}).join(", ")
|
|
560
|
-
+ "]"
|
|
561
|
-
);
|
|
562
|
-
}).sort().join("\n");
|
|
563
|
-
assertOrThrow(causeList === tmp, "\n" + causeList + "\n\n" + tmp);
|
|
564
|
-
causeList.split("\n").forEach(function (cause) {
|
|
565
|
-
cause = JSON.parse(cause);
|
|
566
|
-
tmp = jslint.jslint(cause[0], {
|
|
567
|
-
beta: true,
|
|
568
|
-
test_cause: true
|
|
569
|
-
}).causes;
|
|
570
|
-
// Validate cause.
|
|
571
|
-
assertOrThrow(
|
|
572
|
-
tmp[JSON.stringify(cause.slice(1))],
|
|
573
|
-
(
|
|
574
|
-
"\n" + JSON.stringify(cause) + "\n\n"
|
|
575
|
-
+ Object.keys(tmp).sort().join("\n")
|
|
576
|
-
)
|
|
577
|
-
);
|
|
578
|
-
});
|
|
579
|
-
return "";
|
|
580
|
-
});
|
|
581
|
-
}());
|
|
582
|
-
|
|
583
|
-
(async function testCaseMisc() {
|
|
584
|
-
/*
|
|
585
|
-
* this function will test misc handling-behavior
|
|
586
|
-
*/
|
|
587
|
-
// test debugInline's handling-behavior
|
|
588
|
-
noop(debugInline);
|
|
589
|
-
// test assertErrorThrownAsync's error handling-behavior
|
|
590
|
-
await assertErrorThrownAsync(function () {
|
|
591
|
-
return assertErrorThrownAsync(noop);
|
|
592
|
-
});
|
|
593
|
-
// test assertJsonEqual's error handling-behavior
|
|
594
|
-
await assertErrorThrownAsync(function () {
|
|
595
|
-
assertJsonEqual(1, 2);
|
|
596
|
-
});
|
|
597
|
-
// test assertOrThrow's error handling-behavior
|
|
598
|
-
await assertErrorThrownAsync(function () {
|
|
599
|
-
assertOrThrow(undefined, "undefined");
|
|
600
|
-
});
|
|
601
|
-
await assertErrorThrownAsync(function () {
|
|
602
|
-
assertOrThrow(undefined, new Error());
|
|
603
|
-
});
|
|
604
|
-
}());
|
|
605
|
-
|
|
606
|
-
(async function () {
|
|
607
|
-
let testCoverageMergeData = JSON.parse(
|
|
608
|
-
await moduleFs.promises.readFile(
|
|
609
|
-
"test_coverage_merge_data.json",
|
|
610
|
-
"utf8"
|
|
611
|
-
)
|
|
612
|
-
);
|
|
613
|
-
|
|
614
|
-
jstestDescribe((
|
|
615
|
-
"test jstestXxx's handling-behavior"
|
|
616
|
-
), function () {
|
|
617
|
-
jstestIt((
|
|
618
|
-
"test jstestDescribe's error handling-behavior"
|
|
619
|
-
), function () {
|
|
620
|
-
throw new Error();
|
|
621
|
-
}, "pass");
|
|
622
|
-
jstestIt((
|
|
623
|
-
"test jstestOnExit's error handling-behavior"
|
|
624
|
-
), function () {
|
|
625
|
-
jstestOnExit(undefined, noop, 1);
|
|
626
|
-
});
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
jstestDescribe((
|
|
630
|
-
"test v8CoverageListMerge's handling-behavior"
|
|
631
|
-
), function () {
|
|
632
|
-
let functionsExpected = JSON.stringify([
|
|
633
|
-
{
|
|
634
|
-
functionName: "test",
|
|
635
|
-
isBlockCoverage: true,
|
|
636
|
-
ranges: [
|
|
637
|
-
{
|
|
638
|
-
count: 2,
|
|
639
|
-
endOffset: 4,
|
|
640
|
-
startOffset: 0
|
|
641
|
-
},
|
|
642
|
-
{
|
|
643
|
-
count: 1,
|
|
644
|
-
endOffset: 3,
|
|
645
|
-
startOffset: 1
|
|
646
|
-
}
|
|
647
|
-
]
|
|
648
|
-
}
|
|
649
|
-
]);
|
|
650
|
-
let functionsInput = JSON.stringify([
|
|
651
|
-
{
|
|
652
|
-
functionName: "test",
|
|
653
|
-
isBlockCoverage: true,
|
|
654
|
-
ranges: [
|
|
655
|
-
{
|
|
656
|
-
count: 2,
|
|
657
|
-
endOffset: 4,
|
|
658
|
-
startOffset: 0
|
|
659
|
-
},
|
|
660
|
-
{
|
|
661
|
-
count: 1,
|
|
662
|
-
endOffset: 2,
|
|
663
|
-
startOffset: 1
|
|
664
|
-
},
|
|
665
|
-
{
|
|
666
|
-
count: 1,
|
|
667
|
-
endOffset: 3,
|
|
668
|
-
startOffset: 2
|
|
669
|
-
}
|
|
670
|
-
]
|
|
671
|
-
}
|
|
672
|
-
]);
|
|
673
|
-
jstestIt((
|
|
674
|
-
"accepts empty arrays for `v8CoverageListMerge`"
|
|
675
|
-
), function () {
|
|
676
|
-
assertJsonEqual(v8CoverageListMerge([]), {
|
|
677
|
-
result: []
|
|
678
|
-
});
|
|
679
|
-
});
|
|
680
|
-
jstestIt((
|
|
681
|
-
"funcCovs.length === 1"
|
|
682
|
-
), function () {
|
|
683
|
-
assertJsonEqual(v8CoverageListMerge([
|
|
684
|
-
{
|
|
685
|
-
result: [
|
|
686
|
-
{
|
|
687
|
-
functions: [
|
|
688
|
-
{
|
|
689
|
-
functionName: "test",
|
|
690
|
-
isBlockCoverage: true,
|
|
691
|
-
ranges: [
|
|
692
|
-
{
|
|
693
|
-
count: 2,
|
|
694
|
-
endOffset: 4,
|
|
695
|
-
startOffset: 0
|
|
696
|
-
}
|
|
697
|
-
]
|
|
698
|
-
}
|
|
699
|
-
],
|
|
700
|
-
moduleUrl: "/lib.js",
|
|
701
|
-
scriptId: "1"
|
|
702
|
-
}
|
|
703
|
-
]
|
|
704
|
-
},
|
|
705
|
-
{
|
|
706
|
-
result: [
|
|
707
|
-
{
|
|
708
|
-
functions: [],
|
|
709
|
-
moduleUrl: "/lib.js",
|
|
710
|
-
scriptId: "2"
|
|
711
|
-
}
|
|
712
|
-
]
|
|
713
|
-
}
|
|
714
|
-
]), {
|
|
715
|
-
result: [
|
|
716
|
-
{
|
|
717
|
-
functions: [
|
|
718
|
-
{
|
|
719
|
-
functionName: "test",
|
|
720
|
-
isBlockCoverage: true,
|
|
721
|
-
ranges: [
|
|
722
|
-
{
|
|
723
|
-
count: 2,
|
|
724
|
-
endOffset: 4,
|
|
725
|
-
startOffset: 0
|
|
726
|
-
}
|
|
727
|
-
]
|
|
728
|
-
}
|
|
729
|
-
],
|
|
730
|
-
scriptId: "0"
|
|
731
|
-
}
|
|
732
|
-
]
|
|
733
|
-
});
|
|
734
|
-
});
|
|
735
|
-
jstestIt((
|
|
736
|
-
"accepts arrays with a single item for `v8CoverageListMerge`"
|
|
737
|
-
), function () {
|
|
738
|
-
assertJsonEqual(v8CoverageListMerge([
|
|
739
|
-
{
|
|
740
|
-
result: [
|
|
741
|
-
{
|
|
742
|
-
functions: JSON.parse(functionsInput),
|
|
743
|
-
moduleUrl: "/lib.js",
|
|
744
|
-
scriptId: "123"
|
|
745
|
-
}
|
|
746
|
-
]
|
|
747
|
-
}
|
|
748
|
-
]), {
|
|
749
|
-
result: [
|
|
750
|
-
{
|
|
751
|
-
functions: JSON.parse(functionsExpected),
|
|
752
|
-
moduleUrl: "/lib.js",
|
|
753
|
-
scriptId: "0"
|
|
754
|
-
}
|
|
755
|
-
]
|
|
756
|
-
});
|
|
757
|
-
});
|
|
758
|
-
jstestIt((
|
|
759
|
-
"accepts arrays with two identical items for"
|
|
760
|
-
+ " `v8CoverageListMerge`"
|
|
761
|
-
), function () {
|
|
762
|
-
assertJsonEqual(v8CoverageListMerge([
|
|
763
|
-
{
|
|
764
|
-
result: [
|
|
765
|
-
{
|
|
766
|
-
functions: JSON.parse(functionsInput),
|
|
767
|
-
scriptId: "123",
|
|
768
|
-
url: "/lib.js"
|
|
769
|
-
}, {
|
|
770
|
-
functions: JSON.parse(functionsInput),
|
|
771
|
-
scriptId: "123",
|
|
772
|
-
url: "/lib.js"
|
|
773
|
-
}
|
|
774
|
-
]
|
|
775
|
-
}
|
|
776
|
-
]), {
|
|
777
|
-
result: [
|
|
778
|
-
{
|
|
779
|
-
functions: JSON.parse(functionsExpected),
|
|
780
|
-
scriptId: "0",
|
|
781
|
-
url: "/lib.js"
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
functions: JSON.parse(functionsExpected),
|
|
785
|
-
scriptId: "1",
|
|
786
|
-
url: "/lib.js"
|
|
787
|
-
}
|
|
788
|
-
]
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
[
|
|
792
|
-
"test_coverage_merge_is_block_coverage_test.json",
|
|
793
|
-
"test_coverage_merge_issue_2_mixed_is_block_coverage_test.json",
|
|
794
|
-
"test_coverage_merge_node_10_internal_errors_one_of_test.json",
|
|
795
|
-
"test_coverage_merge_reduced_test.json",
|
|
796
|
-
"test_coverage_merge_simple_test.json",
|
|
797
|
-
"test_coverage_merge_various_test.json"
|
|
798
|
-
].forEach(function (file) {
|
|
799
|
-
jstestIt(file, function () {
|
|
800
|
-
file = testCoverageMergeData[file];
|
|
801
|
-
file.forEach(function ({
|
|
802
|
-
expected,
|
|
803
|
-
inputs
|
|
804
|
-
}) {
|
|
805
|
-
assertJsonEqual(v8CoverageListMerge(inputs), expected);
|
|
806
|
-
});
|
|
807
|
-
});
|
|
808
|
-
});
|
|
809
|
-
jstestIt((
|
|
810
|
-
"merge multiple node-sqlite coverage files"
|
|
811
|
-
), function () {
|
|
812
|
-
let data1 = [
|
|
813
|
-
"test_v8_coverage_node_sqlite_9884_1633662346346_0.json",
|
|
814
|
-
"test_v8_coverage_node_sqlite_13216_1633662333140_0.json"
|
|
815
|
-
].map(function (file) {
|
|
816
|
-
return testCoverageMergeData[file];
|
|
817
|
-
});
|
|
818
|
-
let data2 = testCoverageMergeData[
|
|
819
|
-
"test_v8_coverage_node_sqlite_merged.json"
|
|
820
|
-
];
|
|
821
|
-
data1 = v8CoverageListMerge(data1);
|
|
822
|
-
data1 = v8CoverageListMerge([data1]);
|
|
823
|
-
|
|
824
|
-
// Debug data1.
|
|
825
|
-
// await moduleFs.promises.writeFile(
|
|
826
|
-
// ".test_v8_coverage_node_sqlite_merged.json",
|
|
827
|
-
// JSON.stringify(objectDeepCopyWithKeysSorted(data1), undefined, 4) + "\n"
|
|
828
|
-
// );
|
|
829
|
-
|
|
830
|
-
assertJsonEqual(data1, data2);
|
|
831
|
-
});
|
|
832
|
-
});
|
|
833
|
-
|
|
834
|
-
jstestDescribe((
|
|
835
|
-
"test v8CoverageReportCreate's handling-behavior"
|
|
836
|
-
), function () {
|
|
837
|
-
jstestIt((
|
|
838
|
-
"test null-case handling-behavior"
|
|
839
|
-
), async function () {
|
|
840
|
-
await assertErrorThrownAsync(function () {
|
|
841
|
-
return v8CoverageReportCreate({});
|
|
842
|
-
}, "invalid coverageDir");
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
// CL-xxx - coverage - Relax requirement for coverageDir to be in cwd.
|
|
846
|
-
// jstestIt((
|
|
847
|
-
// "test invalid-coverageDir handling-behavior"
|
|
848
|
-
// ), async function () {
|
|
849
|
-
// await assertErrorThrownAsync(function () {
|
|
850
|
-
// return jslint.jslint_cli({
|
|
851
|
-
// // suppress error
|
|
852
|
-
// console_error: noop,
|
|
853
|
-
// mode_cli: true,
|
|
854
|
-
// process_argv: [
|
|
855
|
-
// "node", "jslint.mjs",
|
|
856
|
-
// "v8_coverage_report=..",
|
|
857
|
-
// "node", "jslint.mjs"
|
|
858
|
-
// ]
|
|
859
|
-
// });
|
|
860
|
-
// }, "is not subdirectory of cwd");
|
|
861
|
-
// });
|
|
862
|
-
|
|
863
|
-
jstestIt((
|
|
864
|
-
"test coverage-report jslint.mjs handling-behavior"
|
|
865
|
-
), async function () {
|
|
866
|
-
await jslint.jslint_cli({
|
|
867
|
-
mode_cli: true,
|
|
868
|
-
process_argv: [
|
|
869
|
-
"node", "jslint.mjs",
|
|
870
|
-
"v8_coverage_report=.tmp/coverage_jslint",
|
|
871
|
-
"node", "jslint.mjs"
|
|
872
|
-
]
|
|
873
|
-
});
|
|
874
|
-
});
|
|
875
|
-
[
|
|
876
|
-
[
|
|
877
|
-
"v8CoverageReportCreate_high.js", (
|
|
878
|
-
"switch(0){\n"
|
|
879
|
-
+ "case 0:break;\n"
|
|
880
|
-
+ "}\n"
|
|
881
|
-
)
|
|
882
|
-
], [
|
|
883
|
-
"v8CoverageReportCreate_ignore.js", (
|
|
884
|
-
"/*mode-coverage-ignore-file*/\n"
|
|
885
|
-
+ "switch(0){\n"
|
|
886
|
-
+ "case 0:break;\n"
|
|
887
|
-
+ "}\n"
|
|
888
|
-
)
|
|
889
|
-
], [
|
|
890
|
-
"v8CoverageReportCreate_low.js", (
|
|
891
|
-
"switch(0){\n"
|
|
892
|
-
+ "case 1:break;\n"
|
|
893
|
-
+ "case 2:break;\n"
|
|
894
|
-
+ "case 3:break;\n"
|
|
895
|
-
+ "case 4:break;\n"
|
|
896
|
-
+ "}\n"
|
|
897
|
-
)
|
|
898
|
-
], [
|
|
899
|
-
"v8CoverageReportCreate_medium.js", (
|
|
900
|
-
"switch(0){\n"
|
|
901
|
-
+ "case 0:break;\n"
|
|
902
|
-
+ "case 1:break;\n"
|
|
903
|
-
+ "case 2:break;\n"
|
|
904
|
-
+ "}\n"
|
|
905
|
-
)
|
|
906
|
-
]
|
|
907
|
-
].forEach(function ([
|
|
908
|
-
file, data
|
|
909
|
-
], ii) {
|
|
910
|
-
jstestIt(file, async function () {
|
|
911
|
-
let dir = ".tmp/coverage" + ii + "/";
|
|
912
|
-
file = dir + file;
|
|
913
|
-
await fsWriteFileWithParents(file, data);
|
|
914
|
-
await jslint.jslint_cli({
|
|
915
|
-
mode_cli: true,
|
|
916
|
-
process_argv: [
|
|
917
|
-
"node", "jslint.mjs",
|
|
918
|
-
"v8_coverage_report=" + dir,
|
|
919
|
-
"node",
|
|
920
|
-
file
|
|
921
|
-
]
|
|
922
|
-
});
|
|
923
|
-
// test npm handling-behavior
|
|
924
|
-
if (ii === 0) {
|
|
925
|
-
await jslint.jslint_cli({
|
|
926
|
-
mode_cli: true,
|
|
927
|
-
process_argv: [
|
|
928
|
-
"node", "jslint.mjs",
|
|
929
|
-
"v8_coverage_report=" + dir,
|
|
930
|
-
"npm", "--version"
|
|
931
|
-
]
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
});
|
|
935
|
-
});
|
|
936
|
-
});
|
|
937
|
-
}());
|