eslint 8.22.0 → 8.33.0

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.
Files changed (80) hide show
  1. package/README.md +51 -45
  2. package/bin/eslint.js +2 -4
  3. package/conf/globals.js +6 -1
  4. package/conf/rule-type-list.json +2 -2
  5. package/lib/cli-engine/file-enumerator.js +4 -2
  6. package/lib/cli-engine/formatters/formatters-meta.json +46 -0
  7. package/lib/cli-engine/formatters/html.js +76 -51
  8. package/lib/cli.js +163 -40
  9. package/lib/config/default-config.js +2 -2
  10. package/lib/config/flat-config-array.js +1 -1
  11. package/lib/eslint/eslint-helpers.js +409 -87
  12. package/lib/eslint/eslint.js +5 -2
  13. package/lib/eslint/flat-eslint.js +113 -110
  14. package/lib/linter/code-path-analysis/code-path-segment.js +2 -2
  15. package/lib/linter/code-path-analysis/code-path-state.js +7 -7
  16. package/lib/linter/code-path-analysis/debug-helpers.js +3 -3
  17. package/lib/linter/code-path-analysis/id-generator.js +2 -2
  18. package/lib/linter/config-comment-parser.js +1 -2
  19. package/lib/linter/linter.js +17 -7
  20. package/lib/linter/timing.js +4 -4
  21. package/lib/options.js +293 -239
  22. package/lib/rule-tester/flat-rule-tester.js +13 -11
  23. package/lib/rule-tester/rule-tester.js +15 -11
  24. package/lib/rules/array-callback-return.js +2 -2
  25. package/lib/rules/comma-dangle.js +3 -3
  26. package/lib/rules/for-direction.js +1 -1
  27. package/lib/rules/func-name-matching.js +2 -2
  28. package/lib/rules/getter-return.js +14 -8
  29. package/lib/rules/global-require.js +2 -1
  30. package/lib/rules/id-length.js +43 -2
  31. package/lib/rules/indent-legacy.js +4 -4
  32. package/lib/rules/indent.js +23 -15
  33. package/lib/rules/index.js +3 -0
  34. package/lib/rules/key-spacing.js +50 -38
  35. package/lib/rules/lines-around-comment.js +2 -2
  36. package/lib/rules/logical-assignment-operators.js +474 -0
  37. package/lib/rules/multiline-ternary.js +2 -2
  38. package/lib/rules/new-cap.js +2 -2
  39. package/lib/rules/no-else-return.js +1 -1
  40. package/lib/rules/no-empty-static-block.js +47 -0
  41. package/lib/rules/no-empty.js +19 -2
  42. package/lib/rules/no-extra-boolean-cast.js +1 -1
  43. package/lib/rules/no-extra-parens.js +18 -3
  44. package/lib/rules/no-fallthrough.js +26 -5
  45. package/lib/rules/no-implicit-coercion.js +20 -1
  46. package/lib/rules/no-implicit-globals.js +5 -0
  47. package/lib/rules/no-invalid-regexp.js +40 -18
  48. package/lib/rules/no-labels.js +1 -1
  49. package/lib/rules/no-lone-blocks.js +1 -1
  50. package/lib/rules/no-loss-of-precision.js +2 -2
  51. package/lib/rules/no-magic-numbers.js +18 -1
  52. package/lib/rules/no-misleading-character-class.js +4 -4
  53. package/lib/rules/no-new-native-nonconstructor.js +64 -0
  54. package/lib/rules/no-obj-calls.js +1 -1
  55. package/lib/rules/no-restricted-exports.js +106 -10
  56. package/lib/rules/no-return-await.js +28 -1
  57. package/lib/rules/no-underscore-dangle.js +36 -11
  58. package/lib/rules/no-unneeded-ternary.js +1 -1
  59. package/lib/rules/no-use-before-define.js +1 -1
  60. package/lib/rules/no-useless-computed-key.js +1 -1
  61. package/lib/rules/no-var.js +2 -2
  62. package/lib/rules/no-warning-comments.js +24 -5
  63. package/lib/rules/padded-blocks.js +1 -1
  64. package/lib/rules/prefer-arrow-callback.js +4 -3
  65. package/lib/rules/prefer-const.js +13 -1
  66. package/lib/rules/prefer-named-capture-group.js +71 -6
  67. package/lib/rules/prefer-object-spread.js +1 -1
  68. package/lib/rules/prefer-regex-literals.js +147 -32
  69. package/lib/rules/prefer-rest-params.js +1 -1
  70. package/lib/rules/require-yield.js +0 -1
  71. package/lib/rules/strict.js +1 -1
  72. package/lib/rules/utils/ast-utils.js +10 -4
  73. package/lib/shared/directives.js +15 -0
  74. package/lib/shared/logging.js +1 -1
  75. package/lib/shared/runtime-info.js +1 -1
  76. package/lib/shared/traverser.js +1 -1
  77. package/lib/shared/types.js +15 -2
  78. package/lib/source-code/token-store/cursor.js +1 -1
  79. package/messages/print-config-with-directory-path.js +1 -1
  80. package/package.json +27 -27
@@ -105,7 +105,7 @@ module.exports = {
105
105
  if (ecmaFeatures.impliedStrict) {
106
106
  mode = "implied";
107
107
  } else if (mode === "safe") {
108
- mode = ecmaFeatures.globalReturn ? "global" : "function";
108
+ mode = ecmaFeatures.globalReturn || context.languageOptions.sourceType === "commonjs" ? "global" : "function";
109
109
  }
110
110
 
111
111
  /**
@@ -1350,7 +1350,7 @@ module.exports = {
1350
1350
  }
1351
1351
  }
1352
1352
 
1353
- /* istanbul ignore next */
1353
+ /* c8 ignore next */
1354
1354
  return true;
1355
1355
  },
1356
1356
 
@@ -1978,7 +1978,7 @@ module.exports = {
1978
1978
  if (comments.length) {
1979
1979
  const lastComment = comments[comments.length - 1];
1980
1980
 
1981
- if (lastComment.range[0] > leftToken.range[0]) {
1981
+ if (!leftToken || lastComment.range[0] > leftToken.range[0]) {
1982
1982
  leftToken = lastComment;
1983
1983
  }
1984
1984
  }
@@ -1986,7 +1986,13 @@ module.exports = {
1986
1986
  leftToken = leftValue;
1987
1987
  }
1988
1988
 
1989
- if (leftToken.type === "Shebang") {
1989
+ /*
1990
+ * If a hashbang comment was passed as a token object from SourceCode,
1991
+ * its type will be "Shebang" because of the way ESLint itself handles hashbangs.
1992
+ * If a hashbang comment was passed in a string and then tokenized in this function,
1993
+ * its type will be "Hashbang" because of the way Espree tokenizes hashbangs.
1994
+ */
1995
+ if (leftToken.type === "Shebang" || leftToken.type === "Hashbang") {
1990
1996
  return false;
1991
1997
  }
1992
1998
 
@@ -2007,7 +2013,7 @@ module.exports = {
2007
2013
  if (comments.length) {
2008
2014
  const firstComment = comments[0];
2009
2015
 
2010
- if (firstComment.range[0] < rightToken.range[0]) {
2016
+ if (!rightToken || firstComment.range[0] < rightToken.range[0]) {
2011
2017
  rightToken = firstComment;
2012
2018
  }
2013
2019
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @fileoverview Common utils for directives.
3
+ *
4
+ * This file contains only shared items for directives.
5
+ * If you make a utility for rules, please see `../rules/utils/ast-utils.js`.
6
+ *
7
+ * @author gfyoung <https://github.com/gfyoung>
8
+ */
9
+ "use strict";
10
+
11
+ const directivesPattern = /^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u;
12
+
13
+ module.exports = {
14
+ directivesPattern
15
+ };
@@ -7,7 +7,7 @@
7
7
 
8
8
  /* eslint no-console: "off" -- Logging util */
9
9
 
10
- /* istanbul ignore next */
10
+ /* c8 ignore next */
11
11
  module.exports = {
12
12
 
13
13
  /**
@@ -97,7 +97,7 @@ function environment() {
97
97
  */
98
98
  function getNpmPackageVersion(pkg, { global = false } = {}) {
99
99
  const npmBinArgs = ["bin", "-g"];
100
- const npmLsArgs = ["ls", "--depth=0", "--json", "eslint"];
100
+ const npmLsArgs = ["ls", "--depth=0", "--json", pkg];
101
101
 
102
102
  if (global) {
103
103
  npmLsArgs.push("-g");
@@ -74,7 +74,7 @@ class Traverser {
74
74
  }
75
75
 
76
76
  /**
77
- * Gives a a copy of the ancestor nodes.
77
+ * Gives a copy of the ancestor nodes.
78
78
  * @returns {ASTNode[]} The ancestor nodes.
79
79
  */
80
80
  parents() {
@@ -21,7 +21,7 @@ module.exports = {};
21
21
  /**
22
22
  * @typedef {Object} ParserOptions
23
23
  * @property {EcmaFeatures} [ecmaFeatures] The optional features.
24
- * @property {3|5|6|7|8|9|10|11|12|13|2015|2016|2017|2018|2019|2020|2021|2022} [ecmaVersion] The ECMAScript version (or revision number).
24
+ * @property {3|5|6|7|8|9|10|11|12|13|14|2015|2016|2017|2018|2019|2020|2021|2022|2023} [ecmaVersion] The ECMAScript version (or revision number).
25
25
  * @property {"script"|"module"} [sourceType] The source code type.
26
26
  * @property {boolean} [allowReserved] Allowing the use of reserved words as identifiers in ES3.
27
27
  */
@@ -190,10 +190,23 @@ module.exports = {};
190
190
  * @property {DeprecatedRuleInfo[]} usedDeprecatedRules The list of used deprecated rules.
191
191
  */
192
192
 
193
+ /**
194
+ * Information provided when the maximum warning threshold is exceeded.
195
+ * @typedef {Object} MaxWarningsExceeded
196
+ * @property {number} maxWarnings Number of warnings to trigger nonzero exit code.
197
+ * @property {number} foundWarnings Number of warnings found while linting.
198
+ */
199
+
200
+ /**
201
+ * Metadata about results for formatters.
202
+ * @typedef {Object} ResultsMeta
203
+ * @property {MaxWarningsExceeded} [maxWarningsExceeded] Present if the maxWarnings threshold was exceeded.
204
+ */
205
+
193
206
  /**
194
207
  * A formatter function.
195
208
  * @callback FormatterFunction
196
209
  * @param {LintResult[]} results The list of linting results.
197
- * @param {{cwd: string, rulesMeta: Record<string, RuleMeta>}} [context] A context object.
210
+ * @param {{cwd: string, maxWarningsExceeded?: MaxWarningsExceeded, rulesMeta: Record<string, RuleMeta>}} [context] A context object.
198
211
  * @returns {string | Promise<string>} Formatted text.
199
212
  */
@@ -69,7 +69,7 @@ module.exports = class Cursor {
69
69
  * @returns {boolean} `true` if the next token exists.
70
70
  * @abstract
71
71
  */
72
- /* istanbul ignore next */
72
+ /* c8 ignore next */
73
73
  moveNext() { // eslint-disable-line class-methods-use-this -- Unused
74
74
  throw new Error("Not implemented.");
75
75
  }
@@ -3,6 +3,6 @@
3
3
  module.exports = function() {
4
4
  return `
5
5
  The '--print-config' CLI option requires a path to a source code file rather than a directory.
6
- See also: https://eslint.org/docs/user-guide/command-line-interface#--print-config
6
+ See also: https://eslint.org/docs/latest/use/command-line-interface#--print-config
7
7
  `.trimStart();
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "8.22.0",
3
+ "version": "8.33.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -13,22 +13,23 @@
13
13
  "./use-at-your-own-risk": "./lib/unsupported-api.js"
14
14
  },
15
15
  "scripts": {
16
+ "build:docs:update-links": "node tools/fetch-docs-links.js",
17
+ "build:site": "node Makefile.js gensite",
18
+ "build:webpack": "node Makefile.js webpack",
19
+ "build:readme": "node tools/update-readme.js",
20
+ "lint": "node Makefile.js lint",
21
+ "lint:docs:js": "node Makefile.js lintDocsJS",
22
+ "lint:fix": "node Makefile.js lint -- fix",
23
+ "lint:fix:docs:js": "node Makefile.js lintDocsJS -- fix",
24
+ "release:generate:alpha": "node Makefile.js generatePrerelease -- alpha",
25
+ "release:generate:beta": "node Makefile.js generatePrerelease -- beta",
26
+ "release:generate:latest": "node Makefile.js generateRelease",
27
+ "release:generate:rc": "node Makefile.js generatePrerelease -- rc",
28
+ "release:publish": "node Makefile.js publishRelease",
16
29
  "test": "node Makefile.js test",
17
30
  "test:cli": "mocha",
18
- "lint": "node Makefile.js lint",
19
- "lint:docsjs": "node Makefile.js lintDocsJS",
20
- "fix": "node Makefile.js lint -- fix",
21
- "fix:docsjs": "node Makefile.js lintDocsJS -- fix",
22
- "fuzz": "node Makefile.js fuzz",
23
- "generate-release": "node Makefile.js generateRelease",
24
- "generate-alpharelease": "node Makefile.js generatePrerelease -- alpha",
25
- "generate-betarelease": "node Makefile.js generatePrerelease -- beta",
26
- "generate-rcrelease": "node Makefile.js generatePrerelease -- rc",
27
- "publish-release": "node Makefile.js publishRelease",
28
- "gensite": "node Makefile.js gensite",
29
- "webpack": "node Makefile.js webpack",
30
- "perf": "node Makefile.js perf",
31
- "docs:update-links": "node tools/fetch-docs-links.js"
31
+ "test:fuzz": "node Makefile.js fuzz",
32
+ "test:performance": "node Makefile.js perf"
32
33
  },
33
34
  "gitHooks": {
34
35
  "pre-commit": "lint-staged"
@@ -55,9 +56,10 @@
55
56
  "homepage": "https://eslint.org",
56
57
  "bugs": "https://github.com/eslint/eslint/issues/",
57
58
  "dependencies": {
58
- "@eslint/eslintrc": "^1.3.0",
59
- "@humanwhocodes/config-array": "^0.10.4",
60
- "@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
59
+ "@eslint/eslintrc": "^1.4.1",
60
+ "@humanwhocodes/config-array": "^0.11.8",
61
+ "@humanwhocodes/module-importer": "^1.0.1",
62
+ "@nodelib/fs.walk": "^1.2.8",
61
63
  "ajv": "^6.10.0",
62
64
  "chalk": "^4.0.0",
63
65
  "cross-spawn": "^7.0.2",
@@ -67,21 +69,21 @@
67
69
  "eslint-scope": "^7.1.1",
68
70
  "eslint-utils": "^3.0.0",
69
71
  "eslint-visitor-keys": "^3.3.0",
70
- "espree": "^9.3.3",
72
+ "espree": "^9.4.0",
71
73
  "esquery": "^1.4.0",
72
74
  "esutils": "^2.0.2",
73
75
  "fast-deep-equal": "^3.1.3",
74
76
  "file-entry-cache": "^6.0.1",
75
77
  "find-up": "^5.0.0",
76
- "functional-red-black-tree": "^1.0.1",
77
- "glob-parent": "^6.0.1",
78
- "globals": "^13.15.0",
79
- "globby": "^11.1.0",
78
+ "glob-parent": "^6.0.2",
79
+ "globals": "^13.19.0",
80
80
  "grapheme-splitter": "^1.0.4",
81
81
  "ignore": "^5.2.0",
82
82
  "import-fresh": "^3.0.0",
83
83
  "imurmurhash": "^0.1.4",
84
84
  "is-glob": "^4.0.0",
85
+ "is-path-inside": "^3.0.3",
86
+ "js-sdsl": "^4.1.4",
85
87
  "js-yaml": "^4.1.0",
86
88
  "json-stable-stringify-without-jsonify": "^1.0.1",
87
89
  "levn": "^0.4.1",
@@ -92,13 +94,13 @@
92
94
  "regexpp": "^3.2.0",
93
95
  "strip-ansi": "^6.0.1",
94
96
  "strip-json-comments": "^3.1.0",
95
- "text-table": "^0.2.0",
96
- "v8-compile-cache": "^2.0.3"
97
+ "text-table": "^0.2.0"
97
98
  },
98
99
  "devDependencies": {
99
100
  "@babel/core": "^7.4.3",
100
101
  "@babel/preset-env": "^7.4.3",
101
102
  "babel-loader": "^8.0.5",
103
+ "c8": "^7.12.0",
102
104
  "chai": "^4.0.1",
103
105
  "cheerio": "^0.22.0",
104
106
  "common-tags": "^1.8.0",
@@ -120,7 +122,6 @@
120
122
  "glob": "^7.1.6",
121
123
  "got": "^11.8.3",
122
124
  "gray-matter": "^4.0.3",
123
- "jsdoc": "^3.5.5",
124
125
  "karma": "^6.1.1",
125
126
  "karma-chrome-launcher": "^3.1.0",
126
127
  "karma-mocha": "^2.0.1",
@@ -142,7 +143,6 @@
142
143
  "mocha-junit-reporter": "^2.0.0",
143
144
  "node-polyfill-webpack-plugin": "^1.0.3",
144
145
  "npm-license": "^0.3.3",
145
- "nyc": "^15.0.1",
146
146
  "pirates": "^4.0.5",
147
147
  "progress": "^2.0.3",
148
148
  "proxyquire": "^2.0.1",