eslint 8.38.0 → 8.40.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 (301) hide show
  1. package/README.md +3 -7
  2. package/lib/config/flat-config-schema.js +57 -35
  3. package/lib/eslint/flat-eslint.js +56 -16
  4. package/lib/linter/linter.js +7 -35
  5. package/lib/rules/accessor-pairs.js +2 -2
  6. package/lib/rules/array-bracket-newline.js +2 -2
  7. package/lib/rules/array-bracket-spacing.js +2 -2
  8. package/lib/rules/array-callback-return.js +2 -2
  9. package/lib/rules/array-element-newline.js +2 -2
  10. package/lib/rules/arrow-body-style.js +2 -2
  11. package/lib/rules/arrow-parens.js +2 -2
  12. package/lib/rules/arrow-spacing.js +2 -2
  13. package/lib/rules/block-scoped-var.js +2 -2
  14. package/lib/rules/block-spacing.js +2 -2
  15. package/lib/rules/brace-style.js +2 -2
  16. package/lib/rules/callback-return.js +2 -2
  17. package/lib/rules/camelcase.js +2 -2
  18. package/lib/rules/capitalized-comments.js +2 -2
  19. package/lib/rules/class-methods-use-this.js +2 -2
  20. package/lib/rules/comma-dangle.js +2 -2
  21. package/lib/rules/comma-spacing.js +2 -2
  22. package/lib/rules/comma-style.js +2 -2
  23. package/lib/rules/complexity.js +1 -1
  24. package/lib/rules/computed-property-spacing.js +2 -2
  25. package/lib/rules/consistent-return.js +3 -3
  26. package/lib/rules/consistent-this.js +2 -2
  27. package/lib/rules/constructor-super.js +1 -1
  28. package/lib/rules/curly.js +2 -2
  29. package/lib/rules/default-case-last.js +1 -1
  30. package/lib/rules/default-case.js +2 -2
  31. package/lib/rules/default-param-last.js +1 -1
  32. package/lib/rules/dot-location.js +2 -2
  33. package/lib/rules/dot-notation.js +2 -2
  34. package/lib/rules/eol-last.js +2 -2
  35. package/lib/rules/eqeqeq.js +2 -2
  36. package/lib/rules/for-direction.js +1 -1
  37. package/lib/rules/func-call-spacing.js +2 -2
  38. package/lib/rules/func-name-matching.js +1 -1
  39. package/lib/rules/func-names.js +2 -2
  40. package/lib/rules/func-style.js +1 -1
  41. package/lib/rules/function-call-argument-newline.js +2 -2
  42. package/lib/rules/function-paren-newline.js +2 -2
  43. package/lib/rules/generator-star-spacing.js +2 -2
  44. package/lib/rules/getter-return.js +2 -2
  45. package/lib/rules/global-require.js +2 -2
  46. package/lib/rules/grouped-accessor-pairs.js +2 -2
  47. package/lib/rules/guard-for-in.js +1 -1
  48. package/lib/rules/handle-callback-err.js +2 -2
  49. package/lib/rules/id-blacklist.js +2 -2
  50. package/lib/rules/id-denylist.js +2 -2
  51. package/lib/rules/id-length.js +3 -36
  52. package/lib/rules/id-match.js +2 -2
  53. package/lib/rules/implicit-arrow-linebreak.js +2 -2
  54. package/lib/rules/indent-legacy.js +2 -2
  55. package/lib/rules/indent.js +2 -2
  56. package/lib/rules/init-declarations.js +1 -1
  57. package/lib/rules/jsx-quotes.js +1 -1
  58. package/lib/rules/key-spacing.js +4 -10
  59. package/lib/rules/keyword-spacing.js +2 -2
  60. package/lib/rules/line-comment-position.js +2 -2
  61. package/lib/rules/linebreak-style.js +2 -2
  62. package/lib/rules/lines-around-comment.js +2 -2
  63. package/lib/rules/lines-around-directive.js +2 -2
  64. package/lib/rules/lines-between-class-members.js +2 -2
  65. package/lib/rules/logical-assignment-operators.js +2 -2
  66. package/lib/rules/max-classes-per-file.js +1 -1
  67. package/lib/rules/max-depth.js +1 -1
  68. package/lib/rules/max-len.js +2 -2
  69. package/lib/rules/max-lines-per-function.js +2 -2
  70. package/lib/rules/max-lines.js +2 -2
  71. package/lib/rules/max-nested-callbacks.js +1 -1
  72. package/lib/rules/max-params.js +2 -2
  73. package/lib/rules/max-statements-per-line.js +2 -2
  74. package/lib/rules/max-statements.js +1 -1
  75. package/lib/rules/multiline-comment-style.js +2 -2
  76. package/lib/rules/multiline-ternary.js +2 -2
  77. package/lib/rules/new-cap.js +2 -2
  78. package/lib/rules/new-parens.js +2 -2
  79. package/lib/rules/newline-after-var.js +2 -2
  80. package/lib/rules/newline-before-return.js +2 -2
  81. package/lib/rules/newline-per-chained-call.js +2 -2
  82. package/lib/rules/no-alert.js +2 -2
  83. package/lib/rules/no-array-constructor.js +1 -1
  84. package/lib/rules/no-async-promise-executor.js +2 -2
  85. package/lib/rules/no-await-in-loop.js +1 -1
  86. package/lib/rules/no-bitwise.js +1 -1
  87. package/lib/rules/no-buffer-constructor.js +1 -1
  88. package/lib/rules/no-caller.js +1 -1
  89. package/lib/rules/no-case-declarations.js +1 -1
  90. package/lib/rules/no-catch-shadow.js +2 -2
  91. package/lib/rules/no-class-assign.js +2 -2
  92. package/lib/rules/no-compare-neg-zero.js +1 -1
  93. package/lib/rules/no-cond-assign.js +2 -2
  94. package/lib/rules/no-confusing-arrow.js +2 -2
  95. package/lib/rules/no-console.js +2 -2
  96. package/lib/rules/no-const-assign.js +2 -2
  97. package/lib/rules/no-constant-binary-expression.js +2 -2
  98. package/lib/rules/no-constant-condition.js +2 -2
  99. package/lib/rules/no-constructor-return.js +1 -1
  100. package/lib/rules/no-continue.js +1 -1
  101. package/lib/rules/no-control-regex.js +1 -1
  102. package/lib/rules/no-debugger.js +1 -1
  103. package/lib/rules/no-delete-var.js +1 -1
  104. package/lib/rules/no-div-regex.js +2 -2
  105. package/lib/rules/no-dupe-args.js +2 -2
  106. package/lib/rules/no-dupe-class-members.js +1 -1
  107. package/lib/rules/no-dupe-else-if.js +2 -2
  108. package/lib/rules/no-dupe-keys.js +1 -1
  109. package/lib/rules/no-duplicate-case.js +2 -2
  110. package/lib/rules/no-duplicate-imports.js +1 -1
  111. package/lib/rules/no-else-return.js +2 -2
  112. package/lib/rules/no-empty-character-class.js +1 -1
  113. package/lib/rules/no-empty-function.js +2 -2
  114. package/lib/rules/no-empty-pattern.js +1 -1
  115. package/lib/rules/no-empty-static-block.js +2 -2
  116. package/lib/rules/no-empty.js +2 -2
  117. package/lib/rules/no-eq-null.js +1 -1
  118. package/lib/rules/no-eval.js +2 -2
  119. package/lib/rules/no-ex-assign.js +2 -2
  120. package/lib/rules/no-extend-native.js +2 -2
  121. package/lib/rules/no-extra-bind.js +2 -2
  122. package/lib/rules/no-extra-boolean-cast.js +2 -2
  123. package/lib/rules/no-extra-label.js +2 -2
  124. package/lib/rules/no-extra-parens.js +2 -2
  125. package/lib/rules/no-extra-semi.js +3 -3
  126. package/lib/rules/no-fallthrough.js +3 -3
  127. package/lib/rules/no-floating-decimal.js +2 -2
  128. package/lib/rules/no-func-assign.js +2 -2
  129. package/lib/rules/no-global-assign.js +2 -2
  130. package/lib/rules/no-implicit-coercion.js +2 -2
  131. package/lib/rules/no-implicit-globals.js +2 -2
  132. package/lib/rules/no-implied-eval.js +2 -2
  133. package/lib/rules/no-import-assign.js +2 -2
  134. package/lib/rules/no-inline-comments.js +2 -2
  135. package/lib/rules/no-inner-declarations.js +1 -1
  136. package/lib/rules/no-invalid-regexp.js +1 -1
  137. package/lib/rules/no-invalid-this.js +2 -2
  138. package/lib/rules/no-irregular-whitespace.js +2 -2
  139. package/lib/rules/no-iterator.js +1 -1
  140. package/lib/rules/no-label-var.js +2 -2
  141. package/lib/rules/no-labels.js +1 -1
  142. package/lib/rules/no-lone-blocks.js +3 -3
  143. package/lib/rules/no-lonely-if.js +4 -5
  144. package/lib/rules/no-loop-func.js +2 -2
  145. package/lib/rules/no-loss-of-precision.js +1 -1
  146. package/lib/rules/no-magic-numbers.js +1 -1
  147. package/lib/rules/no-misleading-character-class.js +2 -2
  148. package/lib/rules/no-mixed-operators.js +2 -2
  149. package/lib/rules/no-mixed-requires.js +1 -1
  150. package/lib/rules/no-mixed-spaces-and-tabs.js +2 -2
  151. package/lib/rules/no-multi-assign.js +1 -1
  152. package/lib/rules/no-multi-spaces.js +2 -2
  153. package/lib/rules/no-multi-str.js +1 -1
  154. package/lib/rules/no-multiple-empty-lines.js +2 -2
  155. package/lib/rules/no-native-reassign.js +2 -2
  156. package/lib/rules/no-negated-condition.js +1 -1
  157. package/lib/rules/no-negated-in-lhs.js +1 -1
  158. package/lib/rules/no-nested-ternary.js +1 -1
  159. package/lib/rules/no-new-func.js +2 -2
  160. package/lib/rules/no-new-native-nonconstructor.js +2 -2
  161. package/lib/rules/no-new-object.js +2 -2
  162. package/lib/rules/no-new-require.js +1 -1
  163. package/lib/rules/no-new-symbol.js +2 -2
  164. package/lib/rules/no-new-wrappers.js +1 -1
  165. package/lib/rules/no-new.js +1 -1
  166. package/lib/rules/no-nonoctal-decimal-escape.js +2 -2
  167. package/lib/rules/no-obj-calls.js +2 -2
  168. package/lib/rules/no-octal-escape.js +1 -1
  169. package/lib/rules/no-octal.js +1 -1
  170. package/lib/rules/no-param-reassign.js +2 -2
  171. package/lib/rules/no-path-concat.js +1 -1
  172. package/lib/rules/no-plusplus.js +1 -1
  173. package/lib/rules/no-process-env.js +1 -1
  174. package/lib/rules/no-process-exit.js +1 -1
  175. package/lib/rules/no-promise-executor-return.js +2 -2
  176. package/lib/rules/no-proto.js +1 -1
  177. package/lib/rules/no-prototype-builtins.js +1 -1
  178. package/lib/rules/no-redeclare.js +2 -2
  179. package/lib/rules/no-regex-spaces.js +2 -2
  180. package/lib/rules/no-restricted-exports.js +2 -2
  181. package/lib/rules/no-restricted-globals.js +2 -2
  182. package/lib/rules/no-restricted-imports.js +2 -2
  183. package/lib/rules/no-restricted-modules.js +1 -1
  184. package/lib/rules/no-restricted-properties.js +1 -1
  185. package/lib/rules/no-restricted-syntax.js +1 -1
  186. package/lib/rules/no-return-assign.js +2 -2
  187. package/lib/rules/no-return-await.js +3 -3
  188. package/lib/rules/no-script-url.js +1 -1
  189. package/lib/rules/no-self-assign.js +2 -2
  190. package/lib/rules/no-self-compare.js +2 -2
  191. package/lib/rules/no-sequences.js +2 -2
  192. package/lib/rules/no-setter-return.js +2 -2
  193. package/lib/rules/no-shadow-restricted-names.js +2 -2
  194. package/lib/rules/no-shadow.js +2 -2
  195. package/lib/rules/no-spaced-func.js +2 -2
  196. package/lib/rules/no-sparse-arrays.js +1 -1
  197. package/lib/rules/no-sync.js +1 -1
  198. package/lib/rules/no-tabs.js +2 -2
  199. package/lib/rules/no-template-curly-in-string.js +1 -1
  200. package/lib/rules/no-ternary.js +1 -1
  201. package/lib/rules/no-this-before-super.js +1 -1
  202. package/lib/rules/no-throw-literal.js +1 -1
  203. package/lib/rules/no-trailing-spaces.js +2 -2
  204. package/lib/rules/no-undef-init.js +2 -2
  205. package/lib/rules/no-undef.js +2 -2
  206. package/lib/rules/no-undefined.js +2 -2
  207. package/lib/rules/no-underscore-dangle.js +2 -2
  208. package/lib/rules/no-unexpected-multiline.js +2 -2
  209. package/lib/rules/no-unmodified-loop-condition.js +2 -2
  210. package/lib/rules/no-unneeded-ternary.js +2 -2
  211. package/lib/rules/no-unreachable-loop.js +1 -1
  212. package/lib/rules/no-unreachable.js +2 -2
  213. package/lib/rules/no-unsafe-finally.js +1 -1
  214. package/lib/rules/no-unsafe-negation.js +2 -2
  215. package/lib/rules/no-unsafe-optional-chaining.js +1 -1
  216. package/lib/rules/no-unused-expressions.js +6 -8
  217. package/lib/rules/no-unused-labels.js +2 -2
  218. package/lib/rules/no-unused-private-class-members.js +1 -1
  219. package/lib/rules/no-unused-vars.js +2 -2
  220. package/lib/rules/no-use-before-define.js +2 -2
  221. package/lib/rules/no-useless-backreference.js +2 -2
  222. package/lib/rules/no-useless-call.js +2 -2
  223. package/lib/rules/no-useless-catch.js +1 -1
  224. package/lib/rules/no-useless-computed-key.js +2 -2
  225. package/lib/rules/no-useless-concat.js +2 -2
  226. package/lib/rules/no-useless-constructor.js +1 -1
  227. package/lib/rules/no-useless-escape.js +2 -2
  228. package/lib/rules/no-useless-rename.js +2 -2
  229. package/lib/rules/no-useless-return.js +2 -2
  230. package/lib/rules/no-var.js +2 -2
  231. package/lib/rules/no-void.js +1 -1
  232. package/lib/rules/no-warning-comments.js +2 -2
  233. package/lib/rules/no-whitespace-before-property.js +2 -2
  234. package/lib/rules/no-with.js +1 -1
  235. package/lib/rules/nonblock-statement-body-position.js +2 -2
  236. package/lib/rules/object-curly-newline.js +2 -2
  237. package/lib/rules/object-curly-spacing.js +4 -4
  238. package/lib/rules/object-property-newline.js +2 -2
  239. package/lib/rules/object-shorthand.js +2 -2
  240. package/lib/rules/one-var-declaration-per-line.js +1 -1
  241. package/lib/rules/one-var.js +2 -2
  242. package/lib/rules/operator-assignment.js +2 -2
  243. package/lib/rules/operator-linebreak.js +2 -2
  244. package/lib/rules/padded-blocks.js +2 -2
  245. package/lib/rules/padding-line-between-statements.js +4 -4
  246. package/lib/rules/prefer-arrow-callback.js +2 -2
  247. package/lib/rules/prefer-const.js +2 -2
  248. package/lib/rules/prefer-destructuring.js +2 -2
  249. package/lib/rules/prefer-exponentiation-operator.js +2 -2
  250. package/lib/rules/prefer-named-capture-group.js +2 -2
  251. package/lib/rules/prefer-numeric-literals.js +2 -2
  252. package/lib/rules/prefer-object-has-own.js +2 -2
  253. package/lib/rules/prefer-object-spread.js +2 -3
  254. package/lib/rules/prefer-promise-reject-errors.js +2 -2
  255. package/lib/rules/prefer-reflect.js +1 -1
  256. package/lib/rules/prefer-regex-literals.js +2 -2
  257. package/lib/rules/prefer-rest-params.js +2 -2
  258. package/lib/rules/prefer-spread.js +2 -2
  259. package/lib/rules/prefer-template.js +2 -2
  260. package/lib/rules/quote-props.js +2 -2
  261. package/lib/rules/quotes.js +2 -2
  262. package/lib/rules/radix.js +2 -2
  263. package/lib/rules/require-atomic-updates.js +2 -2
  264. package/lib/rules/require-await.js +2 -2
  265. package/lib/rules/require-jsdoc.js +2 -2
  266. package/lib/rules/require-unicode-regexp.js +2 -2
  267. package/lib/rules/require-yield.js +1 -1
  268. package/lib/rules/rest-spread-spacing.js +2 -2
  269. package/lib/rules/semi-spacing.js +2 -2
  270. package/lib/rules/semi-style.js +2 -2
  271. package/lib/rules/semi.js +30 -5
  272. package/lib/rules/sort-imports.js +2 -2
  273. package/lib/rules/sort-keys.js +2 -2
  274. package/lib/rules/sort-vars.js +2 -2
  275. package/lib/rules/space-before-blocks.js +2 -2
  276. package/lib/rules/space-before-function-paren.js +2 -2
  277. package/lib/rules/space-in-parens.js +2 -2
  278. package/lib/rules/space-infix-ops.js +2 -2
  279. package/lib/rules/space-unary-ops.js +2 -2
  280. package/lib/rules/spaced-comment.js +2 -2
  281. package/lib/rules/strict.js +1 -1
  282. package/lib/rules/switch-colon-spacing.js +2 -2
  283. package/lib/rules/symbol-description.js +2 -2
  284. package/lib/rules/template-curly-spacing.js +2 -2
  285. package/lib/rules/template-tag-spacing.js +2 -2
  286. package/lib/rules/unicode-bom.js +2 -2
  287. package/lib/rules/use-isnan.js +1 -1
  288. package/lib/rules/valid-jsdoc.js +2 -2
  289. package/lib/rules/valid-typeof.js +3 -3
  290. package/lib/rules/vars-on-top.js +1 -1
  291. package/lib/rules/wrap-iife.js +2 -2
  292. package/lib/rules/wrap-regex.js +4 -5
  293. package/lib/rules/yield-star-spacing.js +2 -2
  294. package/lib/rules/yoda.js +3 -3
  295. package/lib/shared/string-utils.js +39 -1
  296. package/lib/source-code/source-code.js +47 -4
  297. package/lib/source-code/token-store/utils.js +21 -16
  298. package/messages/invalid-rule-options.js +17 -0
  299. package/messages/invalid-rule-severity.js +13 -0
  300. package/messages/shared.js +18 -0
  301. package/package.json +6 -6
@@ -17,7 +17,7 @@ module.exports = {
17
17
  docs: {
18
18
  description: "Require or disallow spacing between template tags and their literals",
19
19
  recommended: false,
20
- url: "https://eslint.org/docs/rules/template-tag-spacing"
20
+ url: "https://eslint.org/docs/latest/rules/template-tag-spacing"
21
21
  },
22
22
 
23
23
  fixable: "whitespace",
@@ -33,7 +33,7 @@ module.exports = {
33
33
 
34
34
  create(context) {
35
35
  const never = context.options[0] !== "always";
36
- const sourceCode = context.getSourceCode();
36
+ const sourceCode = context.sourceCode;
37
37
 
38
38
  /**
39
39
  * Check if a space is present between a template tag and its literal
@@ -16,7 +16,7 @@ module.exports = {
16
16
  docs: {
17
17
  description: "Require or disallow Unicode byte order mark (BOM)",
18
18
  recommended: false,
19
- url: "https://eslint.org/docs/rules/unicode-bom"
19
+ url: "https://eslint.org/docs/latest/rules/unicode-bom"
20
20
  },
21
21
 
22
22
  fixable: "whitespace",
@@ -42,7 +42,7 @@ module.exports = {
42
42
 
43
43
  Program: function checkUnicodeBOM(node) {
44
44
 
45
- const sourceCode = context.getSourceCode(),
45
+ const sourceCode = context.sourceCode,
46
46
  location = { column: 0, line: 1 },
47
47
  requireBOM = context.options[0] || "never";
48
48
 
@@ -39,7 +39,7 @@ module.exports = {
39
39
  docs: {
40
40
  description: "Require calls to `isNaN()` when checking for `NaN`",
41
41
  recommended: true,
42
- url: "https://eslint.org/docs/rules/use-isnan"
42
+ url: "https://eslint.org/docs/latest/rules/use-isnan"
43
43
  },
44
44
 
45
45
  schema: [
@@ -23,7 +23,7 @@ module.exports = {
23
23
  docs: {
24
24
  description: "Enforce valid JSDoc comments",
25
25
  recommended: false,
26
- url: "https://eslint.org/docs/rules/valid-jsdoc"
26
+ url: "https://eslint.org/docs/latest/rules/valid-jsdoc"
27
27
  },
28
28
 
29
29
  schema: [
@@ -96,7 +96,7 @@ module.exports = {
96
96
 
97
97
  const options = context.options[0] || {},
98
98
  prefer = options.prefer || {},
99
- sourceCode = context.getSourceCode(),
99
+ sourceCode = context.sourceCode,
100
100
 
101
101
  // these both default to true, so you have to explicitly make them false
102
102
  requireReturn = options.requireReturn !== false,
@@ -16,7 +16,7 @@ module.exports = {
16
16
  docs: {
17
17
  description: "Enforce comparing `typeof` expressions against valid strings",
18
18
  recommended: true,
19
- url: "https://eslint.org/docs/rules/valid-typeof"
19
+ url: "https://eslint.org/docs/latest/rules/valid-typeof"
20
20
  },
21
21
 
22
22
  hasSuggestions: true,
@@ -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
- const sourceCode = context.getSourceCode();
47
+ const sourceCode = context.sourceCode;
48
48
  const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals;
49
49
 
50
50
  let globalScope;
@@ -83,7 +83,7 @@ module.exports = {
83
83
 
84
84
  UnaryExpression(node) {
85
85
  if (isTypeofExpression(node)) {
86
- const parent = sourceCode.getAncestors(node).pop();
86
+ const { parent } = node;
87
87
 
88
88
  if (parent.type === "BinaryExpression" && OPERATORS.has(parent.operator)) {
89
89
  const sibling = parent.left === node ? parent.right : parent.left;
@@ -17,7 +17,7 @@ module.exports = {
17
17
  docs: {
18
18
  description: "Require `var` declarations be placed at the top of their containing scope",
19
19
  recommended: false,
20
- url: "https://eslint.org/docs/rules/vars-on-top"
20
+ url: "https://eslint.org/docs/latest/rules/vars-on-top"
21
21
  },
22
22
 
23
23
  schema: [],
@@ -45,7 +45,7 @@ module.exports = {
45
45
  docs: {
46
46
  description: "Require parentheses around immediate `function` invocations",
47
47
  recommended: false,
48
- url: "https://eslint.org/docs/rules/wrap-iife"
48
+ url: "https://eslint.org/docs/latest/rules/wrap-iife"
49
49
  },
50
50
 
51
51
  schema: [
@@ -77,7 +77,7 @@ module.exports = {
77
77
  const style = context.options[0] || "outside";
78
78
  const includeFunctionPrototypeMethods = context.options[1] && context.options[1].functionPrototypeMethods;
79
79
 
80
- const sourceCode = context.getSourceCode();
80
+ const sourceCode = context.sourceCode;
81
81
 
82
82
  /**
83
83
  * Check if the node is wrapped in any (). All parens count: grouping parens and parens for constructs such as if()
@@ -17,7 +17,7 @@ module.exports = {
17
17
  docs: {
18
18
  description: "Require parenthesis around regex literals",
19
19
  recommended: false,
20
- url: "https://eslint.org/docs/rules/wrap-regex"
20
+ url: "https://eslint.org/docs/latest/rules/wrap-regex"
21
21
  },
22
22
 
23
23
  schema: [],
@@ -29,7 +29,7 @@ module.exports = {
29
29
  },
30
30
 
31
31
  create(context) {
32
- const sourceCode = context.getSourceCode();
32
+ const sourceCode = context.sourceCode;
33
33
 
34
34
  return {
35
35
 
@@ -40,10 +40,9 @@ module.exports = {
40
40
  if (nodeType === "RegularExpression") {
41
41
  const beforeToken = sourceCode.getTokenBefore(node);
42
42
  const afterToken = sourceCode.getTokenAfter(node);
43
- const ancestors = sourceCode.getAncestors(node);
44
- const grandparent = ancestors[ancestors.length - 1];
43
+ const { parent } = node;
45
44
 
46
- if (grandparent.type === "MemberExpression" && grandparent.object === node &&
45
+ if (parent.type === "MemberExpression" && parent.object === node &&
47
46
  !(beforeToken && beforeToken.value === "(" && afterToken && afterToken.value === ")")) {
48
47
  context.report({
49
48
  node,
@@ -17,7 +17,7 @@ module.exports = {
17
17
  docs: {
18
18
  description: "Require or disallow spacing around the `*` in `yield*` expressions",
19
19
  recommended: false,
20
- url: "https://eslint.org/docs/rules/yield-star-spacing"
20
+ url: "https://eslint.org/docs/latest/rules/yield-star-spacing"
21
21
  },
22
22
 
23
23
  fixable: "whitespace",
@@ -48,7 +48,7 @@ module.exports = {
48
48
  },
49
49
 
50
50
  create(context) {
51
- const sourceCode = context.getSourceCode();
51
+ const sourceCode = context.sourceCode;
52
52
 
53
53
  const mode = (function(option) {
54
54
  if (!option || typeof option === "string") {
package/lib/rules/yoda.js CHANGED
@@ -123,7 +123,7 @@ module.exports = {
123
123
  docs: {
124
124
  description: 'Require or disallow "Yoda" conditions',
125
125
  recommended: false,
126
- url: "https://eslint.org/docs/rules/yoda"
126
+ url: "https://eslint.org/docs/latest/rules/yoda"
127
127
  },
128
128
 
129
129
  schema: [
@@ -162,7 +162,7 @@ module.exports = {
162
162
  const onlyEquality =
163
163
  context.options[1] && context.options[1].onlyEquality;
164
164
 
165
- const sourceCode = context.getSourceCode();
165
+ const sourceCode = context.sourceCode;
166
166
 
167
167
  /**
168
168
  * Determines whether node represents a range test.
@@ -343,7 +343,7 @@ module.exports = {
343
343
  ) &&
344
344
  !(!isEqualityOperator(node.operator) && onlyEquality) &&
345
345
  isComparisonOperator(node.operator) &&
346
- !(exceptRange && isRangeTest(sourceCode.getAncestors(node).pop()))
346
+ !(exceptRange && isRangeTest(node.parent))
347
347
  ) {
348
348
  context.report({
349
349
  node,
@@ -5,6 +5,26 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ //------------------------------------------------------------------------------
9
+ // Requirements
10
+ //------------------------------------------------------------------------------
11
+
12
+ const GraphemeSplitter = require("grapheme-splitter");
13
+
14
+ //------------------------------------------------------------------------------
15
+ // Helpers
16
+ //------------------------------------------------------------------------------
17
+
18
+ // eslint-disable-next-line no-control-regex -- intentionally including control characters
19
+ const ASCII_REGEX = /^[\u0000-\u007f]*$/u;
20
+
21
+ /** @type {GraphemeSplitter | undefined} */
22
+ let splitter;
23
+
24
+ //------------------------------------------------------------------------------
25
+ // Public Interface
26
+ //------------------------------------------------------------------------------
27
+
8
28
  /**
9
29
  * Converts the first letter of a string to uppercase.
10
30
  * @param {string} string The string to operate on
@@ -17,6 +37,24 @@ function upperCaseFirst(string) {
17
37
  return string[0].toUpperCase() + string.slice(1);
18
38
  }
19
39
 
40
+ /**
41
+ * Counts graphemes in a given string.
42
+ * @param {string} value A string to count graphemes.
43
+ * @returns {number} The number of graphemes in `value`.
44
+ */
45
+ function getGraphemeCount(value) {
46
+ if (ASCII_REGEX.test(value)) {
47
+ return value.length;
48
+ }
49
+
50
+ if (!splitter) {
51
+ splitter = new GraphemeSplitter();
52
+ }
53
+
54
+ return splitter.countGraphemes(value);
55
+ }
56
+
20
57
  module.exports = {
21
- upperCaseFirst
58
+ upperCaseFirst,
59
+ getGraphemeCount
22
60
  };
@@ -646,12 +646,12 @@ class SourceCode extends TokenStore {
646
646
  }
647
647
 
648
648
  /**
649
- * Gets all of the declared variables in the scope associated
650
- * with `node`. This is a convenience method that passes through
649
+ * Get the variables that `node` defines.
650
+ * This is a convenience method that passes through
651
651
  * to the same method on the `scopeManager`.
652
- * @param {ASTNode} node The node from which to retrieve the scope to check.
652
+ * @param {ASTNode} node The node for which the variables are obtained.
653
653
  * @returns {Array<Variable>} An array of variable nodes representing
654
- * the declared variables in the scope associated with `node`.
654
+ * the variables that `node` defines.
655
655
  */
656
656
  getDeclaredVariables(node) {
657
657
  return this.scopeManager.getDeclaredVariables(node);
@@ -681,6 +681,49 @@ class SourceCode extends TokenStore {
681
681
  }
682
682
  /* eslint-enable class-methods-use-this -- node is owned by SourceCode */
683
683
 
684
+ /**
685
+ * Marks a variable as used in the current scope
686
+ * @param {string} name The name of the variable to mark as used.
687
+ * @param {ASTNode} [refNode] The closest node to the variable reference.
688
+ * @returns {boolean} True if the variable was found and marked as used, false if not.
689
+ */
690
+ markVariableAsUsed(name, refNode = this.ast) {
691
+
692
+ const currentScope = this.getScope(refNode);
693
+ let initialScope = currentScope;
694
+
695
+ /*
696
+ * When we are in an ESM or CommonJS module, we need to start searching
697
+ * from the top-level scope, not the global scope. For ESM the top-level
698
+ * scope is the module scope; for CommonJS the top-level scope is the
699
+ * outer function scope.
700
+ *
701
+ * Without this check, we might miss a variable declared with `var` at
702
+ * the top-level because it won't exist in the global scope.
703
+ */
704
+ if (
705
+ currentScope.type === "global" &&
706
+ currentScope.childScopes.length > 0 &&
707
+
708
+ // top-level scopes refer to a `Program` node
709
+ currentScope.childScopes[0].block === this.ast
710
+ ) {
711
+ initialScope = currentScope.childScopes[0];
712
+ }
713
+
714
+ for (let scope = initialScope; scope; scope = scope.upper) {
715
+ const variable = scope.variables.find(scopeVar => scopeVar.name === name);
716
+
717
+ if (variable) {
718
+ variable.eslintUsed = true;
719
+ return true;
720
+ }
721
+ }
722
+
723
+ return false;
724
+ }
725
+
726
+
684
727
  }
685
728
 
686
729
  module.exports = SourceCode;
@@ -4,20 +4,6 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- //------------------------------------------------------------------------------
8
- // Helpers
9
- //------------------------------------------------------------------------------
10
-
11
- /**
12
- * Gets `token.range[0]` from the given token.
13
- * @param {Node|Token|Comment} token The token to get.
14
- * @returns {number} The start location.
15
- * @private
16
- */
17
- function getStartLocation(token) {
18
- return token.range[0];
19
- }
20
-
21
7
  //------------------------------------------------------------------------------
22
8
  // Exports
23
9
  //------------------------------------------------------------------------------
@@ -30,9 +16,28 @@ function getStartLocation(token) {
30
16
  * @returns {number} The found index or `tokens.length`.
31
17
  */
32
18
  exports.search = function search(tokens, location) {
33
- const index = tokens.findIndex(el => location <= getStartLocation(el));
19
+ for (let minIndex = 0, maxIndex = tokens.length - 1; minIndex <= maxIndex;) {
34
20
 
35
- return index === -1 ? tokens.length : index;
21
+ /*
22
+ * Calculate the index in the middle between minIndex and maxIndex.
23
+ * `| 0` is used to round a fractional value down to the nearest integer: this is similar to
24
+ * using `Math.trunc()` or `Math.floor()`, but performance tests have shown this method to
25
+ * be faster.
26
+ */
27
+ const index = (minIndex + maxIndex) / 2 | 0;
28
+ const token = tokens[index];
29
+ const tokenStartLocation = token.range[0];
30
+
31
+ if (location <= tokenStartLocation) {
32
+ if (index === minIndex) {
33
+ return index;
34
+ }
35
+ maxIndex = index;
36
+ } else {
37
+ minIndex = index + 1;
38
+ }
39
+ }
40
+ return tokens.length;
36
41
  };
37
42
 
38
43
  /**
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ const { stringifyValueForError } = require("./shared");
4
+
5
+ module.exports = function({ ruleId, value }) {
6
+ return `
7
+ Configuration for rule "${ruleId}" is invalid. Each rule must have a severity ("off", 0, "warn", 1, "error", or 2) and may be followed by additional options for the rule.
8
+
9
+ You passed '${stringifyValueForError(value, 4)}', which doesn't contain a valid severity.
10
+
11
+ If you're attempting to configure rule options, perhaps you meant:
12
+
13
+ "${ruleId}": ["error", ${stringifyValueForError(value, 8)}]
14
+
15
+ See https://eslint.org/docs/latest/use/configure/rules#using-configuration-files for configuring rules.
16
+ `.trimStart();
17
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ const { stringifyValueForError } = require("./shared");
4
+
5
+ module.exports = function({ ruleId, value }) {
6
+ return `
7
+ Configuration for rule "${ruleId}" is invalid. Expected severity of "off", 0, "warn", 1, "error", or 2.
8
+
9
+ You passed '${stringifyValueForError(value, 4)}'.
10
+
11
+ See https://eslint.org/docs/latest/use/configure/rules#using-configuration-files for configuring rules.
12
+ `.trimStart();
13
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview Shared utilities for error messages.
3
+ * @author Josh Goldberg
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /**
9
+ * Converts a value to a string that may be printed in errors.
10
+ * @param {any} value The invalid value.
11
+ * @param {number} indentation How many spaces to indent
12
+ * @returns {string} The value, stringified.
13
+ */
14
+ function stringifyValueForError(value, indentation) {
15
+ return value ? JSON.stringify(value, null, 4).replace(/\n/gu, `\n${" ".repeat(indentation)}`) : `${value}`;
16
+ }
17
+
18
+ module.exports = { stringifyValueForError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "8.38.0",
3
+ "version": "8.40.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -62,8 +62,8 @@
62
62
  "dependencies": {
63
63
  "@eslint-community/eslint-utils": "^4.2.0",
64
64
  "@eslint-community/regexpp": "^4.4.0",
65
- "@eslint/eslintrc": "^2.0.2",
66
- "@eslint/js": "8.38.0",
65
+ "@eslint/eslintrc": "^2.0.3",
66
+ "@eslint/js": "8.40.0",
67
67
  "@humanwhocodes/config-array": "^0.11.8",
68
68
  "@humanwhocodes/module-importer": "^1.0.1",
69
69
  "@nodelib/fs.walk": "^1.2.8",
@@ -73,9 +73,9 @@
73
73
  "debug": "^4.3.2",
74
74
  "doctrine": "^3.0.0",
75
75
  "escape-string-regexp": "^4.0.0",
76
- "eslint-scope": "^7.1.1",
77
- "eslint-visitor-keys": "^3.4.0",
78
- "espree": "^9.5.1",
76
+ "eslint-scope": "^7.2.0",
77
+ "eslint-visitor-keys": "^3.4.1",
78
+ "espree": "^9.5.2",
79
79
  "esquery": "^1.4.2",
80
80
  "esutils": "^2.0.2",
81
81
  "fast-deep-equal": "^3.1.3",