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
@@ -16,7 +16,6 @@ module.exports = {
16
16
 
17
17
  docs: {
18
18
  description: "enforce consistent spacing before and after commas",
19
- category: "Stylistic Issues",
20
19
  recommended: false,
21
20
  url: "https://eslint.org/docs/rules/comma-spacing"
22
21
  },
@@ -17,7 +17,6 @@ module.exports = {
17
17
 
18
18
  docs: {
19
19
  description: "enforce consistent comma style",
20
- category: "Stylistic Issues",
21
20
  recommended: false,
22
21
  url: "https://eslint.org/docs/rules/comma-style"
23
22
  },
@@ -23,7 +23,6 @@ module.exports = {
23
23
 
24
24
  docs: {
25
25
  description: "enforce a maximum cyclomatic complexity allowed in a program",
26
- category: "Best Practices",
27
26
  recommended: false,
28
27
  url: "https://eslint.org/docs/rules/complexity"
29
28
  },
@@ -75,60 +74,16 @@ module.exports = {
75
74
  // Helpers
76
75
  //--------------------------------------------------------------------------
77
76
 
78
- // Using a stack to store complexity (handling nested functions)
79
- const fns = [];
77
+ // Using a stack to store complexity per code path
78
+ const complexities = [];
80
79
 
81
80
  /**
82
- * When parsing a new function, store it in our function stack
83
- * @returns {void}
84
- * @private
85
- */
86
- function startFunction() {
87
- fns.push(1);
88
- }
89
-
90
- /**
91
- * Evaluate the node at the end of function
92
- * @param {ASTNode} node node to evaluate
93
- * @returns {void}
94
- * @private
95
- */
96
- function endFunction(node) {
97
- const name = upperCaseFirst(astUtils.getFunctionNameWithKind(node));
98
- const complexity = fns.pop();
99
-
100
- if (complexity > THRESHOLD) {
101
- context.report({
102
- node,
103
- messageId: "complex",
104
- data: { name, complexity, max: THRESHOLD }
105
- });
106
- }
107
- }
108
-
109
- /**
110
- * Increase the complexity of the function in context
81
+ * Increase the complexity of the code path in context
111
82
  * @returns {void}
112
83
  * @private
113
84
  */
114
85
  function increaseComplexity() {
115
- if (fns.length) {
116
- fns[fns.length - 1]++;
117
- }
118
- }
119
-
120
- /**
121
- * Increase the switch complexity in context
122
- * @param {ASTNode} node node to evaluate
123
- * @returns {void}
124
- * @private
125
- */
126
- function increaseSwitchComplexity(node) {
127
-
128
- // Avoiding `default`
129
- if (node.test) {
130
- increaseComplexity();
131
- }
86
+ complexities[complexities.length - 1]++;
132
87
  }
133
88
 
134
89
  //--------------------------------------------------------------------------
@@ -136,13 +91,14 @@ module.exports = {
136
91
  //--------------------------------------------------------------------------
137
92
 
138
93
  return {
139
- FunctionDeclaration: startFunction,
140
- FunctionExpression: startFunction,
141
- ArrowFunctionExpression: startFunction,
142
- "FunctionDeclaration:exit": endFunction,
143
- "FunctionExpression:exit": endFunction,
144
- "ArrowFunctionExpression:exit": endFunction,
145
94
 
95
+ onCodePathStart() {
96
+
97
+ // The initial complexity is 1, representing one execution path in the CodePath
98
+ complexities.push(1);
99
+ },
100
+
101
+ // Each branching in the code adds 1 to the complexity
146
102
  CatchClause: increaseComplexity,
147
103
  ConditionalExpression: increaseComplexity,
148
104
  LogicalExpression: increaseComplexity,
@@ -150,14 +106,49 @@ module.exports = {
150
106
  ForInStatement: increaseComplexity,
151
107
  ForOfStatement: increaseComplexity,
152
108
  IfStatement: increaseComplexity,
153
- SwitchCase: increaseSwitchComplexity,
154
109
  WhileStatement: increaseComplexity,
155
110
  DoWhileStatement: increaseComplexity,
156
111
 
112
+ // Avoid `default`
113
+ "SwitchCase[test]": increaseComplexity,
114
+
115
+ // Logical assignment operators have short-circuiting behavior
157
116
  AssignmentExpression(node) {
158
117
  if (astUtils.isLogicalAssignmentOperator(node.operator)) {
159
118
  increaseComplexity();
160
119
  }
120
+ },
121
+
122
+ onCodePathEnd(codePath, node) {
123
+ const complexity = complexities.pop();
124
+
125
+ /*
126
+ * This rule only evaluates complexity of functions, so "program" is excluded.
127
+ * Class field initializers are implicit functions. Therefore, they shouldn't contribute
128
+ * to the enclosing function's complexity, but their own complexity should be evaluated.
129
+ */
130
+ if (
131
+ codePath.origin !== "function" &&
132
+ codePath.origin !== "class-field-initializer"
133
+ ) {
134
+ return;
135
+ }
136
+
137
+ if (complexity > THRESHOLD) {
138
+ const name = codePath.origin === "class-field-initializer"
139
+ ? "class field initializer"
140
+ : astUtils.getFunctionNameWithKind(node);
141
+
142
+ context.report({
143
+ node,
144
+ messageId: "complex",
145
+ data: {
146
+ name: upperCaseFirst(name),
147
+ complexity,
148
+ max: THRESHOLD
149
+ }
150
+ });
151
+ }
161
152
  }
162
153
  };
163
154
 
@@ -16,7 +16,6 @@ module.exports = {
16
16
 
17
17
  docs: {
18
18
  description: "enforce consistent spacing inside computed property brackets",
19
- category: "Stylistic Issues",
20
19
  recommended: false,
21
20
  url: "https://eslint.org/docs/rules/computed-property-spacing"
22
21
  },
@@ -46,7 +46,6 @@ module.exports = {
46
46
 
47
47
  docs: {
48
48
  description: "require `return` statements to either always or never specify values",
49
- category: "Best Practices",
50
49
  recommended: false,
51
50
  url: "https://eslint.org/docs/rules/consistent-return"
52
51
  },
@@ -14,7 +14,6 @@ module.exports = {
14
14
 
15
15
  docs: {
16
16
  description: "enforce consistent naming when capturing the current execution context",
17
- category: "Stylistic Issues",
18
17
  recommended: false,
19
18
  url: "https://eslint.org/docs/rules/consistent-this"
20
19
  },
@@ -47,7 +46,7 @@ module.exports = {
47
46
  * Reports that a variable declarator or assignment expression is assigning
48
47
  * a non-'this' value to the specified alias.
49
48
  * @param {ASTNode} node The assigning node.
50
- * @param {string} name the name of the alias that was incorrectly used.
49
+ * @param {string} name the name of the alias that was incorrectly used.
51
50
  * @returns {void}
52
51
  */
53
52
  function reportBadAssignment(node, name) {
@@ -122,7 +122,6 @@ module.exports = {
122
122
 
123
123
  docs: {
124
124
  description: "require `super()` calls in constructors",
125
- category: "ECMAScript 6",
126
125
  recommended: true,
127
126
  url: "https://eslint.org/docs/rules/constructor-super"
128
127
  },
@@ -20,7 +20,6 @@ module.exports = {
20
20
 
21
21
  docs: {
22
22
  description: "enforce consistent brace style for all control statements",
23
- category: "Best Practices",
24
23
  recommended: false,
25
24
  url: "https://eslint.org/docs/rules/curly"
26
25
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "enforce default clauses in switch statements to be last",
18
- category: "Best Practices",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/default-case-last"
21
20
  },
@@ -16,7 +16,6 @@ module.exports = {
16
16
 
17
17
  docs: {
18
18
  description: "require `default` cases in `switch` statements",
19
- category: "Best Practices",
20
19
  recommended: false,
21
20
  url: "https://eslint.org/docs/rules/default-case"
22
21
  },
@@ -50,8 +49,8 @@ module.exports = {
50
49
 
51
50
  /**
52
51
  * Shortcut to get last element of array
53
- * @param {*[]} collection Array
54
- * @returns {*} Last element
52
+ * @param {*[]} collection Array
53
+ * @returns {any} Last element
55
54
  */
56
55
  function last(collection) {
57
56
  return collection[collection.length - 1];
@@ -11,7 +11,6 @@ module.exports = {
11
11
 
12
12
  docs: {
13
13
  description: "enforce default parameters to be last",
14
- category: "Best Practices",
15
14
  recommended: false,
16
15
  url: "https://eslint.org/docs/rules/default-param-last"
17
16
  },
@@ -25,8 +24,8 @@ module.exports = {
25
24
 
26
25
  create(context) {
27
26
 
28
- // eslint-disable-next-line jsdoc/require-description
29
27
  /**
28
+ * Handler for function contexts.
30
29
  * @param {ASTNode} node function node
31
30
  * @returns {void}
32
31
  */
@@ -17,7 +17,6 @@ module.exports = {
17
17
 
18
18
  docs: {
19
19
  description: "enforce consistent newlines before and after dots",
20
- category: "Best Practices",
21
20
  recommended: false,
22
21
  url: "https://eslint.org/docs/rules/dot-location"
23
22
  },
@@ -26,7 +26,6 @@ module.exports = {
26
26
 
27
27
  docs: {
28
28
  description: "enforce dot notation whenever possible",
29
- category: "Best Practices",
30
29
  recommended: false,
31
30
  url: "https://eslint.org/docs/rules/dot-notation"
32
31
  },
@@ -14,7 +14,6 @@ module.exports = {
14
14
 
15
15
  docs: {
16
16
  description: "require or disallow newline at the end of files",
17
- category: "Stylistic Issues",
18
17
  recommended: false,
19
18
  url: "https://eslint.org/docs/rules/eol-last"
20
19
  },
@@ -86,10 +85,15 @@ module.exports = {
86
85
  });
87
86
  } else if (mode === "never" && endsWithNewline) {
88
87
 
88
+ const secondLastLine = sourceCode.lines[sourceCode.lines.length - 2];
89
+
89
90
  // File is newline-terminated, but shouldn't be
90
91
  context.report({
91
92
  node,
92
- loc: location,
93
+ loc: {
94
+ start: { line: sourceCode.lines.length - 1, column: secondLastLine.length },
95
+ end: { line: sourceCode.lines.length, column: 0 }
96
+ },
93
97
  messageId: "unexpected",
94
98
  fix(fixer) {
95
99
  const finalEOLs = /(?:\r?\n)+$/u,
@@ -21,7 +21,6 @@ module.exports = {
21
21
 
22
22
  docs: {
23
23
  description: "require the use of `===` and `!==`",
24
- category: "Best Practices",
25
24
  recommended: false,
26
25
  url: "https://eslint.org/docs/rules/eqeqeq"
27
26
  },
@@ -78,7 +77,7 @@ module.exports = {
78
77
 
79
78
  /**
80
79
  * Checks if an expression is a typeof expression
81
- * @param {ASTNode} node The node to check
80
+ * @param {ASTNode} node The node to check
82
81
  * @returns {boolean} if the node is a typeof expression
83
82
  */
84
83
  function isTypeOf(node) {
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "enforce \"for\" loop update clause moving the counter in the right direction.",
18
- category: "Possible Errors",
19
18
  recommended: true,
20
19
  url: "https://eslint.org/docs/rules/for-direction"
21
20
  },
@@ -21,7 +21,6 @@ module.exports = {
21
21
 
22
22
  docs: {
23
23
  description: "require or disallow spacing between function identifiers and their invocations",
24
- category: "Stylistic Issues",
25
24
  recommended: false,
26
25
  url: "https://eslint.org/docs/rules/func-call-spacing"
27
26
  },
@@ -74,7 +74,6 @@ module.exports = {
74
74
 
75
75
  docs: {
76
76
  description: "require function names to match the name of the variable or property to which they are assigned",
77
- category: "Stylistic Issues",
78
77
  recommended: false,
79
78
  url: "https://eslint.org/docs/rules/func-name-matching"
80
79
  },
@@ -196,21 +195,25 @@ module.exports = {
196
195
  const isProp = node.left.type === "MemberExpression";
197
196
  const name = isProp ? astUtils.getStaticPropertyName(node.left) : node.left.name;
198
197
 
199
- if (node.right.id && isIdentifier(name) && shouldWarn(name, node.right.id.name)) {
198
+ if (node.right.id && name && isIdentifier(name) && shouldWarn(name, node.right.id.name)) {
200
199
  report(node, name, node.right.id.name, isProp);
201
200
  }
202
201
  },
203
202
 
204
- Property(node) {
205
- if (node.value.type !== "FunctionExpression" || !node.value.id || node.computed && !isStringLiteral(node.key)) {
203
+ "Property, PropertyDefinition[value]"(node) {
204
+ if (!(node.value.type === "FunctionExpression" && node.value.id)) {
206
205
  return;
207
206
  }
208
207
 
209
- if (node.key.type === "Identifier") {
208
+ if (node.key.type === "Identifier" && !node.computed) {
210
209
  const functionName = node.value.id.name;
211
210
  let propertyName = node.key.name;
212
211
 
213
- if (considerPropertyDescriptor && propertyName === "value") {
212
+ if (
213
+ considerPropertyDescriptor &&
214
+ propertyName === "value" &&
215
+ node.parent.type === "ObjectExpression"
216
+ ) {
214
217
  if (isPropertyCall("Object", "defineProperty", node.parent.parent) || isPropertyCall("Reflect", "defineProperty", node.parent.parent)) {
215
218
  const property = node.parent.parent.arguments[1];
216
219
 
@@ -30,7 +30,6 @@ module.exports = {
30
30
 
31
31
  docs: {
32
32
  description: "require or disallow named `function` expressions",
33
- category: "Stylistic Issues",
34
33
  recommended: false,
35
34
  url: "https://eslint.org/docs/rules/func-names"
36
35
  },
@@ -14,7 +14,6 @@ module.exports = {
14
14
 
15
15
  docs: {
16
16
  description: "enforce the consistent use of either `function` declarations or expressions",
17
- category: "Stylistic Issues",
18
17
  recommended: false,
19
18
  url: "https://eslint.org/docs/rules/func-style"
20
19
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "enforce line breaks between arguments of a function call",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/function-call-argument-newline"
21
20
  },
@@ -20,7 +20,6 @@ module.exports = {
20
20
 
21
21
  docs: {
22
22
  description: "enforce consistent line breaks inside function parentheses",
23
- category: "Stylistic Issues",
24
23
  recommended: false,
25
24
  url: "https://eslint.org/docs/rules/function-paren-newline"
26
25
  },
@@ -183,6 +182,7 @@ module.exports = {
183
182
  /**
184
183
  * Gets the left paren and right paren tokens of a node.
185
184
  * @param {ASTNode} node The node with parens
185
+ * @throws {TypeError} Unexecpted node type.
186
186
  * @returns {Object} An object with keys `leftParen` for the left paren token, and `rightParen` for the right paren token.
187
187
  * Can also return `null` if an expression has no parens (e.g. a NewExpression with no arguments, or an ArrowFunctionExpression
188
188
  * with a single parameter)
@@ -31,7 +31,6 @@ module.exports = {
31
31
 
32
32
  docs: {
33
33
  description: "enforce consistent spacing around `*` operators in generator functions",
34
- category: "ECMAScript 6",
35
34
  recommended: false,
36
35
  url: "https://eslint.org/docs/rules/generator-star-spacing"
37
36
  },
@@ -35,7 +35,6 @@ module.exports = {
35
35
 
36
36
  docs: {
37
37
  description: "enforce `return` statements in getters",
38
- category: "Possible Errors",
39
38
  recommended: true,
40
39
  url: "https://eslint.org/docs/rules/getter-return"
41
40
  },
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule for disallowing require() outside of the top-level module context
3
3
  * @author Jamund Ferguson
4
+ * @deprecated in ESLint v7.0.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -57,7 +58,6 @@ module.exports = {
57
58
 
58
59
  docs: {
59
60
  description: "require `require()` calls to be placed at top-level module scope",
60
- category: "Node.js and CommonJS",
61
61
  recommended: false,
62
62
  url: "https://eslint.org/docs/rules/global-require"
63
63
  },
@@ -96,7 +96,6 @@ module.exports = {
96
96
 
97
97
  docs: {
98
98
  description: "require grouped accessor pairs in object literals and classes",
99
- category: "Best Practices",
100
99
  recommended: false,
101
100
  url: "https://eslint.org/docs/rules/grouped-accessor-pairs"
102
101
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "require `for-in` loops to include an `if` statement",
18
- category: "Best Practices",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/guard-for-in"
21
20
  },
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Ensure handling of errors when we know they exist.
3
3
  * @author Jamund Ferguson
4
+ * @deprecated in ESLint v7.0.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -19,7 +20,6 @@ module.exports = {
19
20
 
20
21
  docs: {
21
22
  description: "require error handling in callbacks",
22
- category: "Node.js and CommonJS",
23
23
  recommended: false,
24
24
  url: "https://eslint.org/docs/rules/handle-callback-err"
25
25
  },
@@ -2,6 +2,7 @@
2
2
  * @fileoverview Rule that warns when identifier names that are
3
3
  * specified in the configuration are used.
4
4
  * @author Keith Cirkel (http://keithcirkel.co.uk)
5
+ * @deprecated in ESLint v7.5.0
5
6
  */
6
7
 
7
8
  "use strict";
@@ -118,7 +119,6 @@ module.exports = {
118
119
 
119
120
  docs: {
120
121
  description: "disallow specified identifiers",
121
- category: "Stylistic Issues",
122
122
  recommended: false,
123
123
  url: "https://eslint.org/docs/rules/id-blacklist"
124
124
  },
@@ -99,7 +99,6 @@ module.exports = {
99
99
 
100
100
  docs: {
101
101
  description: "disallow specified identifiers",
102
- category: "Stylistic Issues",
103
102
  recommended: false,
104
103
  url: "https://eslint.org/docs/rules/id-denylist"
105
104
  },
@@ -16,7 +16,6 @@ module.exports = {
16
16
 
17
17
  docs: {
18
18
  description: "enforce minimum and maximum identifier lengths",
19
- category: "Stylistic Issues",
20
19
  recommended: false,
21
20
  url: "https://eslint.org/docs/rules/id-length"
22
21
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "require identifiers to match a specified regular expression",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/id-match"
21
20
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "enforce the location of arrow function bodies",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/implicit-arrow-linebreak"
21
20
  },
@@ -4,6 +4,7 @@
4
4
  * This rule has been ported and modified from nodeca.
5
5
  * @author Vitaly Puzrin
6
6
  * @author Gyandeep Singh
7
+ * @deprecated in ESLint v4.0.0
7
8
  */
8
9
 
9
10
  "use strict";
@@ -25,7 +26,6 @@ module.exports = {
25
26
 
26
27
  docs: {
27
28
  description: "enforce consistent indentation",
28
- category: "Stylistic Issues",
29
29
  recommended: false,
30
30
  url: "https://eslint.org/docs/rules/indent-legacy"
31
31
  },
@@ -140,7 +140,7 @@ class BinarySearchTree {
140
140
  /**
141
141
  * Inserts an entry into the tree.
142
142
  * @param {number} key The entry's key
143
- * @param {*} value The entry's value
143
+ * @param {any} value The entry's value
144
144
  * @returns {void}
145
145
  */
146
146
  insert(key, value) {
@@ -190,7 +190,6 @@ class BinarySearchTree {
190
190
  */
191
191
  class TokenInfo {
192
192
 
193
- // eslint-disable-next-line jsdoc/require-description
194
193
  /**
195
194
  * @param {SourceCode} sourceCode A SourceCode object
196
195
  */
@@ -240,7 +239,6 @@ class TokenInfo {
240
239
  */
241
240
  class OffsetStorage {
242
241
 
243
- // eslint-disable-next-line jsdoc/require-description
244
242
  /**
245
243
  * @param {TokenInfo} tokenInfo a TokenInfo instance
246
244
  * @param {number} indentSize The desired size of each indentation level
@@ -265,7 +263,7 @@ class OffsetStorage {
265
263
 
266
264
  /**
267
265
  * Sets the offset column of token B to match the offset column of token A.
268
- * **WARNING**: This matches a *column*, even if baseToken is not the first token on its line. In
266
+ * - **WARNING**: This matches a *column*, even if baseToken is not the first token on its line. In
269
267
  * most cases, `setDesiredOffset` should be used instead.
270
268
  * @param {Token} baseToken The first token
271
269
  * @param {Token} offsetToken The second token, whose offset should be matched to the first token
@@ -354,11 +352,11 @@ class OffsetStorage {
354
352
  * Instead, the offset tree is represented as a collection of contiguous offset ranges in a file. For example, the following
355
353
  * list could represent the state of the offset tree at a given point:
356
354
  *
357
- * * Tokens starting in the interval [0, 15) are aligned with the beginning of the file
358
- * * Tokens starting in the interval [15, 30) are offset by 1 indent level from the `bar` token
359
- * * Tokens starting in the interval [30, 43) are offset by 1 indent level from the `foo` token
360
- * * Tokens starting in the interval [43, 820) are offset by 2 indent levels from the `bar` token
361
- * * Tokens starting in the interval [820, ∞) are offset by 1 indent level from the `baz` token
355
+ * - Tokens starting in the interval [0, 15) are aligned with the beginning of the file
356
+ * - Tokens starting in the interval [15, 30) are offset by 1 indent level from the `bar` token
357
+ * - Tokens starting in the interval [30, 43) are offset by 1 indent level from the `foo` token
358
+ * - Tokens starting in the interval [43, 820) are offset by 2 indent levels from the `bar` token
359
+ * - Tokens starting in the interval [820, ∞) are offset by 1 indent level from the `baz` token
362
360
  *
363
361
  * The `setDesiredOffsets` methods inserts ranges like the ones above. The third line above would be inserted by using:
364
362
  * `setDesiredOffsets([30, 43], fooToken, 1);`
@@ -501,7 +499,6 @@ module.exports = {
501
499
 
502
500
  docs: {
503
501
  description: "enforce consistent indentation",
504
- category: "Stylistic Issues",
505
502
  recommended: false,
506
503
  url: "https://eslint.org/docs/rules/indent"
507
504
  },
@@ -6,7 +6,7 @@
6
6
 
7
7
  "use strict";
8
8
 
9
- /* eslint sort-keys: ["error", "asc"] */
9
+ /* eslint sort-keys: ["error", "asc"] -- More readable for long list */
10
10
 
11
11
  const { LazyLoadingRuleMap } = require("./utils/lazy-loading-rule-map");
12
12
 
@@ -48,7 +48,6 @@ module.exports = {
48
48
 
49
49
  docs: {
50
50
  description: "require or disallow initialization in variable declarations",
51
- category: "Variables",
52
51
  recommended: false,
53
52
  url: "https://eslint.org/docs/rules/init-declarations"
54
53
  },
@@ -42,7 +42,6 @@ module.exports = {
42
42
 
43
43
  docs: {
44
44
  description: "enforce the consistent use of either double or single quotes in JSX attributes",
45
- category: "Stylistic Issues",
46
45
  recommended: false,
47
46
  url: "https://eslint.org/docs/rules/jsx-quotes"
48
47
  },