eslint 8.34.0 → 8.38.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 (104) hide show
  1. package/README.md +6 -12
  2. package/conf/rule-type-list.json +2 -2
  3. package/lib/cli-engine/cli-engine.js +2 -2
  4. package/lib/cli-engine/file-enumerator.js +8 -6
  5. package/lib/config/default-config.js +1 -4
  6. package/lib/config/flat-config-array.js +77 -17
  7. package/lib/config/flat-config-schema.js +4 -18
  8. package/lib/eslint/eslint-helpers.js +3 -3
  9. package/lib/linter/linter.js +7 -48
  10. package/lib/rule-tester/flat-rule-tester.js +1 -1
  11. package/lib/rule-tester/rule-tester.js +1 -1
  12. package/lib/rules/block-scoped-var.js +2 -1
  13. package/lib/rules/camelcase.js +5 -4
  14. package/lib/rules/consistent-this.js +4 -2
  15. package/lib/rules/func-names.js +1 -1
  16. package/lib/rules/global-require.js +4 -2
  17. package/lib/rules/handle-callback-err.js +2 -1
  18. package/lib/rules/id-blacklist.js +3 -2
  19. package/lib/rules/id-denylist.js +3 -2
  20. package/lib/rules/id-match.js +3 -2
  21. package/lib/rules/lines-around-comment.js +11 -0
  22. package/lib/rules/logical-assignment-operators.js +4 -4
  23. package/lib/rules/multiline-comment-style.js +42 -3
  24. package/lib/rules/new-parens.js +5 -14
  25. package/lib/rules/no-alert.js +3 -1
  26. package/lib/rules/no-catch-shadow.js +3 -1
  27. package/lib/rules/no-class-assign.js +3 -1
  28. package/lib/rules/no-console.js +3 -2
  29. package/lib/rules/no-const-assign.js +3 -1
  30. package/lib/rules/no-constant-binary-expression.js +36 -27
  31. package/lib/rules/no-constant-condition.js +3 -2
  32. package/lib/rules/no-control-regex.js +1 -1
  33. package/lib/rules/no-div-regex.js +1 -1
  34. package/lib/rules/no-dupe-args.js +3 -1
  35. package/lib/rules/no-else-return.js +13 -12
  36. package/lib/rules/no-eval.js +5 -5
  37. package/lib/rules/no-ex-assign.js +3 -1
  38. package/lib/rules/no-extend-native.js +3 -2
  39. package/lib/rules/no-extra-boolean-cast.js +1 -1
  40. package/lib/rules/no-extra-parens.js +1 -1
  41. package/lib/rules/no-func-assign.js +3 -1
  42. package/lib/rules/no-global-assign.js +3 -2
  43. package/lib/rules/no-implicit-globals.js +3 -2
  44. package/lib/rules/no-implied-eval.js +5 -4
  45. package/lib/rules/no-import-assign.js +5 -3
  46. package/lib/rules/no-invalid-regexp.js +1 -1
  47. package/lib/rules/no-invalid-this.js +2 -2
  48. package/lib/rules/no-label-var.js +2 -1
  49. package/lib/rules/no-lone-blocks.js +8 -6
  50. package/lib/rules/no-lonely-if.js +1 -1
  51. package/lib/rules/no-loop-func.js +3 -1
  52. package/lib/rules/no-misleading-character-class.js +12 -41
  53. package/lib/rules/no-native-reassign.js +3 -2
  54. package/lib/rules/no-new-func.js +7 -6
  55. package/lib/rules/no-new-native-nonconstructor.js +8 -6
  56. package/lib/rules/no-new-object.js +4 -1
  57. package/lib/rules/no-new-symbol.js +8 -6
  58. package/lib/rules/no-obj-calls.js +8 -6
  59. package/lib/rules/no-param-reassign.js +2 -1
  60. package/lib/rules/no-promise-executor-return.js +3 -2
  61. package/lib/rules/no-redeclare.js +3 -3
  62. package/lib/rules/no-regex-spaces.js +4 -2
  63. package/lib/rules/no-restricted-exports.js +2 -1
  64. package/lib/rules/no-restricted-globals.js +4 -2
  65. package/lib/rules/no-setter-return.js +3 -2
  66. package/lib/rules/no-shadow-restricted-names.js +2 -1
  67. package/lib/rules/no-shadow.js +3 -2
  68. package/lib/rules/no-undef-init.js +1 -1
  69. package/lib/rules/no-undef.js +3 -2
  70. package/lib/rules/no-undefined.js +4 -2
  71. package/lib/rules/no-underscore-dangle.js +2 -1
  72. package/lib/rules/no-unmodified-loop-condition.js +2 -2
  73. package/lib/rules/no-unused-expressions.js +3 -2
  74. package/lib/rules/no-unused-vars.js +2 -2
  75. package/lib/rules/no-use-before-define.js +3 -2
  76. package/lib/rules/no-useless-backreference.js +9 -7
  77. package/lib/rules/no-useless-return.js +1 -1
  78. package/lib/rules/no-var.js +2 -2
  79. package/lib/rules/object-shorthand.js +3 -2
  80. package/lib/rules/prefer-arrow-callback.js +2 -2
  81. package/lib/rules/prefer-const.js +1 -1
  82. package/lib/rules/prefer-exponentiation-operator.js +5 -5
  83. package/lib/rules/prefer-named-capture-group.js +8 -8
  84. package/lib/rules/prefer-object-has-own.js +4 -2
  85. package/lib/rules/prefer-object-spread.js +12 -12
  86. package/lib/rules/prefer-promise-reject-errors.js +2 -1
  87. package/lib/rules/prefer-regex-literals.js +26 -27
  88. package/lib/rules/prefer-rest-params.js +5 -2
  89. package/lib/rules/radix.js +11 -11
  90. package/lib/rules/require-atomic-updates.js +2 -2
  91. package/lib/rules/require-unicode-regexp.js +67 -7
  92. package/lib/rules/symbol-description.js +7 -5
  93. package/lib/rules/utils/regular-expressions.js +42 -0
  94. package/lib/rules/valid-typeof.js +4 -4
  95. package/lib/rules/wrap-iife.js +1 -1
  96. package/lib/rules/wrap-regex.js +1 -1
  97. package/lib/rules/yoda.js +1 -1
  98. package/lib/source-code/source-code.js +94 -1
  99. package/lib/source-code/token-store/index.js +1 -1
  100. package/lib/source-code/token-store/utils.js +14 -4
  101. package/messages/no-config-found.js +1 -1
  102. package/package.json +12 -7
  103. package/conf/eslint-all.js +0 -31
  104. package/conf/eslint-recommended.js +0 -76
@@ -104,6 +104,7 @@ module.exports = {
104
104
 
105
105
  create(context) {
106
106
  const mode = context.options[0] || MODE_ALWAYS;
107
+ const sourceCode = context.getSourceCode();
107
108
 
108
109
  /**
109
110
  * Checks the arguments of a given CallExpression node and reports it if it
@@ -131,7 +132,6 @@ module.exports = {
131
132
  {
132
133
  messageId: "addRadixParameter10",
133
134
  fix(fixer) {
134
- const sourceCode = context.getSourceCode();
135
135
  const tokens = sourceCode.getTokens(node);
136
136
  const lastToken = tokens[tokens.length - 1]; // Parenthesis.
137
137
  const secondToLastToken = tokens[tokens.length - 2]; // May or may not be a comma.
@@ -162,18 +162,18 @@ module.exports = {
162
162
  }
163
163
 
164
164
  return {
165
- "Program:exit"() {
166
- const scope = context.getScope();
165
+ "Program:exit"(node) {
166
+ const scope = sourceCode.getScope(node);
167
167
  let variable;
168
168
 
169
169
  // Check `parseInt()`
170
170
  variable = astUtils.getVariableByName(scope, "parseInt");
171
171
  if (variable && !isShadowed(variable)) {
172
172
  variable.references.forEach(reference => {
173
- const node = reference.identifier;
173
+ const idNode = reference.identifier;
174
174
 
175
- if (astUtils.isCallee(node)) {
176
- checkArguments(node.parent);
175
+ if (astUtils.isCallee(idNode)) {
176
+ checkArguments(idNode.parent);
177
177
  }
178
178
  });
179
179
  }
@@ -182,12 +182,12 @@ module.exports = {
182
182
  variable = astUtils.getVariableByName(scope, "Number");
183
183
  if (variable && !isShadowed(variable)) {
184
184
  variable.references.forEach(reference => {
185
- const node = reference.identifier.parent;
186
- const maybeCallee = node.parent.type === "ChainExpression"
187
- ? node.parent
188
- : node;
185
+ const parentNode = reference.identifier.parent;
186
+ const maybeCallee = parentNode.parent.type === "ChainExpression"
187
+ ? parentNode.parent
188
+ : parentNode;
189
189
 
190
- if (isParseIntMethod(node) && astUtils.isCallee(maybeCallee)) {
190
+ if (isParseIntMethod(parentNode) && astUtils.isCallee(maybeCallee)) {
191
191
  checkArguments(maybeCallee.parent);
192
192
  }
193
193
  });
@@ -204,8 +204,8 @@ module.exports = {
204
204
  let stack = null;
205
205
 
206
206
  return {
207
- onCodePathStart(codePath) {
208
- const scope = context.getScope();
207
+ onCodePathStart(codePath, node) {
208
+ const scope = sourceCode.getScope(node);
209
209
  const shouldVerify =
210
210
  scope.type === "function" &&
211
211
  (scope.block.async || scope.block.generator);
@@ -14,7 +14,9 @@ const {
14
14
  CONSTRUCT,
15
15
  ReferenceTracker,
16
16
  getStringIfConstant
17
- } = require("eslint-utils");
17
+ } = require("@eslint-community/eslint-utils");
18
+ const astUtils = require("./utils/ast-utils.js");
19
+ const { isValidWithUnicodeFlag } = require("./utils/regular-expressions");
18
20
 
19
21
  //------------------------------------------------------------------------------
20
22
  // Rule Definition
@@ -31,7 +33,10 @@ module.exports = {
31
33
  url: "https://eslint.org/docs/rules/require-unicode-regexp"
32
34
  },
33
35
 
36
+ hasSuggestions: true,
37
+
34
38
  messages: {
39
+ addUFlag: "Add the 'u' flag.",
35
40
  requireUFlag: "Use the 'u' flag."
36
41
  },
37
42
 
@@ -39,28 +44,83 @@ module.exports = {
39
44
  },
40
45
 
41
46
  create(context) {
47
+
48
+ const sourceCode = context.getSourceCode();
49
+
42
50
  return {
43
51
  "Literal[regex]"(node) {
44
52
  const flags = node.regex.flags || "";
45
53
 
46
54
  if (!flags.includes("u")) {
47
- context.report({ node, messageId: "requireUFlag" });
55
+ context.report({
56
+ messageId: "requireUFlag",
57
+ node,
58
+ suggest: isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, node.regex.pattern)
59
+ ? [
60
+ {
61
+ fix(fixer) {
62
+ return fixer.insertTextAfter(node, "u");
63
+ },
64
+ messageId: "addUFlag"
65
+ }
66
+ ]
67
+ : null
68
+ });
48
69
  }
49
70
  },
50
71
 
51
- Program() {
52
- const scope = context.getScope();
72
+ Program(node) {
73
+ const scope = sourceCode.getScope(node);
53
74
  const tracker = new ReferenceTracker(scope);
54
75
  const trackMap = {
55
76
  RegExp: { [CALL]: true, [CONSTRUCT]: true }
56
77
  };
57
78
 
58
- for (const { node } of tracker.iterateGlobalReferences(trackMap)) {
59
- const flagsNode = node.arguments[1];
79
+ for (const { node: refNode } of tracker.iterateGlobalReferences(trackMap)) {
80
+ const [patternNode, flagsNode] = refNode.arguments;
81
+
82
+ if (patternNode && patternNode.type === "SpreadElement") {
83
+ continue;
84
+ }
85
+ const pattern = getStringIfConstant(patternNode, scope);
60
86
  const flags = getStringIfConstant(flagsNode, scope);
61
87
 
62
88
  if (!flagsNode || (typeof flags === "string" && !flags.includes("u"))) {
63
- context.report({ node, messageId: "requireUFlag" });
89
+ context.report({
90
+ messageId: "requireUFlag",
91
+ node: refNode,
92
+ suggest: typeof pattern === "string" && isValidWithUnicodeFlag(context.languageOptions.ecmaVersion, pattern)
93
+ ? [
94
+ {
95
+ fix(fixer) {
96
+ if (flagsNode) {
97
+ if ((flagsNode.type === "Literal" && typeof flagsNode.value === "string") || flagsNode.type === "TemplateLiteral") {
98
+ const flagsNodeText = sourceCode.getText(flagsNode);
99
+
100
+ return fixer.replaceText(flagsNode, [
101
+ flagsNodeText.slice(0, flagsNodeText.length - 1),
102
+ flagsNodeText.slice(flagsNodeText.length - 1)
103
+ ].join("u"));
104
+ }
105
+
106
+ // We intentionally don't suggest concatenating + "u" to non-literals
107
+ return null;
108
+ }
109
+
110
+ const penultimateToken = sourceCode.getLastToken(refNode, { skip: 1 }); // skip closing parenthesis
111
+
112
+ return fixer.insertTextAfter(
113
+ penultimateToken,
114
+ astUtils.isCommaToken(penultimateToken)
115
+ ? ' "u",'
116
+ : ', "u"'
117
+ );
118
+ },
119
+ messageId: "addUFlag"
120
+ }
121
+ ]
122
+ : null
123
+ });
64
124
  }
65
125
  }
66
126
  }
@@ -35,6 +35,8 @@ module.exports = {
35
35
 
36
36
  create(context) {
37
37
 
38
+ const sourceCode = context.getSourceCode();
39
+
38
40
  /**
39
41
  * Reports if node does not conform the rule in case rule is set to
40
42
  * report missing description
@@ -51,16 +53,16 @@ module.exports = {
51
53
  }
52
54
 
53
55
  return {
54
- "Program:exit"() {
55
- const scope = context.getScope();
56
+ "Program:exit"(node) {
57
+ const scope = sourceCode.getScope(node);
56
58
  const variable = astUtils.getVariableByName(scope, "Symbol");
57
59
 
58
60
  if (variable && variable.defs.length === 0) {
59
61
  variable.references.forEach(reference => {
60
- const node = reference.identifier;
62
+ const idNode = reference.identifier;
61
63
 
62
- if (astUtils.isCallee(node)) {
63
- checkArgument(node.parent);
64
+ if (astUtils.isCallee(idNode)) {
65
+ checkArgument(idNode.parent);
64
66
  }
65
67
  });
66
68
  }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @fileoverview Common utils for regular expressions.
3
+ * @author Josh Goldberg
4
+ * @author Toru Nagashima
5
+ */
6
+
7
+ "use strict";
8
+
9
+ const { RegExpValidator } = require("@eslint-community/regexpp");
10
+
11
+ const REGEXPP_LATEST_ECMA_VERSION = 2022;
12
+
13
+ /**
14
+ * Checks if the given regular expression pattern would be valid with the `u` flag.
15
+ * @param {number} ecmaVersion ECMAScript version to parse in.
16
+ * @param {string} pattern The regular expression pattern to verify.
17
+ * @returns {boolean} `true` if the pattern would be valid with the `u` flag.
18
+ * `false` if the pattern would be invalid with the `u` flag or the configured
19
+ * ecmaVersion doesn't support the `u` flag.
20
+ */
21
+ function isValidWithUnicodeFlag(ecmaVersion, pattern) {
22
+ if (ecmaVersion <= 5) { // ecmaVersion <= 5 doesn't support the 'u' flag
23
+ return false;
24
+ }
25
+
26
+ const validator = new RegExpValidator({
27
+ ecmaVersion: Math.min(ecmaVersion, REGEXPP_LATEST_ECMA_VERSION)
28
+ });
29
+
30
+ try {
31
+ validator.validatePattern(pattern, void 0, void 0, /* uFlag = */ true);
32
+ } catch {
33
+ return false;
34
+ }
35
+
36
+ return true;
37
+ }
38
+
39
+ module.exports = {
40
+ isValidWithUnicodeFlag,
41
+ REGEXPP_LATEST_ECMA_VERSION
42
+ };
@@ -44,7 +44,7 @@ module.exports = {
44
44
 
45
45
  const VALID_TYPES = new Set(["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"]),
46
46
  OPERATORS = new Set(["==", "===", "!=", "!=="]);
47
-
47
+ const sourceCode = context.getSourceCode();
48
48
  const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals;
49
49
 
50
50
  let globalScope;
@@ -77,13 +77,13 @@ module.exports = {
77
77
 
78
78
  return {
79
79
 
80
- Program() {
81
- globalScope = context.getScope();
80
+ Program(node) {
81
+ globalScope = sourceCode.getScope(node);
82
82
  },
83
83
 
84
84
  UnaryExpression(node) {
85
85
  if (isTypeofExpression(node)) {
86
- const parent = context.getAncestors().pop();
86
+ const parent = sourceCode.getAncestors(node).pop();
87
87
 
88
88
  if (parent.type === "BinaryExpression" && OPERATORS.has(parent.operator)) {
89
89
  const sibling = parent.left === node ? parent.right : parent.left;
@@ -10,7 +10,7 @@
10
10
  //------------------------------------------------------------------------------
11
11
 
12
12
  const astUtils = require("./utils/ast-utils");
13
- const eslintUtils = require("eslint-utils");
13
+ const eslintUtils = require("@eslint-community/eslint-utils");
14
14
 
15
15
  //----------------------------------------------------------------------
16
16
  // Helpers
@@ -40,7 +40,7 @@ module.exports = {
40
40
  if (nodeType === "RegularExpression") {
41
41
  const beforeToken = sourceCode.getTokenBefore(node);
42
42
  const afterToken = sourceCode.getTokenAfter(node);
43
- const ancestors = context.getAncestors();
43
+ const ancestors = sourceCode.getAncestors(node);
44
44
  const grandparent = ancestors[ancestors.length - 1];
45
45
 
46
46
  if (grandparent.type === "MemberExpression" && grandparent.object === node &&
package/lib/rules/yoda.js CHANGED
@@ -343,7 +343,7 @@ module.exports = {
343
343
  ) &&
344
344
  !(!isEqualityOperator(node.operator) && onlyEquality) &&
345
345
  isComparisonOperator(node.operator) &&
346
- !(exceptRange && isRangeTest(context.getAncestors().pop()))
346
+ !(exceptRange && isRangeTest(sourceCode.getAncestors(node).pop()))
347
347
  ) {
348
348
  context.report({
349
349
  node,
@@ -9,11 +9,17 @@
9
9
  //------------------------------------------------------------------------------
10
10
 
11
11
  const
12
- { isCommentToken } = require("eslint-utils"),
12
+ { isCommentToken } = require("@eslint-community/eslint-utils"),
13
13
  TokenStore = require("./token-store"),
14
14
  astUtils = require("../shared/ast-utils"),
15
15
  Traverser = require("../shared/traverser");
16
16
 
17
+ //------------------------------------------------------------------------------
18
+ // Type Definitions
19
+ //------------------------------------------------------------------------------
20
+
21
+ /** @typedef {import("eslint-scope").Variable} Variable */
22
+
17
23
  //------------------------------------------------------------------------------
18
24
  // Private
19
25
  //------------------------------------------------------------------------------
@@ -143,6 +149,8 @@ function isSpaceBetween(sourceCode, first, second, checkInsideOfJSXText) {
143
149
  // Public Interface
144
150
  //------------------------------------------------------------------------------
145
151
 
152
+ const caches = Symbol("caches");
153
+
146
154
  /**
147
155
  * Represents parsed source code.
148
156
  */
@@ -175,6 +183,13 @@ class SourceCode extends TokenStore {
175
183
  validate(ast);
176
184
  super(ast.tokens, ast.comments);
177
185
 
186
+ /**
187
+ * General purpose caching for the class.
188
+ */
189
+ this[caches] = new Map([
190
+ ["scopes", new WeakMap()]
191
+ ]);
192
+
178
193
  /**
179
194
  * The flag to indicate that the source code has Unicode BOM.
180
195
  * @type {boolean}
@@ -588,6 +603,84 @@ class SourceCode extends TokenStore {
588
603
 
589
604
  return positionIndex;
590
605
  }
606
+
607
+ /**
608
+ * Gets the scope for the given node
609
+ * @param {ASTNode} currentNode The node to get the scope of
610
+ * @returns {eslint-scope.Scope} The scope information for this node
611
+ * @throws {TypeError} If the `currentNode` argument is missing.
612
+ */
613
+ getScope(currentNode) {
614
+
615
+ if (!currentNode) {
616
+ throw new TypeError("Missing required argument: node.");
617
+ }
618
+
619
+ // check cache first
620
+ const cache = this[caches].get("scopes");
621
+ const cachedScope = cache.get(currentNode);
622
+
623
+ if (cachedScope) {
624
+ return cachedScope;
625
+ }
626
+
627
+ // On Program node, get the outermost scope to avoid return Node.js special function scope or ES modules scope.
628
+ const inner = currentNode.type !== "Program";
629
+
630
+ for (let node = currentNode; node; node = node.parent) {
631
+ const scope = this.scopeManager.acquire(node, inner);
632
+
633
+ if (scope) {
634
+ if (scope.type === "function-expression-name") {
635
+ cache.set(currentNode, scope.childScopes[0]);
636
+ return scope.childScopes[0];
637
+ }
638
+
639
+ cache.set(currentNode, scope);
640
+ return scope;
641
+ }
642
+ }
643
+
644
+ cache.set(currentNode, this.scopeManager.scopes[0]);
645
+ return this.scopeManager.scopes[0];
646
+ }
647
+
648
+ /**
649
+ * Gets all of the declared variables in the scope associated
650
+ * with `node`. This is a convenience method that passes through
651
+ * to the same method on the `scopeManager`.
652
+ * @param {ASTNode} node The node from which to retrieve the scope to check.
653
+ * @returns {Array<Variable>} An array of variable nodes representing
654
+ * the declared variables in the scope associated with `node`.
655
+ */
656
+ getDeclaredVariables(node) {
657
+ return this.scopeManager.getDeclaredVariables(node);
658
+ }
659
+
660
+ /* eslint-disable class-methods-use-this -- node is owned by SourceCode */
661
+ /**
662
+ * Gets all the ancestors of a given node
663
+ * @param {ASTNode} node The node
664
+ * @returns {Array<ASTNode>} All the ancestor nodes in the AST, not including the provided node, starting
665
+ * from the root node at index 0 and going inwards to the parent node.
666
+ * @throws {TypeError} When `node` is missing.
667
+ */
668
+ getAncestors(node) {
669
+
670
+ if (!node) {
671
+ throw new TypeError("Missing required argument: node.");
672
+ }
673
+
674
+ const ancestorsStartingAtParent = [];
675
+
676
+ for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
677
+ ancestorsStartingAtParent.push(ancestor);
678
+ }
679
+
680
+ return ancestorsStartingAtParent.reverse();
681
+ }
682
+ /* eslint-enable class-methods-use-this -- node is owned by SourceCode */
683
+
591
684
  }
592
685
 
593
686
  module.exports = SourceCode;
@@ -9,7 +9,7 @@
9
9
  //------------------------------------------------------------------------------
10
10
 
11
11
  const assert = require("assert");
12
- const { isCommentToken } = require("eslint-utils");
12
+ const { isCommentToken } = require("@eslint-community/eslint-utils");
13
13
  const cursors = require("./cursors");
14
14
  const ForwardTokenCursor = require("./forward-token-cursor");
15
15
  const PaddedTokenCursor = require("./padded-token-cursor");
@@ -49,13 +49,18 @@ exports.getFirstIndex = function getFirstIndex(tokens, indexMap, startLoc) {
49
49
  }
50
50
  if ((startLoc - 1) in indexMap) {
51
51
  const index = indexMap[startLoc - 1];
52
- const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
52
+ const token = tokens[index];
53
+
54
+ // If the mapped index is out of bounds, the returned cursor index will point after the end of the tokens array.
55
+ if (!token) {
56
+ return tokens.length;
57
+ }
53
58
 
54
59
  /*
55
60
  * For the map of "comment's location -> token's index", it points the next token of a comment.
56
61
  * In that case, +1 is unnecessary.
57
62
  */
58
- if (token && token.range[0] >= startLoc) {
63
+ if (token.range[0] >= startLoc) {
59
64
  return index;
60
65
  }
61
66
  return index + 1;
@@ -77,13 +82,18 @@ exports.getLastIndex = function getLastIndex(tokens, indexMap, endLoc) {
77
82
  }
78
83
  if ((endLoc - 1) in indexMap) {
79
84
  const index = indexMap[endLoc - 1];
80
- const token = (index >= 0 && index < tokens.length) ? tokens[index] : null;
85
+ const token = tokens[index];
86
+
87
+ // If the mapped index is out of bounds, the returned cursor index will point before the end of the tokens array.
88
+ if (!token) {
89
+ return tokens.length - 1;
90
+ }
81
91
 
82
92
  /*
83
93
  * For the map of "comment's location -> token's index", it points the next token of a comment.
84
94
  * In that case, -1 is necessary.
85
95
  */
86
- if (token && token.range[1] > endLoc) {
96
+ if (token.range[1] > endLoc) {
87
97
  return index - 1;
88
98
  }
89
99
  return index;
@@ -10,6 +10,6 @@ ESLint couldn't find a configuration file. To set up a configuration file for th
10
10
 
11
11
  ESLint looked for configuration files in ${directoryPath} and its ancestors. If it found none, it then looked in your home directory.
12
12
 
13
- If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://eslint.org/chat/help
13
+ If you think you already have a configuration file or if you need more help, please stop by the ESLint Discord server: https://eslint.org/chat
14
14
  `.trimStart();
15
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "8.34.0",
3
+ "version": "8.38.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -37,6 +37,10 @@
37
37
  "lint-staged": {
38
38
  "*.js": "eslint --fix",
39
39
  "*.md": "markdownlint --fix",
40
+ "lib/rules/*.js": [
41
+ "node tools/update-eslint-all.js",
42
+ "git add packages/js/src/configs/eslint-all.js"
43
+ ],
40
44
  "docs/src/rules/*.md": [
41
45
  "node tools/fetch-docs-links.js",
42
46
  "git add docs/src/_data/further_reading_links.json"
@@ -56,7 +60,10 @@
56
60
  "homepage": "https://eslint.org",
57
61
  "bugs": "https://github.com/eslint/eslint/issues/",
58
62
  "dependencies": {
59
- "@eslint/eslintrc": "^1.4.1",
63
+ "@eslint-community/eslint-utils": "^4.2.0",
64
+ "@eslint-community/regexpp": "^4.4.0",
65
+ "@eslint/eslintrc": "^2.0.2",
66
+ "@eslint/js": "8.38.0",
60
67
  "@humanwhocodes/config-array": "^0.11.8",
61
68
  "@humanwhocodes/module-importer": "^1.0.1",
62
69
  "@nodelib/fs.walk": "^1.2.8",
@@ -67,10 +74,9 @@
67
74
  "doctrine": "^3.0.0",
68
75
  "escape-string-regexp": "^4.0.0",
69
76
  "eslint-scope": "^7.1.1",
70
- "eslint-utils": "^3.0.0",
71
- "eslint-visitor-keys": "^3.3.0",
72
- "espree": "^9.4.0",
73
- "esquery": "^1.4.0",
77
+ "eslint-visitor-keys": "^3.4.0",
78
+ "espree": "^9.5.1",
79
+ "esquery": "^1.4.2",
74
80
  "esutils": "^2.0.2",
75
81
  "fast-deep-equal": "^3.1.3",
76
82
  "file-entry-cache": "^6.0.1",
@@ -91,7 +97,6 @@
91
97
  "minimatch": "^3.1.2",
92
98
  "natural-compare": "^1.4.0",
93
99
  "optionator": "^0.9.1",
94
- "regexpp": "^3.2.0",
95
100
  "strip-ansi": "^6.0.1",
96
101
  "strip-json-comments": "^3.1.0",
97
102
  "text-table": "^0.2.0"
@@ -1,31 +0,0 @@
1
- /**
2
- * @fileoverview Config to enable all rules.
3
- * @author Robert Fletcher
4
- */
5
-
6
- "use strict";
7
-
8
- //------------------------------------------------------------------------------
9
- // Requirements
10
- //------------------------------------------------------------------------------
11
-
12
- const builtInRules = require("../lib/rules");
13
-
14
- //------------------------------------------------------------------------------
15
- // Helpers
16
- //------------------------------------------------------------------------------
17
-
18
- const allRules = {};
19
-
20
- for (const [ruleId, rule] of builtInRules) {
21
- if (!rule.meta.deprecated) {
22
- allRules[ruleId] = "error";
23
- }
24
- }
25
-
26
- //------------------------------------------------------------------------------
27
- // Public Interface
28
- //------------------------------------------------------------------------------
29
-
30
- /** @type {import("../lib/shared/types").ConfigData} */
31
- module.exports = { rules: allRules };
@@ -1,76 +0,0 @@
1
- /**
2
- * @fileoverview Configuration applied when a user configuration extends from
3
- * eslint:recommended.
4
- * @author Nicholas C. Zakas
5
- */
6
-
7
- "use strict";
8
-
9
- /* eslint sort-keys: ["error", "asc"] -- Long, so make more readable */
10
-
11
- /** @type {import("../lib/shared/types").ConfigData} */
12
- module.exports = {
13
- rules: {
14
- "constructor-super": "error",
15
- "for-direction": "error",
16
- "getter-return": "error",
17
- "no-async-promise-executor": "error",
18
- "no-case-declarations": "error",
19
- "no-class-assign": "error",
20
- "no-compare-neg-zero": "error",
21
- "no-cond-assign": "error",
22
- "no-const-assign": "error",
23
- "no-constant-condition": "error",
24
- "no-control-regex": "error",
25
- "no-debugger": "error",
26
- "no-delete-var": "error",
27
- "no-dupe-args": "error",
28
- "no-dupe-class-members": "error",
29
- "no-dupe-else-if": "error",
30
- "no-dupe-keys": "error",
31
- "no-duplicate-case": "error",
32
- "no-empty": "error",
33
- "no-empty-character-class": "error",
34
- "no-empty-pattern": "error",
35
- "no-ex-assign": "error",
36
- "no-extra-boolean-cast": "error",
37
- "no-extra-semi": "error",
38
- "no-fallthrough": "error",
39
- "no-func-assign": "error",
40
- "no-global-assign": "error",
41
- "no-import-assign": "error",
42
- "no-inner-declarations": "error",
43
- "no-invalid-regexp": "error",
44
- "no-irregular-whitespace": "error",
45
- "no-loss-of-precision": "error",
46
- "no-misleading-character-class": "error",
47
- "no-mixed-spaces-and-tabs": "error",
48
- "no-new-symbol": "error",
49
- "no-nonoctal-decimal-escape": "error",
50
- "no-obj-calls": "error",
51
- "no-octal": "error",
52
- "no-prototype-builtins": "error",
53
- "no-redeclare": "error",
54
- "no-regex-spaces": "error",
55
- "no-self-assign": "error",
56
- "no-setter-return": "error",
57
- "no-shadow-restricted-names": "error",
58
- "no-sparse-arrays": "error",
59
- "no-this-before-super": "error",
60
- "no-undef": "error",
61
- "no-unexpected-multiline": "error",
62
- "no-unreachable": "error",
63
- "no-unsafe-finally": "error",
64
- "no-unsafe-negation": "error",
65
- "no-unsafe-optional-chaining": "error",
66
- "no-unused-labels": "error",
67
- "no-unused-vars": "error",
68
- "no-useless-backreference": "error",
69
- "no-useless-catch": "error",
70
- "no-useless-escape": "error",
71
- "no-with": "error",
72
- "require-yield": "error",
73
- "use-isnan": "error",
74
- "valid-typeof": "error"
75
- }
76
- };