eslint 9.5.0 → 9.7.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.
@@ -147,6 +147,36 @@ module.exports = {
147
147
  }
148
148
  }
149
149
 
150
+ /**
151
+ * Determines what variable type a def is.
152
+ * @param {Object} def the declaration to check
153
+ * @returns {VariableType} a simple name for the types of variables that this rule supports
154
+ */
155
+ function defToVariableType(def) {
156
+
157
+ /*
158
+ * This `destructuredArrayIgnorePattern` error report works differently from the catch
159
+ * clause and parameter error reports. _Both_ the `varsIgnorePattern` and the
160
+ * `destructuredArrayIgnorePattern` will be checked for array destructuring. However,
161
+ * for the purposes of the report, the currently defined behavior is to only inform the
162
+ * user of the `destructuredArrayIgnorePattern` if it's present (regardless of the fact
163
+ * that the `varsIgnorePattern` would also apply). If it's not present, the user will be
164
+ * informed of the `varsIgnorePattern`, assuming that's present.
165
+ */
166
+ if (config.destructuredArrayIgnorePattern && def.name.parent.type === "ArrayPattern") {
167
+ return "array-destructure";
168
+ }
169
+
170
+ switch (def.type) {
171
+ case "CatchClause":
172
+ return "catch-clause";
173
+ case "Parameter":
174
+ return "parameter";
175
+ default:
176
+ return "variable";
177
+ }
178
+ }
179
+
150
180
  /**
151
181
  * Gets a given variable's description and configured ignore pattern
152
182
  * based on the provided variableType
@@ -167,7 +197,7 @@ module.exports = {
167
197
 
168
198
  case "catch-clause":
169
199
  pattern = config.caughtErrorsIgnorePattern;
170
- variableDescription = "args";
200
+ variableDescription = "caught errors";
171
201
  break;
172
202
 
173
203
  case "parameter":
@@ -202,28 +232,7 @@ module.exports = {
202
232
  let additionalMessageData = "";
203
233
 
204
234
  if (def) {
205
- let pattern;
206
- let variableDescription;
207
-
208
- switch (def.type) {
209
- case "CatchClause":
210
- if (config.caughtErrorsIgnorePattern) {
211
- [variableDescription, pattern] = getVariableDescription("catch-clause");
212
- }
213
- break;
214
-
215
- case "Parameter":
216
- if (config.argsIgnorePattern) {
217
- [variableDescription, pattern] = getVariableDescription("parameter");
218
- }
219
- break;
220
-
221
- default:
222
- if (config.varsIgnorePattern) {
223
- [variableDescription, pattern] = getVariableDescription("variable");
224
- }
225
- break;
226
- }
235
+ const [variableDescription, pattern] = getVariableDescription(defToVariableType(def));
227
236
 
228
237
  if (pattern && variableDescription) {
229
238
  additionalMessageData = `. Allowed unused ${variableDescription} must match ${pattern}`;
@@ -248,14 +257,7 @@ module.exports = {
248
257
  let additionalMessageData = "";
249
258
 
250
259
  if (def) {
251
- let pattern;
252
- let variableDescription;
253
-
254
- if (def.name.parent.type === "ArrayPattern" && config.destructuredArrayIgnorePattern) {
255
- [variableDescription, pattern] = getVariableDescription("array-destructure");
256
- } else if (config.varsIgnorePattern) {
257
- [variableDescription, pattern] = getVariableDescription("variable");
258
- }
260
+ const [variableDescription, pattern] = getVariableDescription(defToVariableType(def));
259
261
 
260
262
  if (pattern && variableDescription) {
261
263
  additionalMessageData = `. Allowed unused ${variableDescription} must match ${pattern}`;
@@ -338,7 +340,7 @@ module.exports = {
338
340
  /**
339
341
  * Determines if a variable has a sibling rest property
340
342
  * @param {Variable} variable eslint-scope variable object.
341
- * @returns {boolean} True if the variable is exported, false if not.
343
+ * @returns {boolean} True if the variable has a sibling rest property, false if not.
342
344
  * @private
343
345
  */
344
346
  function hasRestSpreadSibling(variable) {
@@ -72,11 +72,11 @@ module.exports = {
72
72
  schema: [],
73
73
 
74
74
  messages: {
75
- nested: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' from within that group.",
76
- forward: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' which appears later in the pattern.",
77
- backward: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' which appears before in the same lookbehind.",
78
- disjunctive: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' which is in another alternative.",
79
- intoNegativeLookaround: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}' which is in a negative lookaround."
75
+ nested: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} from within that group.",
76
+ forward: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which appears later in the pattern.",
77
+ backward: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which appears before in the same lookbehind.",
78
+ disjunctive: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which is in another alternative.",
79
+ intoNegativeLookaround: "Backreference '{{ bref }}' will be ignored. It references group '{{ group }}'{{ otherGroups }} which is in a negative lookaround."
80
80
  }
81
81
  },
82
82
 
@@ -104,16 +104,21 @@ module.exports = {
104
104
 
105
105
  visitRegExpAST(regExpAST, {
106
106
  onBackreferenceEnter(bref) {
107
- const group = bref.resolved,
108
- brefPath = getPathToRoot(bref),
109
- groupPath = getPathToRoot(group);
110
- let messageId = null;
107
+ const groups = [bref.resolved].flat(),
108
+ brefPath = getPathToRoot(bref);
111
109
 
112
- if (brefPath.includes(group)) {
110
+ const problems = groups.map(group => {
111
+ const groupPath = getPathToRoot(group);
112
+
113
+ if (brefPath.includes(group)) {
114
+
115
+ // group is bref's ancestor => bref is nested ('nested reference') => group hasn't matched yet when bref starts to match.
116
+ return {
117
+ messageId: "nested",
118
+ group
119
+ };
120
+ }
113
121
 
114
- // group is bref's ancestor => bref is nested ('nested reference') => group hasn't matched yet when bref starts to match.
115
- messageId = "nested";
116
- } else {
117
122
 
118
123
  // Start from the root to find the lowest common ancestor.
119
124
  let i = brefPath.length - 1,
@@ -130,35 +135,80 @@ module.exports = {
130
135
  lowestCommonLookaround = commonPath.find(isLookaround),
131
136
  isMatchingBackward = lowestCommonLookaround && lowestCommonLookaround.kind === "lookbehind";
132
137
 
138
+ if (groupCut.at(-1).type === "Alternative") {
139
+
140
+ // group's and bref's ancestor nodes below the lowest common ancestor are sibling alternatives => they're disjunctive.
141
+ return {
142
+ messageId: "disjunctive",
143
+ group
144
+ };
145
+ }
133
146
  if (!isMatchingBackward && bref.end <= group.start) {
134
147
 
135
148
  // bref is left, group is right ('forward reference') => group hasn't matched yet when bref starts to match.
136
- messageId = "forward";
137
- } else if (isMatchingBackward && group.end <= bref.start) {
149
+ return {
150
+ messageId: "forward",
151
+ group
152
+ };
153
+ }
154
+ if (isMatchingBackward && group.end <= bref.start) {
138
155
 
139
156
  // the opposite of the previous when the regex is matching backward in a lookbehind context.
140
- messageId = "backward";
141
- } else if (groupCut.at(-1).type === "Alternative") {
142
-
143
- // group's and bref's ancestor nodes below the lowest common ancestor are sibling alternatives => they're disjunctive.
144
- messageId = "disjunctive";
145
- } else if (groupCut.some(isNegativeLookaround)) {
157
+ return {
158
+ messageId: "backward",
159
+ group
160
+ };
161
+ }
162
+ if (groupCut.some(isNegativeLookaround)) {
146
163
 
147
164
  // group is in a negative lookaround which isn't bref's ancestor => group has already failed when bref starts to match.
148
- messageId = "intoNegativeLookaround";
165
+ return {
166
+ messageId: "intoNegativeLookaround",
167
+ group
168
+ };
149
169
  }
170
+
171
+ return null;
172
+ });
173
+
174
+ if (problems.length === 0 || problems.some(problem => !problem)) {
175
+
176
+ // If there are no problems or no problems with any group then do not report it.
177
+ return;
150
178
  }
151
179
 
152
- if (messageId) {
153
- context.report({
154
- node,
155
- messageId,
156
- data: {
157
- bref: bref.raw,
158
- group: group.raw
159
- }
160
- });
180
+ let problemsToReport;
181
+
182
+ // Gets problems that appear in the same disjunction.
183
+ const problemsInSameDisjunction = problems.filter(problem => problem.messageId !== "disjunctive");
184
+
185
+ if (problemsInSameDisjunction.length) {
186
+
187
+ // Only report problems that appear in the same disjunction.
188
+ problemsToReport = problemsInSameDisjunction;
189
+ } else {
190
+
191
+ // If all groups appear in different disjunctions, report it.
192
+ problemsToReport = problems;
161
193
  }
194
+
195
+ const [{ messageId, group }, ...other] = problemsToReport;
196
+ let otherGroups = "";
197
+
198
+ if (other.length === 1) {
199
+ otherGroups = " and another group";
200
+ } else if (other.length > 1) {
201
+ otherGroups = ` and other ${other.length} groups`;
202
+ }
203
+ context.report({
204
+ node,
205
+ messageId,
206
+ data: {
207
+ bref: bref.raw,
208
+ group: group.raw,
209
+ otherGroups
210
+ }
211
+ });
162
212
  }
163
213
  });
164
214
  }
@@ -8,7 +8,7 @@
8
8
 
9
9
  const { RegExpValidator } = require("@eslint-community/regexpp");
10
10
 
11
- const REGEXPP_LATEST_ECMA_VERSION = 2024;
11
+ const REGEXPP_LATEST_ECMA_VERSION = 2025;
12
12
 
13
13
  /**
14
14
  * Checks if the given regular expression pattern would be valid with the `u` flag.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @fileoverview Shared flags for ESLint.
3
+ */
4
+
5
+ "use strict";
6
+
7
+ /**
8
+ * The set of flags that change ESLint behavior with a description.
9
+ * @type {Map<string, string>}
10
+ */
11
+ const activeFlags = new Map([
12
+ ["test_only", "This flag is only used for testing."]
13
+ ]);
14
+
15
+ /**
16
+ * The set of flags that used to be active but no longer have an effect.
17
+ * @type {Map<string, string>}
18
+ */
19
+ const inactiveFlags = new Map([
20
+ ["test_only_old", "This flag is no longer used for testing."]
21
+ ]);
22
+
23
+ module.exports = {
24
+ activeFlags,
25
+ inactiveFlags
26
+ };
@@ -11,7 +11,7 @@
11
11
  module.exports = {
12
12
 
13
13
  /**
14
- * Cover for console.log
14
+ * Cover for console.info
15
15
  * @param {...any} args The elements to log.
16
16
  * @returns {void}
17
17
  */
@@ -19,6 +19,15 @@ module.exports = {
19
19
  console.log(...args);
20
20
  },
21
21
 
22
+ /**
23
+ * Cover for console.warn
24
+ * @param {...any} args The elements to log.
25
+ * @returns {void}
26
+ */
27
+ warn(...args) {
28
+ console.warn(...args);
29
+ },
30
+
22
31
  /**
23
32
  * Cover for console.error
24
33
  * @param {...any} args The elements to log.
@@ -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|14|15|2015|2016|2017|2018|2019|2020|2021|2022|2023|2024} [ecmaVersion] The ECMAScript version (or revision number).
24
+ * @property {3|5|6|7|8|9|10|11|12|13|14|15|16|2015|2016|2017|2018|2019|2020|2021|2022|2023|2024|2025} [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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "9.5.0",
3
+ "version": "9.7.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -67,10 +67,10 @@
67
67
  "bugs": "https://github.com/eslint/eslint/issues/",
68
68
  "dependencies": {
69
69
  "@eslint-community/eslint-utils": "^4.2.0",
70
- "@eslint-community/regexpp": "^4.6.1",
71
- "@eslint/config-array": "^0.16.0",
70
+ "@eslint-community/regexpp": "^4.11.0",
71
+ "@eslint/config-array": "^0.17.0",
72
72
  "@eslint/eslintrc": "^3.1.0",
73
- "@eslint/js": "9.5.0",
73
+ "@eslint/js": "9.7.0",
74
74
  "@humanwhocodes/module-importer": "^1.0.1",
75
75
  "@humanwhocodes/retry": "^0.3.0",
76
76
  "@nodelib/fs.walk": "^1.2.8",
@@ -79,9 +79,9 @@
79
79
  "cross-spawn": "^7.0.2",
80
80
  "debug": "^4.3.2",
81
81
  "escape-string-regexp": "^4.0.0",
82
- "eslint-scope": "^8.0.1",
82
+ "eslint-scope": "^8.0.2",
83
83
  "eslint-visitor-keys": "^4.0.0",
84
- "espree": "^10.0.1",
84
+ "espree": "^10.1.0",
85
85
  "esquery": "^1.5.0",
86
86
  "esutils": "^2.0.2",
87
87
  "fast-deep-equal": "^3.1.3",
@@ -104,13 +104,12 @@
104
104
  "devDependencies": {
105
105
  "@babel/core": "^7.4.3",
106
106
  "@babel/preset-env": "^7.4.3",
107
- "@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
107
+ "@eslint/core": "^0.1.0",
108
108
  "@types/estree": "^1.0.5",
109
109
  "@types/node": "^20.11.5",
110
110
  "@wdio/browser-runner": "^8.38.3",
111
111
  "@wdio/cli": "^8.38.2",
112
112
  "@wdio/concise-reporter": "^8.38.2",
113
- "@wdio/globals": "^8.38.2",
114
113
  "@wdio/mocha-framework": "^8.38.2",
115
114
  "babel-loader": "^8.0.5",
116
115
  "c8": "^7.12.0",
@@ -122,11 +121,8 @@
122
121
  "eslint": "file:.",
123
122
  "eslint-config-eslint": "file:packages/eslint-config-eslint",
124
123
  "eslint-plugin-eslint-plugin": "^6.0.0",
125
- "eslint-plugin-internal-rules": "file:tools/internal-rules",
126
- "eslint-plugin-jsdoc": "^48.2.3",
127
- "eslint-plugin-n": "^17.2.0",
128
- "eslint-plugin-unicorn": "^52.0.0",
129
124
  "eslint-release": "^3.2.2",
125
+ "eslint-rule-composer": "^0.3.0",
130
126
  "eslump": "^3.0.0",
131
127
  "esprima": "^4.0.1",
132
128
  "fast-glob": "^3.2.11",
@@ -136,7 +132,7 @@
136
132
  "got": "^11.8.3",
137
133
  "gray-matter": "^4.0.3",
138
134
  "js-yaml": "^4.1.0",
139
- "knip": "^5.8.0",
135
+ "knip": "^5.21.0",
140
136
  "lint-staged": "^11.0.0",
141
137
  "load-perf": "^0.2.0",
142
138
  "markdown-it": "^12.2.0",