eslint 8.0.0-beta.0 → 8.0.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 (333) hide show
  1. package/README.md +4 -4
  2. package/bin/eslint.js +1 -1
  3. package/conf/eslint-recommended.js +1 -1
  4. package/conf/{category-list.json → rule-type-list.json} +4 -7
  5. package/lib/cli-engine/cli-engine.js +11 -3
  6. package/lib/cli-engine/file-enumerator.js +4 -3
  7. package/lib/cli-engine/formatters/html.js +1 -1
  8. package/lib/cli-engine/hash.js +2 -2
  9. package/lib/cli-engine/xml-escape.js +1 -1
  10. package/lib/config/flat-config-array.js +2 -2
  11. package/lib/config/flat-config-schema.js +1 -1
  12. package/lib/config/rule-validator.js +25 -8
  13. package/lib/eslint/eslint.js +4 -0
  14. package/lib/init/autoconfig.js +17 -18
  15. package/lib/init/config-file.js +3 -3
  16. package/lib/init/config-initializer.js +11 -10
  17. package/lib/init/config-rule.js +15 -16
  18. package/lib/init/npm-utils.js +16 -15
  19. package/lib/init/source-code-utils.js +6 -5
  20. package/lib/linter/apply-disable-directives.js +80 -11
  21. package/lib/linter/code-path-analysis/code-path-analyzer.js +115 -36
  22. package/lib/linter/code-path-analysis/code-path-segment.js +0 -1
  23. package/lib/linter/code-path-analysis/code-path-state.js +4 -1
  24. package/lib/linter/code-path-analysis/code-path.js +14 -5
  25. package/lib/linter/code-path-analysis/debug-helpers.js +2 -2
  26. package/lib/linter/code-path-analysis/fork-context.js +0 -1
  27. package/lib/linter/code-path-analysis/id-generator.js +0 -1
  28. package/lib/linter/config-comment-parser.js +1 -1
  29. package/lib/linter/linter.js +51 -22
  30. package/lib/linter/node-event-generator.js +0 -1
  31. package/lib/linter/report-translator.js +12 -12
  32. package/lib/linter/rules.js +3 -0
  33. package/lib/linter/safe-emitter.js +2 -2
  34. package/lib/linter/source-code-fixer.js +2 -2
  35. package/lib/linter/timing.js +2 -2
  36. package/lib/rule-tester/rule-tester.js +12 -2
  37. package/lib/rules/accessor-pairs.js +0 -1
  38. package/lib/rules/array-bracket-newline.js +0 -1
  39. package/lib/rules/array-bracket-spacing.js +0 -1
  40. package/lib/rules/array-callback-return.js +0 -1
  41. package/lib/rules/array-element-newline.js +0 -1
  42. package/lib/rules/arrow-body-style.js +0 -1
  43. package/lib/rules/arrow-parens.js +0 -1
  44. package/lib/rules/arrow-spacing.js +0 -1
  45. package/lib/rules/block-scoped-var.js +0 -1
  46. package/lib/rules/block-spacing.js +0 -1
  47. package/lib/rules/brace-style.js +0 -1
  48. package/lib/rules/callback-return.js +1 -1
  49. package/lib/rules/camelcase.js +17 -19
  50. package/lib/rules/capitalized-comments.js +0 -1
  51. package/lib/rules/class-methods-use-this.js +51 -9
  52. package/lib/rules/comma-dangle.js +0 -1
  53. package/lib/rules/comma-spacing.js +0 -1
  54. package/lib/rules/comma-style.js +0 -1
  55. package/lib/rules/complexity.js +47 -56
  56. package/lib/rules/computed-property-spacing.js +0 -1
  57. package/lib/rules/consistent-return.js +0 -1
  58. package/lib/rules/consistent-this.js +1 -2
  59. package/lib/rules/constructor-super.js +0 -1
  60. package/lib/rules/curly.js +0 -1
  61. package/lib/rules/default-case-last.js +0 -1
  62. package/lib/rules/default-case.js +2 -3
  63. package/lib/rules/default-param-last.js +1 -2
  64. package/lib/rules/dot-location.js +0 -1
  65. package/lib/rules/dot-notation.js +0 -1
  66. package/lib/rules/eol-last.js +6 -2
  67. package/lib/rules/eqeqeq.js +1 -2
  68. package/lib/rules/for-direction.js +0 -1
  69. package/lib/rules/func-call-spacing.js +0 -1
  70. package/lib/rules/func-name-matching.js +9 -6
  71. package/lib/rules/func-names.js +0 -1
  72. package/lib/rules/func-style.js +0 -1
  73. package/lib/rules/function-call-argument-newline.js +0 -1
  74. package/lib/rules/function-paren-newline.js +1 -1
  75. package/lib/rules/generator-star-spacing.js +0 -1
  76. package/lib/rules/getter-return.js +0 -1
  77. package/lib/rules/global-require.js +1 -1
  78. package/lib/rules/grouped-accessor-pairs.js +0 -1
  79. package/lib/rules/guard-for-in.js +0 -1
  80. package/lib/rules/handle-callback-err.js +1 -1
  81. package/lib/rules/id-blacklist.js +1 -1
  82. package/lib/rules/id-denylist.js +0 -1
  83. package/lib/rules/id-length.js +0 -1
  84. package/lib/rules/id-match.js +0 -1
  85. package/lib/rules/implicit-arrow-linebreak.js +0 -1
  86. package/lib/rules/indent-legacy.js +1 -1
  87. package/lib/rules/indent.js +7 -10
  88. package/lib/rules/index.js +1 -1
  89. package/lib/rules/init-declarations.js +0 -1
  90. package/lib/rules/jsx-quotes.js +0 -1
  91. package/lib/rules/key-spacing.js +4 -5
  92. package/lib/rules/keyword-spacing.js +19 -3
  93. package/lib/rules/line-comment-position.js +0 -1
  94. package/lib/rules/linebreak-style.js +0 -1
  95. package/lib/rules/lines-around-comment.js +0 -1
  96. package/lib/rules/lines-around-directive.js +1 -2
  97. package/lib/rules/lines-between-class-members.js +50 -3
  98. package/lib/rules/max-classes-per-file.js +31 -8
  99. package/lib/rules/max-depth.js +0 -1
  100. package/lib/rules/max-len.js +1 -2
  101. package/lib/rules/max-lines-per-function.js +1 -2
  102. package/lib/rules/max-lines.js +0 -1
  103. package/lib/rules/max-nested-callbacks.js +0 -1
  104. package/lib/rules/max-params.js +0 -1
  105. package/lib/rules/max-statements-per-line.js +0 -1
  106. package/lib/rules/max-statements.js +0 -1
  107. package/lib/rules/multiline-comment-style.js +0 -1
  108. package/lib/rules/multiline-ternary.js +0 -1
  109. package/lib/rules/new-cap.js +2 -2
  110. package/lib/rules/new-parens.js +0 -1
  111. package/lib/rules/newline-after-var.js +4 -5
  112. package/lib/rules/newline-before-return.js +2 -3
  113. package/lib/rules/newline-per-chained-call.js +1 -2
  114. package/lib/rules/no-alert.js +0 -1
  115. package/lib/rules/no-array-constructor.js +0 -1
  116. package/lib/rules/no-async-promise-executor.js +0 -1
  117. package/lib/rules/no-await-in-loop.js +0 -1
  118. package/lib/rules/no-bitwise.js +5 -6
  119. package/lib/rules/no-buffer-constructor.js +1 -1
  120. package/lib/rules/no-caller.js +0 -1
  121. package/lib/rules/no-case-declarations.js +0 -1
  122. package/lib/rules/no-catch-shadow.js +0 -1
  123. package/lib/rules/no-class-assign.js +0 -1
  124. package/lib/rules/no-compare-neg-zero.js +0 -1
  125. package/lib/rules/no-cond-assign.js +0 -1
  126. package/lib/rules/no-confusing-arrow.js +0 -1
  127. package/lib/rules/no-console.js +0 -1
  128. package/lib/rules/no-const-assign.js +0 -1
  129. package/lib/rules/no-constant-condition.js +0 -1
  130. package/lib/rules/no-constructor-return.js +0 -1
  131. package/lib/rules/no-continue.js +0 -1
  132. package/lib/rules/no-control-regex.js +0 -1
  133. package/lib/rules/no-debugger.js +0 -1
  134. package/lib/rules/no-delete-var.js +0 -1
  135. package/lib/rules/no-div-regex.js +0 -1
  136. package/lib/rules/no-dupe-args.js +0 -1
  137. package/lib/rules/no-dupe-class-members.js +0 -1
  138. package/lib/rules/no-dupe-else-if.js +0 -1
  139. package/lib/rules/no-dupe-keys.js +0 -2
  140. package/lib/rules/no-duplicate-case.js +0 -1
  141. package/lib/rules/no-duplicate-imports.js +0 -1
  142. package/lib/rules/no-else-return.js +0 -1
  143. package/lib/rules/no-empty-character-class.js +0 -1
  144. package/lib/rules/no-empty-function.js +0 -1
  145. package/lib/rules/no-empty-pattern.js +0 -1
  146. package/lib/rules/no-empty.js +0 -1
  147. package/lib/rules/no-eq-null.js +0 -1
  148. package/lib/rules/no-eval.js +0 -1
  149. package/lib/rules/no-ex-assign.js +0 -1
  150. package/lib/rules/no-extend-native.js +0 -1
  151. package/lib/rules/no-extra-bind.js +0 -1
  152. package/lib/rules/no-extra-boolean-cast.js +1 -1
  153. package/lib/rules/no-extra-label.js +0 -1
  154. package/lib/rules/no-extra-parens.js +0 -1
  155. package/lib/rules/no-extra-semi.js +0 -1
  156. package/lib/rules/no-fallthrough.js +0 -1
  157. package/lib/rules/no-floating-decimal.js +0 -1
  158. package/lib/rules/no-func-assign.js +0 -1
  159. package/lib/rules/no-global-assign.js +0 -1
  160. package/lib/rules/no-implicit-coercion.js +0 -1
  161. package/lib/rules/no-implicit-globals.js +0 -1
  162. package/lib/rules/no-implied-eval.js +0 -1
  163. package/lib/rules/no-import-assign.js +0 -1
  164. package/lib/rules/no-inline-comments.js +0 -1
  165. package/lib/rules/no-inner-declarations.js +0 -1
  166. package/lib/rules/no-invalid-regexp.js +0 -1
  167. package/lib/rules/no-invalid-this.js +0 -1
  168. package/lib/rules/no-irregular-whitespace.js +0 -1
  169. package/lib/rules/no-iterator.js +0 -1
  170. package/lib/rules/no-label-var.js +0 -1
  171. package/lib/rules/no-labels.js +0 -1
  172. package/lib/rules/no-lone-blocks.js +0 -1
  173. package/lib/rules/no-lonely-if.js +0 -1
  174. package/lib/rules/no-loop-func.js +1 -2
  175. package/lib/rules/no-loss-of-precision.js +0 -1
  176. package/lib/rules/no-magic-numbers.js +0 -1
  177. package/lib/rules/no-misleading-character-class.js +0 -1
  178. package/lib/rules/no-mixed-operators.js +1 -2
  179. package/lib/rules/no-mixed-requires.js +1 -1
  180. package/lib/rules/no-mixed-spaces-and-tabs.js +0 -1
  181. package/lib/rules/no-multi-assign.js +0 -1
  182. package/lib/rules/no-multi-spaces.js +0 -1
  183. package/lib/rules/no-multi-str.js +0 -1
  184. package/lib/rules/no-multiple-empty-lines.js +0 -1
  185. package/lib/rules/no-native-reassign.js +0 -1
  186. package/lib/rules/no-negated-condition.js +0 -1
  187. package/lib/rules/no-negated-in-lhs.js +0 -1
  188. package/lib/rules/no-nested-ternary.js +0 -1
  189. package/lib/rules/no-new-func.js +34 -7
  190. package/lib/rules/no-new-object.js +0 -1
  191. package/lib/rules/no-new-require.js +1 -1
  192. package/lib/rules/no-new-symbol.js +0 -1
  193. package/lib/rules/no-new-wrappers.js +0 -1
  194. package/lib/rules/no-new.js +0 -1
  195. package/lib/rules/no-nonoctal-decimal-escape.js +0 -1
  196. package/lib/rules/no-obj-calls.js +0 -1
  197. package/lib/rules/no-octal-escape.js +0 -1
  198. package/lib/rules/no-octal.js +0 -1
  199. package/lib/rules/no-param-reassign.js +0 -1
  200. package/lib/rules/no-path-concat.js +1 -1
  201. package/lib/rules/no-plusplus.js +0 -1
  202. package/lib/rules/no-process-env.js +1 -1
  203. package/lib/rules/no-process-exit.js +1 -1
  204. package/lib/rules/no-promise-executor-return.js +0 -1
  205. package/lib/rules/no-proto.js +0 -1
  206. package/lib/rules/no-prototype-builtins.js +0 -1
  207. package/lib/rules/no-redeclare.js +0 -1
  208. package/lib/rules/no-regex-spaces.js +0 -1
  209. package/lib/rules/no-restricted-exports.js +0 -1
  210. package/lib/rules/no-restricted-globals.js +1 -2
  211. package/lib/rules/no-restricted-imports.js +5 -6
  212. package/lib/rules/no-restricted-modules.js +3 -3
  213. package/lib/rules/no-restricted-properties.js +2 -3
  214. package/lib/rules/no-restricted-syntax.js +1 -2
  215. package/lib/rules/no-return-assign.js +0 -1
  216. package/lib/rules/no-return-await.js +0 -1
  217. package/lib/rules/no-script-url.js +1 -3
  218. package/lib/rules/no-self-assign.js +0 -1
  219. package/lib/rules/no-self-compare.js +0 -1
  220. package/lib/rules/no-sequences.js +0 -1
  221. package/lib/rules/no-setter-return.js +0 -1
  222. package/lib/rules/no-shadow-restricted-names.js +0 -1
  223. package/lib/rules/no-shadow.js +1 -2
  224. package/lib/rules/no-spaced-func.js +0 -1
  225. package/lib/rules/no-sparse-arrays.js +0 -1
  226. package/lib/rules/no-sync.js +1 -3
  227. package/lib/rules/no-tabs.js +0 -1
  228. package/lib/rules/no-template-curly-in-string.js +0 -1
  229. package/lib/rules/no-ternary.js +0 -1
  230. package/lib/rules/no-this-before-super.js +0 -1
  231. package/lib/rules/no-throw-literal.js +0 -1
  232. package/lib/rules/no-trailing-spaces.js +0 -1
  233. package/lib/rules/no-undef-init.js +9 -61
  234. package/lib/rules/no-undef.js +0 -1
  235. package/lib/rules/no-undefined.js +0 -1
  236. package/lib/rules/no-underscore-dangle.js +0 -1
  237. package/lib/rules/no-unexpected-multiline.js +0 -1
  238. package/lib/rules/no-unmodified-loop-condition.js +0 -1
  239. package/lib/rules/no-unneeded-ternary.js +0 -1
  240. package/lib/rules/no-unreachable-loop.js +0 -1
  241. package/lib/rules/no-unreachable.js +26 -25
  242. package/lib/rules/no-unsafe-finally.js +0 -1
  243. package/lib/rules/no-unsafe-negation.js +0 -1
  244. package/lib/rules/no-unsafe-optional-chaining.js +0 -1
  245. package/lib/rules/no-unused-expressions.js +4 -5
  246. package/lib/rules/no-unused-labels.js +0 -1
  247. package/lib/rules/no-unused-vars.js +26 -28
  248. package/lib/rules/no-use-before-define.js +0 -1
  249. package/lib/rules/no-useless-backreference.js +0 -1
  250. package/lib/rules/no-useless-call.js +0 -1
  251. package/lib/rules/no-useless-catch.js +0 -1
  252. package/lib/rules/no-useless-computed-key.js +1 -1
  253. package/lib/rules/no-useless-concat.js +0 -1
  254. package/lib/rules/no-useless-constructor.js +0 -1
  255. package/lib/rules/no-useless-escape.js +9 -9
  256. package/lib/rules/no-useless-rename.js +0 -1
  257. package/lib/rules/no-useless-return.js +0 -1
  258. package/lib/rules/no-var.js +0 -1
  259. package/lib/rules/no-void.js +0 -1
  260. package/lib/rules/no-warning-comments.js +0 -1
  261. package/lib/rules/no-whitespace-before-property.js +0 -1
  262. package/lib/rules/no-with.js +0 -1
  263. package/lib/rules/nonblock-statement-body-position.js +0 -1
  264. package/lib/rules/object-curly-newline.js +0 -1
  265. package/lib/rules/object-curly-spacing.js +0 -1
  266. package/lib/rules/object-property-newline.js +0 -1
  267. package/lib/rules/object-shorthand.js +3 -8
  268. package/lib/rules/one-var-declaration-per-line.js +0 -1
  269. package/lib/rules/one-var.js +1 -2
  270. package/lib/rules/operator-assignment.js +6 -7
  271. package/lib/rules/operator-linebreak.js +0 -1
  272. package/lib/rules/padded-blocks.js +1 -1
  273. package/lib/rules/padding-line-between-statements.js +0 -1
  274. package/lib/rules/prefer-arrow-callback.js +1 -1
  275. package/lib/rules/prefer-const.js +0 -1
  276. package/lib/rules/prefer-destructuring.js +1 -2
  277. package/lib/rules/prefer-exponentiation-operator.js +0 -1
  278. package/lib/rules/prefer-named-capture-group.js +0 -1
  279. package/lib/rules/prefer-numeric-literals.js +0 -1
  280. package/lib/rules/prefer-object-spread.js +0 -1
  281. package/lib/rules/prefer-promise-reject-errors.js +0 -1
  282. package/lib/rules/prefer-reflect.js +0 -1
  283. package/lib/rules/prefer-regex-literals.js +0 -1
  284. package/lib/rules/prefer-rest-params.js +0 -1
  285. package/lib/rules/prefer-spread.js +0 -1
  286. package/lib/rules/prefer-template.js +0 -1
  287. package/lib/rules/quote-props.js +8 -9
  288. package/lib/rules/quotes.js +0 -1
  289. package/lib/rules/radix.js +0 -1
  290. package/lib/rules/require-atomic-updates.js +24 -9
  291. package/lib/rules/require-await.js +0 -1
  292. package/lib/rules/require-jsdoc.js +1 -1
  293. package/lib/rules/require-unicode-regexp.js +0 -1
  294. package/lib/rules/require-yield.js +0 -1
  295. package/lib/rules/rest-spread-spacing.js +0 -1
  296. package/lib/rules/semi-spacing.js +0 -1
  297. package/lib/rules/semi-style.js +0 -1
  298. package/lib/rules/semi.js +66 -6
  299. package/lib/rules/sort-imports.js +0 -1
  300. package/lib/rules/sort-keys.js +0 -1
  301. package/lib/rules/sort-vars.js +0 -1
  302. package/lib/rules/space-before-blocks.js +14 -3
  303. package/lib/rules/space-before-function-paren.js +0 -1
  304. package/lib/rules/space-in-parens.js +0 -1
  305. package/lib/rules/space-infix-ops.js +0 -1
  306. package/lib/rules/space-unary-ops.js +0 -1
  307. package/lib/rules/spaced-comment.js +0 -1
  308. package/lib/rules/strict.js +0 -1
  309. package/lib/rules/switch-colon-spacing.js +1 -14
  310. package/lib/rules/symbol-description.js +0 -1
  311. package/lib/rules/template-curly-spacing.js +0 -1
  312. package/lib/rules/template-tag-spacing.js +0 -1
  313. package/lib/rules/unicode-bom.js +0 -1
  314. package/lib/rules/use-isnan.js +0 -1
  315. package/lib/rules/utils/ast-utils.js +29 -7
  316. package/lib/rules/utils/lazy-loading-rule-map.js +3 -3
  317. package/lib/rules/valid-jsdoc.js +1 -1
  318. package/lib/rules/valid-typeof.js +0 -1
  319. package/lib/rules/vars-on-top.js +1 -2
  320. package/lib/rules/wrap-iife.js +0 -1
  321. package/lib/rules/wrap-regex.js +0 -1
  322. package/lib/rules/yield-star-spacing.js +0 -1
  323. package/lib/rules/yoda.js +0 -1
  324. package/lib/shared/ajv.js +1 -1
  325. package/lib/shared/config-validator.js +10 -5
  326. package/lib/shared/logging.js +1 -1
  327. package/lib/shared/relative-module-resolver.js +1 -0
  328. package/lib/shared/runtime-info.js +3 -0
  329. package/lib/shared/traverser.js +2 -2
  330. package/lib/shared/types.js +2 -2
  331. package/lib/source-code/source-code.js +11 -5
  332. package/lib/source-code/token-store/cursor.js +1 -1
  333. package/package.json +5 -5
@@ -17,7 +17,6 @@ module.exports = {
17
17
 
18
18
  docs: {
19
19
  description: "disallow initializing variables to `undefined`",
20
- category: "Variables",
21
20
  recommended: false,
22
21
  url: "https://eslint.org/docs/rules/no-undef-init"
23
22
  },
@@ -34,88 +33,37 @@ module.exports = {
34
33
 
35
34
  const sourceCode = context.getSourceCode();
36
35
 
37
- /**
38
- * Get the node of init target.
39
- * @param {ASTNode} node The node to get.
40
- * @returns {ASTNode} The node of init target.
41
- */
42
- function getIdNode(node) {
43
- switch (node.type) {
44
- case "VariableDeclarator":
45
- return node.id;
46
- case "PropertyDefinition":
47
- return node.key;
48
- default:
49
- throw new Error("unreachable");
50
- }
51
- }
52
-
53
- /**
54
- * Get the node of init value.
55
- * @param {ASTNode} node The node to get.
56
- * @returns {ASTNode} The node of init value.
57
- */
58
- function getInitNode(node) {
59
- switch (node.type) {
60
- case "VariableDeclarator":
61
- return node.init;
62
- case "PropertyDefinition":
63
- return node.value;
64
- default:
65
- throw new Error("unreachable");
66
- }
67
- }
68
-
69
- /**
70
- * Get the parent kind of the node.
71
- * @param {ASTNode} node The node to get.
72
- * @returns {string} The parent kind.
73
- */
74
- function getParentKind(node) {
75
- switch (node.type) {
76
- case "VariableDeclarator":
77
- return node.parent.kind;
78
- case "PropertyDefinition":
79
- return "field";
80
- default:
81
- throw new Error("unreachable");
82
- }
83
- }
84
-
85
36
  return {
86
37
 
87
- "VariableDeclarator, PropertyDefinition"(node) {
88
- const idNode = getIdNode(node),
89
- name = sourceCode.getText(idNode),
90
- initNode = getInitNode(node),
91
- initIsUndefined = initNode && initNode.type === "Identifier" && initNode.name === "undefined",
92
- parentKind = getParentKind(node),
38
+ VariableDeclarator(node) {
39
+ const name = sourceCode.getText(node.id),
40
+ init = node.init && node.init.name,
93
41
  scope = context.getScope(),
94
42
  undefinedVar = astUtils.getVariableByName(scope, "undefined"),
95
43
  shadowed = undefinedVar && undefinedVar.defs.length > 0,
96
- lastToken = sourceCode.getLastToken(node, astUtils.isNotSemicolonToken);
44
+ lastToken = sourceCode.getLastToken(node);
97
45
 
98
- if (initIsUndefined && parentKind !== "const" && !shadowed) {
46
+ if (init === "undefined" && node.parent.kind !== "const" && !shadowed) {
99
47
  context.report({
100
48
  node,
101
49
  messageId: "unnecessaryUndefinedInit",
102
50
  data: { name },
103
51
  fix(fixer) {
104
- if (parentKind === "var") {
52
+ if (node.parent.kind === "var") {
105
53
  return null;
106
54
  }
107
55
 
108
- if (idNode.type === "ArrayPattern" || idNode.type === "ObjectPattern") {
56
+ if (node.id.type === "ArrayPattern" || node.id.type === "ObjectPattern") {
109
57
 
110
58
  // Don't fix destructuring assignment to `undefined`.
111
59
  return null;
112
60
  }
113
61
 
114
- if (sourceCode.commentsExistBetween(idNode, lastToken)) {
62
+ if (sourceCode.commentsExistBetween(node.id, lastToken)) {
115
63
  return null;
116
64
  }
117
65
 
118
- return fixer.removeRange([idNode.range[1], lastToken.range[1]]);
66
+ return fixer.removeRange([node.id.range[1], node.range[1]]);
119
67
  }
120
68
  });
121
69
  }
@@ -29,7 +29,6 @@ module.exports = {
29
29
 
30
30
  docs: {
31
31
  description: "disallow the use of undeclared variables unless mentioned in `/*global */` comments",
32
- category: "Variables",
33
32
  recommended: true,
34
33
  url: "https://eslint.org/docs/rules/no-undef"
35
34
  },
@@ -14,7 +14,6 @@ module.exports = {
14
14
 
15
15
  docs: {
16
16
  description: "disallow the use of `undefined` as an identifier",
17
- category: "Variables",
18
17
  recommended: false,
19
18
  url: "https://eslint.org/docs/rules/no-undefined"
20
19
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "disallow dangling underscores in identifiers",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/no-underscore-dangle"
21
20
  },
@@ -20,7 +20,6 @@ module.exports = {
20
20
 
21
21
  docs: {
22
22
  description: "disallow confusing multiline expressions",
23
- category: "Possible Errors",
24
23
  recommended: true,
25
24
  url: "https://eslint.org/docs/rules/no-unexpected-multiline"
26
25
  },
@@ -162,7 +162,6 @@ module.exports = {
162
162
 
163
163
  docs: {
164
164
  description: "disallow unmodified loop conditions",
165
- category: "Best Practices",
166
165
  recommended: false,
167
166
  url: "https://eslint.org/docs/rules/no-unmodified-loop-condition"
168
167
  },
@@ -29,7 +29,6 @@ module.exports = {
29
29
 
30
30
  docs: {
31
31
  description: "disallow ternary operators when simpler alternatives exist",
32
- category: "Stylistic Issues",
33
32
  recommended: false,
34
33
  url: "https://eslint.org/docs/rules/no-unneeded-ternary"
35
34
  },
@@ -59,7 +59,6 @@ module.exports = {
59
59
 
60
60
  docs: {
61
61
  description: "disallow loops with a body that allows only one iteration",
62
- category: "Possible Errors",
63
62
  recommended: false,
64
63
  url: "https://eslint.org/docs/rules/no-unreachable-loop"
65
64
  },
@@ -9,9 +9,8 @@
9
9
  //------------------------------------------------------------------------------
10
10
 
11
11
  /**
12
- * @typedef {Object} ClassInfo
13
- * @property {ClassInfo | null} upper The class info that encloses this class.
14
- * @property {boolean} hasConstructor The flag about having user-defined constructor.
12
+ * @typedef {Object} ConstructorInfo
13
+ * @property {ConstructorInfo | null} upper Info about the constructor that encloses this constructor.
15
14
  * @property {boolean} hasSuperCall The flag about having `super()` expressions.
16
15
  */
17
16
 
@@ -112,7 +111,6 @@ module.exports = {
112
111
 
113
112
  docs: {
114
113
  description: "disallow unreachable code after `return`, `throw`, `continue`, and `break` statements",
115
- category: "Possible Errors",
116
114
  recommended: true,
117
115
  url: "https://eslint.org/docs/rules/no-unreachable"
118
116
  },
@@ -127,8 +125,8 @@ module.exports = {
127
125
  create(context) {
128
126
  let currentCodePath = null;
129
127
 
130
- /** @type {ClassInfo | null} */
131
- let classInfo = null;
128
+ /** @type {ConstructorInfo | null} */
129
+ let constructorInfo = null;
132
130
 
133
131
  /** @type {ConsecutiveRange} */
134
132
  const range = new ConsecutiveRange(context.getSourceCode());
@@ -225,36 +223,39 @@ module.exports = {
225
223
  reportIfUnreachable();
226
224
  },
227
225
 
228
- // Address class fields.
229
- "ClassDeclaration, ClassExpression"() {
230
- classInfo = {
231
- upper: classInfo,
232
- hasConstructor: false,
226
+ /*
227
+ * Instance fields defined in a subclass are never created if the constructor of the subclass
228
+ * doesn't call `super()`, so their definitions are unreachable code.
229
+ */
230
+ "MethodDefinition[kind='constructor']"() {
231
+ constructorInfo = {
232
+ upper: constructorInfo,
233
233
  hasSuperCall: false
234
234
  };
235
235
  },
236
- "ClassDeclaration, ClassExpression:exit"(node) {
237
- const { hasConstructor, hasSuperCall } = classInfo;
238
- const hasExtends = Boolean(node.superClass);
236
+ "MethodDefinition[kind='constructor']:exit"(node) {
237
+ const { hasSuperCall } = constructorInfo;
238
+
239
+ constructorInfo = constructorInfo.upper;
240
+
241
+ // skip typescript constructors without the body
242
+ if (!node.value.body) {
243
+ return;
244
+ }
239
245
 
240
- classInfo = classInfo.upper;
246
+ const classDefinition = node.parent.parent;
241
247
 
242
- if (hasConstructor && hasExtends && !hasSuperCall) {
243
- for (const element of node.body.body) {
244
- if (element.type === "PropertyDefinition") {
248
+ if (classDefinition.superClass && !hasSuperCall) {
249
+ for (const element of classDefinition.body.body) {
250
+ if (element.type === "PropertyDefinition" && !element.static) {
245
251
  reportIfUnreachable(element);
246
252
  }
247
253
  }
248
254
  }
249
255
  },
250
- "MethodDefinition[kind='constructor']"() {
251
- if (classInfo) {
252
- classInfo.hasConstructor = true;
253
- }
254
- },
255
256
  "CallExpression > Super.callee"() {
256
- if (classInfo) {
257
- classInfo.hasSuperCall = true;
257
+ if (constructorInfo) {
258
+ constructorInfo.hasSuperCall = true;
258
259
  }
259
260
  }
260
261
  };
@@ -24,7 +24,6 @@ module.exports = {
24
24
 
25
25
  docs: {
26
26
  description: "disallow control flow statements in `finally` blocks",
27
- category: "Possible Errors",
28
27
  recommended: true,
29
28
  url: "https://eslint.org/docs/rules/no-unsafe-finally"
30
29
  },
@@ -52,7 +52,6 @@ module.exports = {
52
52
 
53
53
  docs: {
54
54
  description: "disallow negating the left operand of relational operators",
55
- category: "Possible Errors",
56
55
  recommended: true,
57
56
  url: "https://eslint.org/docs/rules/no-unsafe-negation"
58
57
  },
@@ -24,7 +24,6 @@ module.exports = {
24
24
 
25
25
  docs: {
26
26
  description: "disallow use of optional chaining in contexts where the `undefined` value is not allowed",
27
- category: "Possible Errors",
28
27
  recommended: true,
29
28
  url: "https://eslint.org/docs/rules/no-unsafe-optional-chaining"
30
29
  },
@@ -30,7 +30,6 @@ module.exports = {
30
30
 
31
31
  docs: {
32
32
  description: "disallow unused expressions",
33
- category: "Best Practices",
34
33
  recommended: false,
35
34
  url: "https://eslint.org/docs/rules/no-unused-expressions"
36
35
  },
@@ -72,8 +71,8 @@ module.exports = {
72
71
  allowTaggedTemplates = config.allowTaggedTemplates || false,
73
72
  enforceForJSX = config.enforceForJSX || false;
74
73
 
75
- // eslint-disable-next-line jsdoc/require-description
76
74
  /**
75
+ * Has AST suggesting a directive.
77
76
  * @param {ASTNode} node any node
78
77
  * @returns {boolean} whether the given node structurally represents a directive
79
78
  */
@@ -82,8 +81,8 @@ module.exports = {
82
81
  node.expression.type === "Literal" && typeof node.expression.value === "string";
83
82
  }
84
83
 
85
- // eslint-disable-next-line jsdoc/require-description
86
84
  /**
85
+ * Gets the leading sequence of members in a list that pass the predicate.
87
86
  * @param {Function} predicate ([a] -> Boolean) the function used to make the determination
88
87
  * @param {a[]} list the input list
89
88
  * @returns {a[]} the leading sequence of members in the given list that pass the given predicate
@@ -97,8 +96,8 @@ module.exports = {
97
96
  return list.slice();
98
97
  }
99
98
 
100
- // eslint-disable-next-line jsdoc/require-description
101
99
  /**
100
+ * Gets leading directives nodes in a Node body.
102
101
  * @param {ASTNode} node a Program or BlockStatement node
103
102
  * @returns {ASTNode[]} the leading sequence of directive nodes in the given node's body
104
103
  */
@@ -106,8 +105,8 @@ module.exports = {
106
105
  return takeWhile(looksLikeDirective, node.body);
107
106
  }
108
107
 
109
- // eslint-disable-next-line jsdoc/require-description
110
108
  /**
109
+ * Detect if a Node is a directive.
111
110
  * @param {ASTNode} node any node
112
111
  * @param {ASTNode[]} ancestors the given node's ancestors
113
112
  * @returns {boolean} whether the given node is considered a directive in its current position
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "disallow unused labels",
18
- category: "Best Practices",
19
18
  recommended: true,
20
19
  url: "https://eslint.org/docs/rules/no-unused-labels"
21
20
  },
@@ -33,7 +33,6 @@ module.exports = {
33
33
 
34
34
  docs: {
35
35
  description: "disallow unused variables",
36
- category: "Variables",
37
36
  recommended: true,
38
37
  url: "https://eslint.org/docs/rules/no-unused-vars"
39
38
  },
@@ -295,6 +294,31 @@ module.exports = {
295
294
  );
296
295
  }
297
296
 
297
+ /**
298
+ * Checks whether a given node is unused expression or not.
299
+ * @param {ASTNode} node The node itself
300
+ * @returns {boolean} The node is an unused expression.
301
+ * @private
302
+ */
303
+ function isUnusedExpression(node) {
304
+ const parent = node.parent;
305
+
306
+ if (parent.type === "ExpressionStatement") {
307
+ return true;
308
+ }
309
+
310
+ if (parent.type === "SequenceExpression") {
311
+ const isLastExpression = parent.expressions[parent.expressions.length - 1] === node;
312
+
313
+ if (!isLastExpression) {
314
+ return true;
315
+ }
316
+ return isUnusedExpression(parent);
317
+ }
318
+
319
+ return false;
320
+ }
321
+
298
322
  /**
299
323
  * If a given reference is left-hand side of an assignment, this gets
300
324
  * the right-hand side node of the assignment.
@@ -313,7 +337,6 @@ module.exports = {
313
337
  function getRhsNode(ref, prevRhsNode) {
314
338
  const id = ref.identifier;
315
339
  const parent = id.parent;
316
- const grandparent = parent.parent;
317
340
  const refScope = ref.from.variableScope;
318
341
  const varScope = ref.resolved.scope.variableScope;
319
342
  const canBeUsedLater = refScope !== varScope || astUtils.isInLoop(id);
@@ -327,7 +350,7 @@ module.exports = {
327
350
  }
328
351
 
329
352
  if (parent.type === "AssignmentExpression" &&
330
- grandparent.type === "ExpressionStatement" &&
353
+ isUnusedExpression(parent) &&
331
354
  id === parent.left &&
332
355
  !canBeUsedLater
333
356
  ) {
@@ -410,31 +433,6 @@ module.exports = {
410
433
  );
411
434
  }
412
435
 
413
- /**
414
- * Checks whether a given node is unused expression or not.
415
- * @param {ASTNode} node The node itself
416
- * @returns {boolean} The node is an unused expression.
417
- * @private
418
- */
419
- function isUnusedExpression(node) {
420
- const parent = node.parent;
421
-
422
- if (parent.type === "ExpressionStatement") {
423
- return true;
424
- }
425
-
426
- if (parent.type === "SequenceExpression") {
427
- const isLastExpression = parent.expressions[parent.expressions.length - 1] === node;
428
-
429
- if (!isLastExpression) {
430
- return true;
431
- }
432
- return isUnusedExpression(parent);
433
- }
434
-
435
- return false;
436
- }
437
-
438
436
  /**
439
437
  * Checks whether a given reference is a read to update itself or not.
440
438
  * @param {eslint-scope.Reference} ref A reference to check.
@@ -135,7 +135,6 @@ module.exports = {
135
135
 
136
136
  docs: {
137
137
  description: "disallow the use of variables before they are defined",
138
- category: "Variables",
139
138
  recommended: false,
140
139
  url: "https://eslint.org/docs/rules/no-use-before-define"
141
140
  },
@@ -64,7 +64,6 @@ module.exports = {
64
64
 
65
65
  docs: {
66
66
  description: "disallow useless backreferences in regular expressions",
67
- category: "Possible Errors",
68
67
  recommended: true,
69
68
  url: "https://eslint.org/docs/rules/no-useless-backreference"
70
69
  },
@@ -55,7 +55,6 @@ module.exports = {
55
55
 
56
56
  docs: {
57
57
  description: "disallow unnecessary calls to `.call()` and `.apply()`",
58
- category: "Best Practices",
59
58
  recommended: false,
60
59
  url: "https://eslint.org/docs/rules/no-useless-call"
61
60
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "disallow unnecessary `catch` clauses",
18
- category: "Best Practices",
19
18
  recommended: true,
20
19
  url: "https://eslint.org/docs/rules/no-useless-catch"
21
20
  },
@@ -36,6 +36,7 @@ const astUtils = require("./utils/ast-utils");
36
36
  * - class C { static ["prototype"]() {} } produces a runtime error (doesn't break the whole script)
37
37
  * class C { static "prototype"() {} } produces a parsing error (breaks the whole script)
38
38
  * @param {ASTNode} node The node to check. It can be `Property`, `PropertyDefinition` or `MethodDefinition`.
39
+ * @throws {Error} (Unreachable.)
39
40
  * @returns {void} `true` if the node has useless computed key.
40
41
  */
41
42
  function hasUselessComputedKey(node) {
@@ -90,7 +91,6 @@ module.exports = {
90
91
 
91
92
  docs: {
92
93
  description: "disallow unnecessary computed property keys in objects and classes",
93
- category: "ECMAScript 6",
94
94
  recommended: false,
95
95
  url: "https://eslint.org/docs/rules/no-useless-computed-key"
96
96
  },
@@ -70,7 +70,6 @@ module.exports = {
70
70
 
71
71
  docs: {
72
72
  description: "disallow unnecessary concatenation of literals or template literals",
73
- category: "Best Practices",
74
73
  recommended: false,
75
74
  url: "https://eslint.org/docs/rules/no-useless-concat"
76
75
  },
@@ -138,7 +138,6 @@ module.exports = {
138
138
 
139
139
  docs: {
140
140
  description: "disallow unnecessary constructors",
141
- category: "ECMAScript 6",
142
141
  recommended: false,
143
142
  url: "https://eslint.org/docs/rules/no-useless-constructor"
144
143
  },
@@ -34,16 +34,17 @@ const REGEX_NON_CHARCLASS_ESCAPES = union(REGEX_GENERAL_ESCAPES, new Set("^/.$*+
34
34
  * @returns {Object[]} A list of characters, each with info on escaping and whether they're in a character class.
35
35
  * @example
36
36
  *
37
- * parseRegExp('a\\b[cd-]')
37
+ * parseRegExp("a\\b[cd-]");
38
38
  *
39
- * returns:
39
+ * // returns:
40
40
  * [
41
- * {text: 'a', index: 0, escaped: false, inCharClass: false, startsCharClass: false, endsCharClass: false},
42
- * {text: 'b', index: 2, escaped: true, inCharClass: false, startsCharClass: false, endsCharClass: false},
43
- * {text: 'c', index: 4, escaped: false, inCharClass: true, startsCharClass: true, endsCharClass: false},
44
- * {text: 'd', index: 5, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false},
45
- * {text: '-', index: 6, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false}
46
- * ]
41
+ * { text: "a", index: 0, escaped: false, inCharClass: false, startsCharClass: false, endsCharClass: false },
42
+ * { text: "b", index: 2, escaped: true, inCharClass: false, startsCharClass: false, endsCharClass: false },
43
+ * { text: "c", index: 4, escaped: false, inCharClass: true, startsCharClass: true, endsCharClass: false },
44
+ * { text: "d", index: 5, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false },
45
+ * { text: "-", index: 6, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false }
46
+ * ];
47
+ *
47
48
  */
48
49
  function parseRegExp(regExpText) {
49
50
  const charList = [];
@@ -83,7 +84,6 @@ module.exports = {
83
84
 
84
85
  docs: {
85
86
  description: "disallow unnecessary escape characters",
86
- category: "Best Practices",
87
87
  recommended: true,
88
88
  url: "https://eslint.org/docs/rules/no-useless-escape"
89
89
  },
@@ -21,7 +21,6 @@ module.exports = {
21
21
 
22
22
  docs: {
23
23
  description: "disallow renaming import, export, and destructured assignments to the same name",
24
- category: "ECMAScript 6",
25
24
  recommended: false,
26
25
  url: "https://eslint.org/docs/rules/no-useless-rename"
27
26
  },
@@ -67,7 +67,6 @@ module.exports = {
67
67
 
68
68
  docs: {
69
69
  description: "disallow redundant return statements",
70
- category: "Best Practices",
71
70
  recommended: false,
72
71
  url: "https://eslint.org/docs/rules/no-useless-return"
73
72
  },
@@ -185,7 +185,6 @@ module.exports = {
185
185
 
186
186
  docs: {
187
187
  description: "require `let` or `const` instead of `var`",
188
- category: "ECMAScript 6",
189
188
  recommended: false,
190
189
  url: "https://eslint.org/docs/rules/no-var"
191
190
  },
@@ -14,7 +14,6 @@ module.exports = {
14
14
 
15
15
  docs: {
16
16
  description: "disallow `void` operators",
17
- category: "Best Practices",
18
17
  recommended: false,
19
18
  url: "https://eslint.org/docs/rules/no-void"
20
19
  },
@@ -20,7 +20,6 @@ module.exports = {
20
20
 
21
21
  docs: {
22
22
  description: "disallow specified warning terms in comments",
23
- category: "Best Practices",
24
23
  recommended: false,
25
24
  url: "https://eslint.org/docs/rules/no-warning-comments"
26
25
  },
@@ -20,7 +20,6 @@ module.exports = {
20
20
 
21
21
  docs: {
22
22
  description: "disallow whitespace before properties",
23
- category: "Stylistic Issues",
24
23
  recommended: false,
25
24
  url: "https://eslint.org/docs/rules/no-whitespace-before-property"
26
25
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "disallow `with` statements",
18
- category: "Best Practices",
19
18
  recommended: true,
20
19
  url: "https://eslint.org/docs/rules/no-with"
21
20
  },
@@ -16,7 +16,6 @@ module.exports = {
16
16
 
17
17
  docs: {
18
18
  description: "enforce the location of single-line statements",
19
- category: "Stylistic Issues",
20
19
  recommended: false,
21
20
  url: "https://eslint.org/docs/rules/nonblock-statement-body-position"
22
21
  },
@@ -150,7 +150,6 @@ module.exports = {
150
150
 
151
151
  docs: {
152
152
  description: "enforce consistent line breaks after opening and before closing braces",
153
- category: "Stylistic Issues",
154
153
  recommended: false,
155
154
  url: "https://eslint.org/docs/rules/object-curly-newline"
156
155
  },
@@ -16,7 +16,6 @@ module.exports = {
16
16
 
17
17
  docs: {
18
18
  description: "enforce consistent spacing inside braces",
19
- category: "Stylistic Issues",
20
19
  recommended: false,
21
20
  url: "https://eslint.org/docs/rules/object-curly-spacing"
22
21
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "enforce placing object properties on separate lines",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/object-property-newline"
21
20
  },