@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/jslint.mjs CHANGED
@@ -94,10 +94,11 @@
94
94
  /*jslint beta, node*/
95
95
 
96
96
  /*property
97
+ mode_conditional,
97
98
  JSLINT_BETA, NODE_V8_COVERAGE, a, all, argv, arity, artifact,
98
99
  assertErrorThrownAsync, assertJsonEqual, assertOrThrow, assign, async, b,
99
100
  beta, bitwise, block, body, browser, c, calls, catch, catch_list,
100
- catch_stack, causes, char, children, cjs_module, cjs_require, clear, closer,
101
+ catch_stack, causes, char, children, clear, closer,
101
102
  closure, code, column, concat, consoleError, console_error, console_log,
102
103
  constant, context, convert, count, coverageDir, create, cwd, d, dead,
103
104
  debugInline, default, delta, devel, directive, directive_list,
@@ -105,7 +106,7 @@
105
106
  ellipsis, else, end, endOffset, endsWith, entries, env, error, eval, every,
106
107
  example_list, exec, execArgv, exit, export_dict, exports, expression, extra,
107
108
  file, fileList, fileURLToPath, filter, finally, flag, floor, for, forEach,
108
- formatted_message, free, freeze, from, froms, fsRmRecursive,
109
+ formatted_message, free, freeze, from, froms,
109
110
  fsWriteFileWithParents, fud, functionName, function_list, function_stack,
110
111
  functions, get, getset, github_repo, global, global_dict, global_list,
111
112
  holeList, htmlEscape, id, identifier, import, import_list, inc, indent2,
@@ -120,7 +121,7 @@
120
121
  mkdir, modeCoverageIgnoreFile, modeIndex, mode_cli, mode_json, mode_module,
121
122
  mode_noop, mode_property, mode_shebang, mode_stop, module, moduleFsInit,
122
123
  moduleName, module_list, name, names, node, noop, now,
123
- npm_config_mode_coverage, nr, nud, ok, on, open, opening, option,
124
+ nr, nud, objectDeepCopyWithKeysSorted, ok, on, open, opening, option,
124
125
  option_dict, order, package_name, padEnd, padStart, parameters, parent,
125
126
  parentIi, parse, pathname, platform, pop, processArgv, process_argv,
126
127
  process_env, process_exit, process_version, promises, property,
@@ -142,16 +143,18 @@ let debugInline = (function () {
142
143
  let consoleError = function () {
143
144
  return;
144
145
  };
145
- return function (...argv) {
146
+ function debug(...argv) {
146
147
 
147
- // This function will both print <argv> to stderr and return <argv>[0].
148
+ // This function will print <argv> to stderr and then return <argv>[0].
148
149
 
149
150
  consoleError("\n\ndebugInline");
150
151
  consoleError(...argv);
151
152
  consoleError("\n");
152
- consoleError = console.error;
153
153
  return argv[0];
154
- };
154
+ }
155
+ debug(); // Coverage-hack.
156
+ consoleError = console.error;
157
+ return debug;
155
158
  }());
156
159
  let jslint_charset_ascii = (
157
160
  "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007"
@@ -162,7 +165,7 @@ let jslint_charset_ascii = (
162
165
  + "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
163
166
  + "`abcdefghijklmnopqrstuvwxyz{|}~\u007f"
164
167
  );
165
- let jslint_edition = "v2021.10.20";
168
+ let jslint_edition = "v2021.11.20";
166
169
  let jslint_export; // The jslint object to be exported.
167
170
  let jslint_fudge = 1; // Fudge starting line and starting
168
171
  // ... column to 1.
@@ -180,7 +183,7 @@ let moduleUrl;
180
183
 
181
184
  async function assertErrorThrownAsync(asyncFunc, regexp) {
182
185
 
183
- // This function will assert <asyncFunc> throws an error.
186
+ // This function will assert calling <asyncFunc> throws an error.
184
187
 
185
188
  let err;
186
189
  try {
@@ -188,14 +191,14 @@ async function assertErrorThrownAsync(asyncFunc, regexp) {
188
191
  } catch (errCaught) {
189
192
  err = errCaught;
190
193
  }
191
- assertOrThrow(err, "no error thrown");
194
+ assertOrThrow(err, "No error thrown.");
192
195
  assertOrThrow(
193
196
  regexp === undefined || new RegExp(regexp).test(err.message),
194
197
  err
195
198
  );
196
199
  }
197
200
 
198
- function assertJsonEqual(aa, bb) {
201
+ function assertJsonEqual(aa, bb, message) {
199
202
 
200
203
  // This function will assert JSON.stringify(<aa>) === JSON.stringify(<bb>).
201
204
 
@@ -203,7 +206,11 @@ function assertJsonEqual(aa, bb) {
203
206
  bb = JSON.stringify(objectDeepCopyWithKeysSorted(bb));
204
207
  if (aa !== bb) {
205
208
  throw new Error(
206
- JSON.stringify(aa) + " !== " + JSON.stringify(bb)
209
+ JSON.stringify(aa) + " !== " + JSON.stringify(bb) + (
210
+ message
211
+ ? " - " + message
212
+ : ""
213
+ )
207
214
  );
208
215
  }
209
216
  }
@@ -230,31 +237,6 @@ function empty() {
230
237
  return Object.create(null);
231
238
  }
232
239
 
233
- async function fsRmRecursive(path, option_dict) {
234
-
235
- // This function will 'rm -r' <path>.
236
-
237
- await moduleFsInit();
238
- console.error("rm -r path " + path);
239
- if (((
240
- option_dict && option_dict.process_version
241
- ) || process.version) < "v14") {
242
-
243
- // Legacy rmdir for nodejs v12
244
-
245
- await Promise.all([
246
- moduleFs.promises.unlink(path).catch(noop),
247
- moduleFs.promises.rmdir(path, {
248
- recursive: true
249
- }).catch(noop)
250
- ]);
251
- return;
252
- }
253
- await moduleFs.promises.rm(path, {
254
- recursive: true
255
- }).catch(noop);
256
- }
257
-
258
240
  async function fsWriteFileWithParents(pathname, data) {
259
241
 
260
242
  // This function will write <data> to <pathname> and lazy-mkdirp if necessary.
@@ -1450,8 +1432,6 @@ ${String(message).slice(0, 2000)}`
1450
1432
  }
1451
1433
 
1452
1434
  async function jslint_cli({
1453
- cjs_module,
1454
- cjs_require,
1455
1435
  console_error,
1456
1436
  console_log,
1457
1437
  file,
@@ -1477,9 +1457,18 @@ async function jslint_cli({
1477
1457
  code,
1478
1458
  file,
1479
1459
  line_offset = 0,
1460
+ mode_conditional,
1480
1461
  option = empty()
1481
1462
  }) {
1482
1463
  let result_from_file;
1464
+ if (
1465
+ mode_conditional
1466
+ && !(
1467
+ /^\/\*jslint\b/m
1468
+ ).test(code.slice(0, 65536))
1469
+ ) {
1470
+ return;
1471
+ }
1483
1472
  option = Object.assign(empty(), option, {
1484
1473
  file
1485
1474
  });
@@ -1504,28 +1493,25 @@ async function jslint_cli({
1504
1493
  return "";
1505
1494
  });
1506
1495
  return;
1496
+ case ".md":
1497
+
1498
+ // Recursively jslint embedded "node --eval '\n...\n'".
1499
+
1500
+ jslint_node_eval({
1501
+ code,
1502
+ file,
1503
+ mode_conditional: true,
1504
+ option
1505
+ });
1506
+ return;
1507
1507
  case ".sh":
1508
1508
 
1509
- // Recursively jslint embedded "node -e '\n...\n'".
1509
+ // Recursively jslint embedded "node --eval '\n...\n'".
1510
1510
 
1511
- code.replace((
1512
- /\bnode\b.*? -e '\n([\S\s]*?\n)'/gm
1513
- ), function (ignore, match1, ii) {
1514
- jslint_from_file({
1515
- code: match1,
1516
- file: file + ".<node -e>.js",
1517
- line_offset: string_line_count(code.slice(0, ii)) + 1,
1518
- option: Object.assign(empty(), {
1519
- beta: Boolean(
1520
- process_env.JSLINT_BETA
1521
- && !(
1522
- /0|false|null|undefined/
1523
- ).test(process_env.JSLINT_BETA)
1524
- ),
1525
- node: true
1526
- }, option)
1527
- });
1528
- return "";
1511
+ jslint_node_eval({
1512
+ code,
1513
+ file,
1514
+ option
1529
1515
  });
1530
1516
  return;
1531
1517
  default:
@@ -1568,6 +1554,34 @@ async function jslint_cli({
1568
1554
  return result_from_file;
1569
1555
  }
1570
1556
 
1557
+ function jslint_node_eval({
1558
+ code,
1559
+ file,
1560
+ mode_conditional,
1561
+ option = empty()
1562
+ }) {
1563
+ code.replace((
1564
+ /\bnode\b.*? (?:--eval|-e) '\n([\S\s]*?\n)'/gm
1565
+ ), function (ignore, match1, ii) {
1566
+ jslint_from_file({
1567
+ code: match1,
1568
+ file: file + ".<node -e>.js",
1569
+ line_offset: string_line_count(code.slice(0, ii)) + 1,
1570
+ mode_conditional,
1571
+ option: Object.assign(empty(), {
1572
+ beta: Boolean(
1573
+ process_env.JSLINT_BETA
1574
+ && !(
1575
+ /0|false|null|undefined/
1576
+ ).test(process_env.JSLINT_BETA)
1577
+ ),
1578
+ node: true
1579
+ }, option)
1580
+ });
1581
+ return "";
1582
+ });
1583
+ }
1584
+
1571
1585
  function string_line_count(code) {
1572
1586
 
1573
1587
  // This function will count number of newlines in <code>.
@@ -1606,16 +1620,11 @@ async function jslint_cli({
1606
1620
  process_env = process_env || process.env;
1607
1621
  process_exit = process_exit || process.exit;
1608
1622
  await moduleFsInit();
1609
- if (!(
1610
-
1611
- // Feature-detect nodejs-cjs-cli.
1612
-
1613
- (cjs_module && cjs_require)
1614
- ? cjs_module === cjs_require.main
1623
+ if (
1624
+ !(
1615
1625
 
1616
- // Feature-detect nodejs-esm-cli.
1626
+ // Feature-detect nodejs-cli.
1617
1627
 
1618
- : (
1619
1628
  process.execArgv.indexOf("--eval") === -1
1620
1629
  && process.execArgv.indexOf("-e") === -1
1621
1630
  && (
@@ -1624,10 +1633,11 @@ async function jslint_cli({
1624
1633
  ).test(process_argv[1])
1625
1634
  || mode_cli
1626
1635
  )
1627
- && moduleUrl.fileURLToPath(jslint_import_meta_url) ===
1628
- modulePath.resolve(process_argv[1])
1636
+ && moduleUrl.fileURLToPath(jslint_import_meta_url)
1637
+ === modulePath.resolve(process_argv[1])
1629
1638
  )
1630
- ) && !mode_cli) {
1639
+ && !mode_cli
1640
+ ) {
1631
1641
  return exit_code;
1632
1642
  }
1633
1643
 
@@ -1718,6 +1728,7 @@ async function jslint_cli({
1718
1728
  case ".html":
1719
1729
  case ".js":
1720
1730
  case ".json":
1731
+ case ".md":
1721
1732
  case ".mjs":
1722
1733
  case ".sh":
1723
1734
  break;
@@ -1729,11 +1740,12 @@ async function jslint_cli({
1729
1740
  } catch (ignore) {
1730
1741
  return;
1731
1742
  }
1732
- if (!(
1733
- !(
1743
+ if (
1744
+ (
1734
1745
  /(?:\b|_)(?:lock|min|raw|rollup)(?:\b|_)/
1735
- ).test(file2) && code && code.length < 1048576
1736
- )) {
1746
+ ).test(file2)
1747
+ || !(code && code.length < 1048576)
1748
+ ) {
1737
1749
  return;
1738
1750
  }
1739
1751
  jslint_from_file({
@@ -2965,12 +2977,10 @@ function jslint_phase2_lex(state) {
2965
2977
  switch (val && key) {
2966
2978
 
2967
2979
  // Assign global browser variables to global_dict.
2968
- // /*jslint beta, browser, devel*/
2969
- // console.log(JSON.stringify(Array.from([
2970
- // ...
2971
- // ]).filter(function (key) {
2972
- // return window.hasOwnProperty(key);
2973
- // }), undefined, 4));
2980
+ /*
2981
+ // /\*jslint beta, browser, devel*\/
2982
+ console.log(JSON.stringify(Object.keys(window).sort(), undefined, 4));
2983
+ */
2974
2984
 
2975
2985
  case "browser":
2976
2986
  object_assign_from_list(global_dict, [
@@ -2978,6 +2988,7 @@ function jslint_phase2_lex(state) {
2978
2988
  // Shared with Node.js.
2979
2989
 
2980
2990
  "AbortController",
2991
+ // "Buffer",
2981
2992
  "DOMException",
2982
2993
  "Event",
2983
2994
  "EventTarget",
@@ -2989,17 +3000,33 @@ function jslint_phase2_lex(state) {
2989
3000
  "URL",
2990
3001
  "URLSearchParams",
2991
3002
  "WebAssembly",
3003
+ // "__dirname",
3004
+ // "__filename",
2992
3005
  // "atob",
2993
3006
  // "btoa",
3007
+ // "clearImmediate",
2994
3008
  "clearInterval",
2995
3009
  "clearTimeout",
2996
3010
  // "console",
3011
+ // "exports",
3012
+ // "global",
3013
+ // "module",
2997
3014
  "performance",
3015
+ // "process",
2998
3016
  "queueMicrotask",
3017
+ // "require",
3018
+ // "setImmediate",
2999
3019
  "setInterval",
3000
3020
  "setTimeout",
3021
+ "structuredClone",
3022
+
3023
+ // Web worker only.
3024
+ // https://github.com/mdn/content/blob/main/files/en-us/web/api
3025
+ // /workerglobalscope/index.md
3001
3026
 
3002
- // Browser only.
3027
+ "importScripts",
3028
+
3029
+ // Window.
3003
3030
 
3004
3031
  // "CharacterData",
3005
3032
  // "DocumentType",
@@ -3023,6 +3050,7 @@ function jslint_phase2_lex(state) {
3023
3050
  // "event",
3024
3051
  "fetch",
3025
3052
  // "history",
3053
+ "indexedDb",
3026
3054
  "localStorage",
3027
3055
  "location",
3028
3056
  // "name",
@@ -3061,7 +3089,7 @@ function jslint_phase2_lex(state) {
3061
3089
  // These are the globals that are provided by the language standard.
3062
3090
  // Assign global ECMAScript variables to global_dict.
3063
3091
  /*
3064
- node --input-type=module -e '
3092
+ node --input-type=module --eval '
3065
3093
  // /\*jslint beta, node*\/
3066
3094
  import https from "https";
3067
3095
  (async function () {
@@ -3069,8 +3097,8 @@ import https from "https";
3069
3097
  let result = "";
3070
3098
  await new Promise(function (resolve) {
3071
3099
  https.get((
3072
- "https://raw.githubusercontent.com/mdn/content/main/files/"
3073
- + "en-us/web/javascript/reference/global_objects/index.md"
3100
+ "https://raw.githubusercontent.com/mdn/content/main/files"
3101
+ + "/en-us/web/javascript/reference/global_objects/index.md"
3074
3102
  ), function (res) {
3075
3103
  res.on("data", function (chunk) {
3076
3104
  result += chunk;
@@ -3154,7 +3182,7 @@ import https from "https";
3154
3182
 
3155
3183
  // Assign global Node.js variables to global_dict.
3156
3184
  /*
3157
- node --input-type=module -e '
3185
+ node --input-type=module --eval '
3158
3186
  // /\*jslint beta, node*\/
3159
3187
  import moduleHttps from "https";
3160
3188
  (async function () {
@@ -3162,8 +3190,8 @@ import moduleHttps from "https";
3162
3190
  let result = "";
3163
3191
  await new Promise(function (resolve) {
3164
3192
  moduleHttps.get((
3165
- "https://raw.githubusercontent.com/nodejs/node/master/doc/api/"
3166
- + "globals.md"
3193
+ "https://raw.githubusercontent.com/nodejs/node/master/doc/api"
3194
+ + "/globals.md"
3167
3195
  ), function (res) {
3168
3196
  res.on("data", function (chunk) {
3169
3197
  result += chunk;
@@ -3213,7 +3241,8 @@ import moduleHttps from "https";
3213
3241
  "require",
3214
3242
  "setImmediate",
3215
3243
  "setInterval",
3216
- "setTimeout"
3244
+ "setTimeout",
3245
+ "structuredClone"
3217
3246
  ], "Node.js");
3218
3247
  break;
3219
3248
  }
@@ -4823,10 +4852,12 @@ function jslint_phase3_parse(state) {
4823
4852
 
4824
4853
  function prefix_await() {
4825
4854
  const the_await = token_now;
4826
- if (functionage.async === 0) {
4855
+
4856
+ // PR-370 - Add top-level-await support.
4857
+
4858
+ if (functionage.async === 0 && functionage !== token_global) {
4827
4859
 
4828
4860
  // test_cause:
4829
- // ["await", "prefix_await", "unexpected_a", "await", 1]
4830
4861
  // ["function aa(){aa=await 0;}", "prefix_await", "unexpected_a", "await", 18]
4831
4862
  // ["function aa(){await 0;}", "prefix_await", "unexpected_a", "await", 15]
4832
4863
 
@@ -7832,8 +7863,10 @@ function jslint_phase4_walk(state) {
7832
7863
  left_variable = parent.context[left.id];
7833
7864
  if (
7834
7865
  left_variable !== undefined
7835
- // Coverage-hack.
7836
- // && left_variable.dead
7866
+
7867
+ // Probably deadcode.
7868
+ // && left_variable.dead
7869
+
7837
7870
  && left_variable.parent === parent
7838
7871
  && left_variable.calls !== undefined
7839
7872
  && left_variable.calls[functionage.name.id] !== undefined
@@ -8812,6 +8845,14 @@ function jslint_report({
8812
8845
  let html = "";
8813
8846
  let length_80 = 1111;
8814
8847
 
8848
+ function address(line = 1, column = 1) {
8849
+
8850
+ // This function will create HTML address element from <line> and <column>
8851
+
8852
+ return `<address>${Number(line)}: ${Number(column)}</address>`;
8853
+
8854
+ }
8855
+
8815
8856
  function detail(title, list) {
8816
8857
  return (
8817
8858
  (Array.isArray(list) && list.length > 0)
@@ -8993,15 +9034,12 @@ pyNj+JctcQLXenBOCms46aMkenIx45WpXqxxVJQLz/vgpmAVa0fmDv6Pue9xVTBPfVxCUGfj\
8993
9034
  }
8994
9035
  /*csslint ignore:end*/
8995
9036
 
8996
- .JSLINT_ {
8997
- font-family: daley, sans-serif;
8998
- font-size: 14px;
8999
- }
9037
+ /* css - jslint_report - font */
9038
+ .JSLINT_,
9000
9039
  .JSLINT_ fieldset legend,
9001
9040
  .JSLINT_ .center {
9002
9041
  font-family: daley, sans-serif;
9003
9042
  font-size: 14px;
9004
- text-align: center;
9005
9043
  }
9006
9044
  .JSLINT_ fieldset textarea,
9007
9045
  .JSLINT_ #JSLINT_REPORT_FUNCTIONS dt,
@@ -9015,7 +9053,18 @@ pyNj+JctcQLXenBOCms46aMkenIx45WpXqxxVJQLz/vgpmAVa0fmDv6Pue9xVTBPfVxCUGfj\
9015
9053
  .JSLINT_ fieldset > div {
9016
9054
  font-family: sans-serif;
9017
9055
  }
9056
+ .JSLINT_ #JSLINT_REPORT_FUNCTIONS .level dfn {
9057
+ font-style: normal;
9058
+ font-weight: bold;
9059
+ }
9060
+ .JSLINT_ #JSLINT_REPORT_FUNCTIONS .level dt {
9061
+ font-style: italic;
9062
+ }
9063
+ .JSLINT_ #JSLINT_REPORT_TITLE {
9064
+ font-size: 32px;
9065
+ }
9018
9066
 
9067
+ /* css - jslint_report - general */
9019
9068
  body {
9020
9069
  background: antiquewhite;
9021
9070
  }
@@ -9028,6 +9077,10 @@ body {
9028
9077
  .JSLINT_ fieldset address {
9029
9078
  float: right;
9030
9079
  }
9080
+ .JSLINT_ fieldset legend,
9081
+ .JSLINT_ .center {
9082
+ text-align: center;
9083
+ }
9031
9084
  .JSLINT_ fieldset legend {
9032
9085
  background: darkslategray;
9033
9086
  color: white;
@@ -9058,15 +9111,12 @@ body {
9058
9111
  }
9059
9112
  .JSLINT_ #JSLINT_REPORT_FUNCTIONS .level dfn {
9060
9113
  display: block;
9061
- font-style: normal;
9062
- font-weight: bold;
9063
9114
  line-height: 20px;
9064
9115
  }
9065
9116
  .JSLINT_ #JSLINT_REPORT_FUNCTIONS .level dl {
9066
9117
  position: relative
9067
9118
  }
9068
9119
  .JSLINT_ #JSLINT_REPORT_FUNCTIONS .level dt {
9069
- font-style: italic;
9070
9120
  line-height: 20px;
9071
9121
  position: absolute;
9072
9122
  text-align: right;
@@ -9125,9 +9175,7 @@ body {
9125
9175
  }
9126
9176
  .JSLINT_ #JSLINT_REPORT_TITLE {
9127
9177
  color: darkslategray;
9128
- font-size: 32px;
9129
9178
  padding-top: 16px;
9130
- text-align: center;
9131
9179
  }
9132
9180
  .JSLINT_ #JSLINT_REPORT_WARNINGS cite {
9133
9181
  display: block;
@@ -9160,7 +9208,7 @@ body {
9160
9208
 
9161
9209
  // Produce the Title.
9162
9210
 
9163
- html += "<div id=\"JSLINT_REPORT_TITLE\">\n";
9211
+ html += "<div class=\"center\" id=\"JSLINT_REPORT_TITLE\">\n";
9164
9212
  html += "JSLint Report\n";
9165
9213
  html += "</div>\n";
9166
9214
 
@@ -9186,7 +9234,7 @@ body {
9186
9234
  }, ii) {
9187
9235
  html += (
9188
9236
  "<cite>"
9189
- + "<address>" + htmlEscape(line + ": " + column) + "</address>"
9237
+ + address(line, column)
9190
9238
  + htmlEscape((ii + 1) + ". " + message)
9191
9239
  + "</cite>"
9192
9240
  + "<samp>"
@@ -9272,6 +9320,7 @@ body {
9272
9320
  functions.forEach(function (the_function) {
9273
9321
  let {
9274
9322
  context,
9323
+ from,
9275
9324
  level,
9276
9325
  line,
9277
9326
  name,
@@ -9285,7 +9334,7 @@ body {
9285
9334
  let params;
9286
9335
  html += (
9287
9336
  "<div class=\"level level" + htmlEscape(level) + "\">"
9288
- + "<address>" + htmlEscape(line) + "</address>"
9337
+ + address(line, from + 1)
9289
9338
  + "<dfn>"
9290
9339
  + (
9291
9340
  name === "=>"
@@ -9503,13 +9552,13 @@ function objectDeepCopyWithKeysSorted(obj) {
9503
9552
  return obj;
9504
9553
  }
9505
9554
 
9506
- // recursively deep-copy list with child-keys sorted
9555
+ // Recursively deep-copy list with child-keys sorted.
9507
9556
 
9508
9557
  if (Array.isArray(obj)) {
9509
9558
  return obj.map(objectDeepCopyWithKeysSorted);
9510
9559
  }
9511
9560
 
9512
- // recursively deep-copy obj with keys sorted
9561
+ // Recursively deep-copy obj with keys sorted.
9513
9562
 
9514
9563
  sorted = {};
9515
9564
  Object.keys(obj).sort().forEach(function (key) {
@@ -9830,29 +9879,6 @@ function v8CoverageListMerge(processCovs) {
9830
9879
  return funcCov;
9831
9880
  }
9832
9881
 
9833
- function sortProcess(processCov) {
9834
-
9835
- // This function will sort <processCov>.result.
9836
- // Sorts the scripts alphabetically by `url`.
9837
- // Reassigns script ids: the script at index `0` receives `"0"`, the script at
9838
- // index `1` receives `"1"` etc.
9839
-
9840
- Object.entries(processCov.result.sort(function (aa, bb) {
9841
- return (
9842
- aa.url < bb.url
9843
- ? -1
9844
- : aa.url > bb.url
9845
- ? 1
9846
- : 0
9847
- );
9848
- })).forEach(function ([
9849
- scriptId, scriptCov
9850
- ]) {
9851
- scriptCov.scriptId = scriptId.toString(10);
9852
- });
9853
- return processCov;
9854
- }
9855
-
9856
9882
  function sortScript(scriptCov) {
9857
9883
 
9858
9884
  // This function will normalize-and-sort <scriptCov>.functions.
@@ -10015,18 +10041,6 @@ function v8CoverageListMerge(processCovs) {
10015
10041
  result: []
10016
10042
  };
10017
10043
  }
10018
- if (processCovs.length === 1) {
10019
-
10020
- // Normalize-and-sort scriptCov.
10021
-
10022
- processCovs[0].result.forEach(function (scriptCov) {
10023
- sortScript(scriptCov);
10024
- });
10025
-
10026
- // Sort processCovs[0].result.
10027
-
10028
- return sortProcess(processCovs[0]);
10029
- }
10030
10044
 
10031
10045
  // Init urlToScriptDict.
10032
10046
 
@@ -10168,9 +10182,25 @@ function v8CoverageListMerge(processCovs) {
10168
10182
  url: scriptCovs[0].url
10169
10183
  }));
10170
10184
  });
10171
- return sortProcess({
10172
- result: resultMerged
10185
+
10186
+ // Sorts the scripts alphabetically by `url`.
10187
+ // Reassigns script ids: the script at index `0` receives `"0"`, the script at
10188
+ // index `1` receives `"1"` etc.
10189
+
10190
+ Object.entries(resultMerged.sort(function (aa, bb) {
10191
+ return (
10192
+ aa.url > bb.url
10193
+ ? 1
10194
+ : -1
10195
+ );
10196
+ })).forEach(function ([
10197
+ scriptId, scriptCov
10198
+ ]) {
10199
+ scriptCov.scriptId = scriptId.toString(10);
10173
10200
  });
10201
+ return {
10202
+ result: resultMerged
10203
+ };
10174
10204
  }
10175
10205
 
10176
10206
  async function v8CoverageReportCreate({
@@ -10188,6 +10218,10 @@ async function v8CoverageReportCreate({
10188
10218
  let cwd;
10189
10219
  let exitCode = 0;
10190
10220
  let fileDict;
10221
+ let fileExcludeList = [];
10222
+ let fileIncludeList = [];
10223
+ let fileIncludeNodeModules;
10224
+ let processArgElem;
10191
10225
  let promiseList = [];
10192
10226
  let v8CoverageObj;
10193
10227
 
@@ -10216,6 +10250,8 @@ box-sizing: border-box;
10216
10250
  font-family: consolas, menlo, monospace;
10217
10251
  }
10218
10252
  /*csslint ignore:end*/
10253
+
10254
+ /* css - coverage_report - general */
10219
10255
  body {
10220
10256
  margin: 0;
10221
10257
  }
@@ -10228,8 +10264,9 @@ body {
10228
10264
  .coverage td,
10229
10265
  .coverage th {
10230
10266
  border: 1px solid #777;
10267
+ line-height: 20px;
10231
10268
  margin: 0;
10232
- padding: 5px;
10269
+ padding: 5px 10px;
10233
10270
  }
10234
10271
  .coverage td span {
10235
10272
  display: inline-block;
@@ -10269,30 +10306,30 @@ body {
10269
10306
  margin-bottom: 10px;
10270
10307
  }
10271
10308
 
10309
+ /* css - coverage_report - color */
10272
10310
  .coverage td,
10273
10311
  .coverage th {
10274
10312
  background: #fff;
10275
10313
  }
10276
- .coverage .count {
10314
+ .coverage .count,
10315
+ .coverage .coverageHigh {
10277
10316
  background: #9d9;
10278
- color: #777;
10279
10317
  }
10280
- .coverage .coverageHigh{
10281
- background: #9d9;
10318
+ .coverage .count {
10319
+ color: #666;
10282
10320
  }
10283
- .coverage .coverageIgnore{
10321
+ .coverage .coverageIgnore {
10284
10322
  background: #ccc;
10285
10323
  }
10286
- .coverage .coverageLow{
10324
+ .coverage .coverageLow,
10325
+ .coverage .uncovered {
10287
10326
  background: #ebb;
10288
10327
  }
10289
- .coverage .coverageMedium{
10328
+ .coverage .coverageMedium {
10290
10329
  background: #fd7;
10291
10330
  }
10292
10331
  .coverage .footer,
10293
- .coverage .header {
10294
- background: #ddd;
10295
- }
10332
+ .coverage .header,
10296
10333
  .coverage .lineno {
10297
10334
  background: #ddd;
10298
10335
  }
@@ -10302,17 +10339,15 @@ body {
10302
10339
  .coverage .percentbar div {
10303
10340
  background: #666;
10304
10341
  }
10305
- .coverage .uncovered {
10306
- background: #dbb;
10307
- }
10308
10342
 
10343
+ /* css - coverage_report - important */
10309
10344
  .coverage pre:hover span,
10310
10345
  .coverage tr:hover td {
10311
10346
  background: #7d7;
10312
10347
  }
10313
10348
  .coverage pre:hover span.uncovered,
10314
10349
  .coverage tr:hover td.coverageLow {
10315
- background: #d99;
10350
+ background: #f99;
10316
10351
  }
10317
10352
  </style>
10318
10353
  </head>
@@ -10325,6 +10360,7 @@ body {
10325
10360
  <tr>
10326
10361
  <th>Files covered</th>
10327
10362
  <th>Lines</th>
10363
+ <th>Remaining</th>
10328
10364
  </tr>
10329
10365
  </thead>
10330
10366
  <tbody>
@@ -10417,7 +10453,7 @@ body {
10417
10453
  xx1 = 6 * str1.length + 20;
10418
10454
  xx2 = 6 * str2.length + 20;
10419
10455
 
10420
- // Fs - write coverage_badge.svg
10456
+ // Fs - write coverage_badge.svg.
10421
10457
 
10422
10458
  promiseList.push(fsWriteFileWithParents((
10423
10459
  coverageDir + "coverage_badge.svg"
@@ -10427,7 +10463,7 @@ body {
10427
10463
  <rect fill="${fill}" height="20" width="${xx2}" x="${xx1}"/>
10428
10464
  <g
10429
10465
  fill="#fff"
10430
- font-family="dejavu sans, verdana, geneva, sans-serif"
10466
+ font-family="verdana, geneva, dejavu sans, sans-serif"
10431
10467
  font-size="11"
10432
10468
  font-weight="bold"
10433
10469
  text-anchor="middle"
@@ -10483,6 +10519,10 @@ body {
10483
10519
  ${modeCoverageIgnoreFile} ${coveragePct} %<br>
10484
10520
  ${linesCovered} / ${linesTotal}
10485
10521
  </td>
10522
+ <td style="text-align: right;">
10523
+ <br>
10524
+ ${linesTotal - linesCovered} / ${linesTotal}
10525
+ </td>
10486
10526
  </tr>
10487
10527
  `).trim() + "\n";
10488
10528
  });
@@ -10510,10 +10550,7 @@ body {
10510
10550
  lineHtml = "";
10511
10551
  lineId = "line_" + (ii + 1);
10512
10552
  switch (count) {
10513
-
10514
- // PR-364 - Probably deadcode.
10515
- // case -1:
10516
-
10553
+ case -1:
10517
10554
  case 0:
10518
10555
  if (holeList.length === 0) {
10519
10556
  lineHtml += "</span>";
@@ -10544,11 +10581,15 @@ body {
10544
10581
  }) {
10545
10582
  if (inHole !== isHole) {
10546
10583
  lineHtml += htmlEscape(chunk);
10547
- lineHtml += (
10548
- isHole
10549
- ? "</span><span class=\"uncovered\">"
10550
- : "</span><span>"
10551
- );
10584
+ lineHtml += "</span><span";
10585
+
10586
+ // Coverage-hack - Ugly-hack around possible deadcode where isHole is always
10587
+ // true.
10588
+
10589
+ if (isHole) {
10590
+ lineHtml += " class=\"uncovered\"";
10591
+ }
10592
+ lineHtml += ">";
10552
10593
  chunk = "";
10553
10594
  inHole = isHole;
10554
10595
  }
@@ -10571,7 +10612,7 @@ body {
10571
10612
  : ""
10572
10613
  )}"
10573
10614
  >
10574
- ${String(count).padStart(7, " ")}
10615
+ ${String(count || "-0").padStart(7, " ")}
10575
10616
  </span>
10576
10617
  <span>${lineHtml}</span>
10577
10618
  </pre>
@@ -10595,14 +10636,14 @@ ${String(count).padStart(7, " ")}
10595
10636
  </html>
10596
10637
  `).trim() + "\n";
10597
10638
 
10598
- // Fs - write <file>.html
10639
+ // Fs - write <file>.html.
10599
10640
 
10600
10641
  promiseList.push(fsWriteFileWithParents(pathname + ".html", html));
10601
10642
  if (!modeIndex) {
10602
10643
  return;
10603
10644
  }
10604
10645
 
10605
- // Fs - write coverage_report.txt
10646
+ // Fs - write coverage_report.txt.
10606
10647
 
10607
10648
  consoleError("\n" + txt);
10608
10649
  promiseList.push(fsWriteFileWithParents((
@@ -10640,7 +10681,7 @@ function sentinel() {}
10640
10681
 
10641
10682
  assertOrThrow(coverageDir, "invalid coverageDir " + coverageDir);
10642
10683
 
10643
- // CL-xxx - coverage - Relax requirement for coverageDir to be in cwd.
10684
+ // CL-61b11012 - coverage - Relax requirement for coverageDir to be in cwd.
10644
10685
  // assertOrThrow(
10645
10686
  // pathnameRelativeCwd(coverageDir),
10646
10687
  // "coverageDir " + coverageDir + " is not subdirectory of cwd " + cwd
@@ -10650,6 +10691,38 @@ function sentinel() {}
10650
10691
  /\\/g
10651
10692
  ), "/") + "/";
10652
10693
 
10694
+ processArgv = processArgv.slice();
10695
+ while (processArgv[0] && processArgv[0][0] === "-") {
10696
+ processArgElem = processArgv.shift().split("=");
10697
+ processArgElem[1] = processArgElem.slice(1).join("=");
10698
+ switch (processArgElem[0]) {
10699
+
10700
+ // PR-371 - add cli-option `--exclude=aa,bb`
10701
+
10702
+ case "--exclude":
10703
+ fileExcludeList = fileExcludeList.concat(
10704
+ processArgElem[1].split(",")
10705
+ );
10706
+ break;
10707
+
10708
+ // PR-371 - add cli-option `--exclude-node-modules=false`
10709
+
10710
+ case "--exclude-node-modules":
10711
+ fileIncludeNodeModules = (
10712
+ /0|false|null|undefined/
10713
+ ).test(processArgElem[1]);
10714
+ break;
10715
+
10716
+ // PR-371 - add cli-option `--include=aa,bb`
10717
+
10718
+ case "--include":
10719
+ fileIncludeList = fileIncludeList.concat(
10720
+ processArgElem[1].split(",")
10721
+ );
10722
+ break;
10723
+ }
10724
+ }
10725
+
10653
10726
  // 1. Spawn node.js program <processArgv> with coverage
10654
10727
 
10655
10728
  if (processArgv.length > 0) {
@@ -10672,7 +10745,7 @@ function sentinel() {}
10672
10745
  processArgv[0] === "npm"
10673
10746
 
10674
10747
  // If win32 environment, then replace program npm with npm.cmd.
10675
- // Coverage-hack - Ugly hack to get test-coverage under both win32 and linux.
10748
+ // Coverage-hack - Ugly-hack to get test-coverage under both win32 and linux.
10676
10749
 
10677
10750
  ? process.platform.replace("win32", "npm.cmd").replace(
10678
10751
  process.platform,
@@ -10720,14 +10793,25 @@ function sentinel() {}
10720
10793
  !pathname
10721
10794
  || pathname.startsWith("[")
10722
10795
 
10723
- // Filter directory node_modules.
10796
+ // PR-371 - Filter directory node_modules.
10724
10797
 
10725
10798
  || (
10726
- process.env.npm_config_mode_coverage !== "all"
10799
+ !fileIncludeNodeModules
10727
10800
  && (
10728
10801
  /(?:^|\/)node_modules\//m
10729
10802
  ).test(pathname)
10730
10803
  )
10804
+
10805
+ // PR-371 - Filter fileExcludeList.
10806
+
10807
+ || fileExcludeList.indexOf(pathname) >= 0
10808
+
10809
+ // PR-371 - Filter fileIncludeList.
10810
+
10811
+ || (
10812
+ fileIncludeList.length > 0
10813
+ && fileIncludeList.indexOf(pathname) === -1
10814
+ )
10731
10815
  ) {
10732
10816
  return;
10733
10817
  }
@@ -10745,7 +10829,7 @@ function sentinel() {}
10745
10829
 
10746
10830
  await fsWriteFileWithParents(
10747
10831
  coverageDir + "v8_coverage_merged.json",
10748
- JSON.stringify(v8CoverageObj)
10832
+ JSON.stringify(v8CoverageObj, undefined, 1)
10749
10833
  );
10750
10834
 
10751
10835
  // 3. Create html-coverage-reports in <coverageDir>.
@@ -10840,7 +10924,7 @@ function sentinel() {}
10840
10924
  linesTotal,
10841
10925
  modeCoverageIgnoreFile: (
10842
10926
  (
10843
- /^\/\*mode-coverage-ignore-file\*\/$/m
10927
+ /^\/\*coverage-ignore-file\*\/$/m
10844
10928
  ).test(source.slice(0, 65536))
10845
10929
  ? "(ignore)"
10846
10930
  : ""
@@ -10880,7 +10964,6 @@ jslint_export = Object.freeze(Object.assign(jslint, {
10880
10964
  assertJsonEqual,
10881
10965
  assertOrThrow,
10882
10966
  debugInline,
10883
- fsRmRecursive,
10884
10967
  fsWriteFileWithParents,
10885
10968
  htmlEscape,
10886
10969
  jslint,
@@ -10900,6 +10983,7 @@ jslint_export = Object.freeze(Object.assign(jslint, {
10900
10983
  jstestOnExit,
10901
10984
  moduleFsInit,
10902
10985
  noop,
10986
+ objectDeepCopyWithKeysSorted,
10903
10987
  v8CoverageListMerge,
10904
10988
  v8CoverageReportCreate
10905
10989
  }));
@@ -10908,25 +10992,4 @@ export default Object.freeze(jslint_export); // Export jslint as esm.
10908
10992
  jslint_import_meta_url = import.meta.url;
10909
10993
 
10910
10994
  // Run jslint_cli.
10911
-
10912
- (function () {
10913
- let cjs_module;
10914
- let cjs_require;
10915
-
10916
- // Coverage-hack.
10917
- // Init commonjs builtins in try-catch-block in case we're in es-module-mode.
10918
-
10919
- try {
10920
- cjs_module = module;
10921
- } catch (ignore) {}
10922
- try {
10923
- cjs_require = require;
10924
- } catch (ignore) {}
10925
- jslint_cli({
10926
- cjs_module,
10927
- cjs_require
10928
- });
10929
- }());
10930
-
10931
- // Coverage-hack.
10932
- debugInline();
10995
+ jslint_cli({});