eslint 8.1.0 → 8.4.1

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 +7 -11
  2. package/conf/globals.js +144 -0
  3. package/lib/cli.js +1 -1
  4. package/lib/config/default-config.js +11 -2
  5. package/lib/config/flat-config-array.js +2 -2
  6. package/lib/config/flat-config-helpers.js +67 -0
  7. package/lib/config/flat-config-schema.js +13 -8
  8. package/lib/config/rule-validator.js +28 -27
  9. package/lib/eslint/eslint.js +11 -3
  10. package/lib/linter/code-path-analysis/code-path-analyzer.js +6 -1
  11. package/lib/linter/code-path-analysis/code-path.js +1 -1
  12. package/lib/linter/linter.js +457 -45
  13. package/lib/options.js +6 -6
  14. package/lib/rules/accessor-pairs.js +1 -0
  15. package/lib/rules/array-bracket-newline.js +1 -0
  16. package/lib/rules/array-bracket-spacing.js +1 -0
  17. package/lib/rules/array-callback-return.js +1 -0
  18. package/lib/rules/array-element-newline.js +1 -0
  19. package/lib/rules/arrow-body-style.js +1 -0
  20. package/lib/rules/arrow-parens.js +1 -0
  21. package/lib/rules/arrow-spacing.js +1 -0
  22. package/lib/rules/block-scoped-var.js +3 -0
  23. package/lib/rules/block-spacing.js +11 -3
  24. package/lib/rules/brace-style.js +7 -0
  25. package/lib/rules/callback-return.js +1 -0
  26. package/lib/rules/camelcase.js +1 -0
  27. package/lib/rules/capitalized-comments.js +1 -0
  28. package/lib/rules/class-methods-use-this.js +11 -1
  29. package/lib/rules/comma-dangle.js +1 -0
  30. package/lib/rules/comma-spacing.js +1 -0
  31. package/lib/rules/comma-style.js +1 -0
  32. package/lib/rules/complexity.js +15 -6
  33. package/lib/rules/computed-property-spacing.js +1 -0
  34. package/lib/rules/consistent-return.js +1 -0
  35. package/lib/rules/consistent-this.js +1 -0
  36. package/lib/rules/constructor-super.js +1 -0
  37. package/lib/rules/curly.js +1 -0
  38. package/lib/rules/default-case-last.js +1 -0
  39. package/lib/rules/default-case.js +1 -0
  40. package/lib/rules/default-param-last.js +1 -0
  41. package/lib/rules/dot-location.js +1 -0
  42. package/lib/rules/dot-notation.js +1 -0
  43. package/lib/rules/eol-last.js +1 -0
  44. package/lib/rules/eqeqeq.js +1 -0
  45. package/lib/rules/for-direction.js +1 -0
  46. package/lib/rules/func-call-spacing.js +1 -0
  47. package/lib/rules/func-name-matching.js +1 -0
  48. package/lib/rules/func-names.js +1 -0
  49. package/lib/rules/func-style.js +1 -0
  50. package/lib/rules/function-call-argument-newline.js +1 -0
  51. package/lib/rules/function-paren-newline.js +1 -0
  52. package/lib/rules/generator-star-spacing.js +1 -0
  53. package/lib/rules/getter-return.js +1 -0
  54. package/lib/rules/global-require.js +1 -0
  55. package/lib/rules/grouped-accessor-pairs.js +1 -0
  56. package/lib/rules/guard-for-in.js +1 -0
  57. package/lib/rules/handle-callback-err.js +1 -0
  58. package/lib/rules/id-blacklist.js +1 -0
  59. package/lib/rules/id-denylist.js +1 -0
  60. package/lib/rules/id-length.js +1 -0
  61. package/lib/rules/id-match.js +1 -0
  62. package/lib/rules/implicit-arrow-linebreak.js +1 -0
  63. package/lib/rules/indent-legacy.js +1 -0
  64. package/lib/rules/indent.js +22 -0
  65. package/lib/rules/init-declarations.js +1 -0
  66. package/lib/rules/jsx-quotes.js +1 -0
  67. package/lib/rules/key-spacing.js +15 -13
  68. package/lib/rules/keyword-spacing.js +2 -0
  69. package/lib/rules/line-comment-position.js +1 -0
  70. package/lib/rules/linebreak-style.js +1 -0
  71. package/lib/rules/lines-around-comment.js +55 -7
  72. package/lib/rules/lines-around-directive.js +1 -0
  73. package/lib/rules/lines-between-class-members.js +1 -0
  74. package/lib/rules/max-classes-per-file.js +1 -0
  75. package/lib/rules/max-depth.js +3 -0
  76. package/lib/rules/max-len.js +1 -0
  77. package/lib/rules/max-lines-per-function.js +1 -0
  78. package/lib/rules/max-lines.js +1 -0
  79. package/lib/rules/max-nested-callbacks.js +1 -0
  80. package/lib/rules/max-params.js +1 -0
  81. package/lib/rules/max-statements-per-line.js +1 -0
  82. package/lib/rules/max-statements.js +11 -0
  83. package/lib/rules/multiline-comment-style.js +1 -0
  84. package/lib/rules/multiline-ternary.js +1 -0
  85. package/lib/rules/new-cap.js +1 -0
  86. package/lib/rules/new-parens.js +1 -0
  87. package/lib/rules/newline-after-var.js +1 -0
  88. package/lib/rules/newline-before-return.js +1 -0
  89. package/lib/rules/newline-per-chained-call.js +1 -0
  90. package/lib/rules/no-alert.js +1 -0
  91. package/lib/rules/no-array-constructor.js +1 -0
  92. package/lib/rules/no-async-promise-executor.js +1 -0
  93. package/lib/rules/no-await-in-loop.js +1 -0
  94. package/lib/rules/no-bitwise.js +1 -0
  95. package/lib/rules/no-buffer-constructor.js +1 -0
  96. package/lib/rules/no-caller.js +1 -0
  97. package/lib/rules/no-case-declarations.js +1 -0
  98. package/lib/rules/no-catch-shadow.js +1 -0
  99. package/lib/rules/no-class-assign.js +1 -0
  100. package/lib/rules/no-compare-neg-zero.js +1 -0
  101. package/lib/rules/no-cond-assign.js +1 -0
  102. package/lib/rules/no-confusing-arrow.js +1 -0
  103. package/lib/rules/no-console.js +1 -0
  104. package/lib/rules/no-const-assign.js +1 -0
  105. package/lib/rules/no-constant-condition.js +4 -1
  106. package/lib/rules/no-constructor-return.js +1 -0
  107. package/lib/rules/no-continue.js +1 -0
  108. package/lib/rules/no-control-regex.js +1 -0
  109. package/lib/rules/no-debugger.js +1 -0
  110. package/lib/rules/no-delete-var.js +1 -0
  111. package/lib/rules/no-div-regex.js +1 -0
  112. package/lib/rules/no-dupe-args.js +1 -0
  113. package/lib/rules/no-dupe-class-members.js +1 -0
  114. package/lib/rules/no-dupe-else-if.js +1 -0
  115. package/lib/rules/no-dupe-keys.js +1 -0
  116. package/lib/rules/no-duplicate-case.js +1 -0
  117. package/lib/rules/no-duplicate-imports.js +1 -0
  118. package/lib/rules/no-else-return.js +1 -0
  119. package/lib/rules/no-empty-character-class.js +1 -0
  120. package/lib/rules/no-empty-function.js +1 -0
  121. package/lib/rules/no-empty-pattern.js +1 -0
  122. package/lib/rules/no-empty.js +1 -0
  123. package/lib/rules/no-eq-null.js +1 -0
  124. package/lib/rules/no-eval.js +3 -0
  125. package/lib/rules/no-ex-assign.js +1 -0
  126. package/lib/rules/no-extend-native.js +1 -0
  127. package/lib/rules/no-extra-bind.js +1 -0
  128. package/lib/rules/no-extra-boolean-cast.js +1 -0
  129. package/lib/rules/no-extra-label.js +1 -0
  130. package/lib/rules/no-extra-parens.js +1 -0
  131. package/lib/rules/no-extra-semi.js +2 -1
  132. package/lib/rules/no-fallthrough.js +1 -0
  133. package/lib/rules/no-floating-decimal.js +1 -0
  134. package/lib/rules/no-func-assign.js +1 -0
  135. package/lib/rules/no-global-assign.js +1 -0
  136. package/lib/rules/no-implicit-coercion.js +1 -0
  137. package/lib/rules/no-implicit-globals.js +1 -0
  138. package/lib/rules/no-implied-eval.js +1 -0
  139. package/lib/rules/no-import-assign.js +1 -0
  140. package/lib/rules/no-inline-comments.js +1 -0
  141. package/lib/rules/no-inner-declarations.js +27 -4
  142. package/lib/rules/no-invalid-regexp.js +1 -0
  143. package/lib/rules/no-invalid-this.js +5 -0
  144. package/lib/rules/no-irregular-whitespace.js +1 -0
  145. package/lib/rules/no-iterator.js +1 -0
  146. package/lib/rules/no-label-var.js +1 -0
  147. package/lib/rules/no-labels.js +1 -0
  148. package/lib/rules/no-lone-blocks.js +9 -2
  149. package/lib/rules/no-lonely-if.js +1 -0
  150. package/lib/rules/no-loop-func.js +1 -0
  151. package/lib/rules/no-loss-of-precision.js +1 -0
  152. package/lib/rules/no-magic-numbers.js +1 -0
  153. package/lib/rules/no-misleading-character-class.js +1 -0
  154. package/lib/rules/no-mixed-operators.js +1 -0
  155. package/lib/rules/no-mixed-requires.js +1 -0
  156. package/lib/rules/no-mixed-spaces-and-tabs.js +1 -0
  157. package/lib/rules/no-multi-assign.js +1 -0
  158. package/lib/rules/no-multi-spaces.js +1 -0
  159. package/lib/rules/no-multi-str.js +1 -0
  160. package/lib/rules/no-multiple-empty-lines.js +1 -0
  161. package/lib/rules/no-native-reassign.js +1 -0
  162. package/lib/rules/no-negated-condition.js +1 -0
  163. package/lib/rules/no-negated-in-lhs.js +1 -0
  164. package/lib/rules/no-nested-ternary.js +1 -0
  165. package/lib/rules/no-new-func.js +1 -0
  166. package/lib/rules/no-new-object.js +1 -0
  167. package/lib/rules/no-new-require.js +1 -0
  168. package/lib/rules/no-new-symbol.js +1 -0
  169. package/lib/rules/no-new-wrappers.js +1 -0
  170. package/lib/rules/no-new.js +1 -0
  171. package/lib/rules/no-nonoctal-decimal-escape.js +1 -0
  172. package/lib/rules/no-obj-calls.js +1 -0
  173. package/lib/rules/no-octal-escape.js +1 -0
  174. package/lib/rules/no-octal.js +1 -0
  175. package/lib/rules/no-param-reassign.js +1 -0
  176. package/lib/rules/no-path-concat.js +1 -0
  177. package/lib/rules/no-plusplus.js +1 -0
  178. package/lib/rules/no-process-env.js +1 -0
  179. package/lib/rules/no-process-exit.js +1 -0
  180. package/lib/rules/no-promise-executor-return.js +1 -0
  181. package/lib/rules/no-proto.js +1 -0
  182. package/lib/rules/no-prototype-builtins.js +1 -0
  183. package/lib/rules/no-redeclare.js +3 -0
  184. package/lib/rules/no-regex-spaces.js +1 -0
  185. package/lib/rules/no-restricted-exports.js +1 -0
  186. package/lib/rules/no-restricted-globals.js +1 -0
  187. package/lib/rules/no-restricted-imports.js +1 -0
  188. package/lib/rules/no-restricted-modules.js +1 -0
  189. package/lib/rules/no-restricted-properties.js +1 -0
  190. package/lib/rules/no-restricted-syntax.js +1 -0
  191. package/lib/rules/no-return-assign.js +1 -0
  192. package/lib/rules/no-return-await.js +1 -0
  193. package/lib/rules/no-script-url.js +1 -0
  194. package/lib/rules/no-self-assign.js +1 -0
  195. package/lib/rules/no-self-compare.js +1 -0
  196. package/lib/rules/no-sequences.js +1 -0
  197. package/lib/rules/no-setter-return.js +1 -0
  198. package/lib/rules/no-shadow-restricted-names.js +1 -0
  199. package/lib/rules/no-shadow.js +1 -0
  200. package/lib/rules/no-spaced-func.js +1 -0
  201. package/lib/rules/no-sparse-arrays.js +1 -0
  202. package/lib/rules/no-sync.js +1 -0
  203. package/lib/rules/no-tabs.js +1 -0
  204. package/lib/rules/no-template-curly-in-string.js +1 -0
  205. package/lib/rules/no-ternary.js +1 -0
  206. package/lib/rules/no-this-before-super.js +1 -0
  207. package/lib/rules/no-throw-literal.js +1 -0
  208. package/lib/rules/no-trailing-spaces.js +1 -0
  209. package/lib/rules/no-undef-init.js +1 -0
  210. package/lib/rules/no-undef.js +1 -0
  211. package/lib/rules/no-undefined.js +1 -0
  212. package/lib/rules/no-underscore-dangle.js +1 -0
  213. package/lib/rules/no-unexpected-multiline.js +1 -0
  214. package/lib/rules/no-unmodified-loop-condition.js +1 -0
  215. package/lib/rules/no-unneeded-ternary.js +1 -0
  216. package/lib/rules/no-unreachable-loop.js +1 -0
  217. package/lib/rules/no-unreachable.js +1 -0
  218. package/lib/rules/no-unsafe-finally.js +1 -0
  219. package/lib/rules/no-unsafe-negation.js +1 -0
  220. package/lib/rules/no-unsafe-optional-chaining.js +1 -0
  221. package/lib/rules/no-unused-expressions.js +7 -0
  222. package/lib/rules/no-unused-labels.js +1 -0
  223. package/lib/rules/no-unused-private-class-members.js +1 -0
  224. package/lib/rules/no-unused-vars.js +1 -0
  225. package/lib/rules/no-use-before-define.js +176 -74
  226. package/lib/rules/no-useless-backreference.js +1 -0
  227. package/lib/rules/no-useless-call.js +1 -0
  228. package/lib/rules/no-useless-catch.js +1 -0
  229. package/lib/rules/no-useless-computed-key.js +1 -0
  230. package/lib/rules/no-useless-concat.js +1 -0
  231. package/lib/rules/no-useless-constructor.js +1 -0
  232. package/lib/rules/no-useless-escape.js +1 -0
  233. package/lib/rules/no-useless-rename.js +1 -0
  234. package/lib/rules/no-useless-return.js +1 -0
  235. package/lib/rules/no-var.js +1 -0
  236. package/lib/rules/no-void.js +1 -0
  237. package/lib/rules/no-warning-comments.js +1 -0
  238. package/lib/rules/no-whitespace-before-property.js +1 -0
  239. package/lib/rules/no-with.js +1 -0
  240. package/lib/rules/nonblock-statement-body-position.js +1 -0
  241. package/lib/rules/object-curly-newline.js +1 -0
  242. package/lib/rules/object-curly-spacing.js +1 -0
  243. package/lib/rules/object-property-newline.js +1 -0
  244. package/lib/rules/object-shorthand.js +1 -0
  245. package/lib/rules/one-var-declaration-per-line.js +1 -0
  246. package/lib/rules/one-var.js +6 -1
  247. package/lib/rules/operator-assignment.js +1 -0
  248. package/lib/rules/operator-linebreak.js +1 -0
  249. package/lib/rules/padded-blocks.js +9 -0
  250. package/lib/rules/padding-line-between-statements.js +3 -0
  251. package/lib/rules/prefer-arrow-callback.js +1 -0
  252. package/lib/rules/prefer-const.js +2 -1
  253. package/lib/rules/prefer-destructuring.js +1 -0
  254. package/lib/rules/prefer-exponentiation-operator.js +1 -0
  255. package/lib/rules/prefer-named-capture-group.js +1 -0
  256. package/lib/rules/prefer-numeric-literals.js +1 -0
  257. package/lib/rules/prefer-object-spread.js +1 -0
  258. package/lib/rules/prefer-promise-reject-errors.js +1 -0
  259. package/lib/rules/prefer-reflect.js +1 -0
  260. package/lib/rules/prefer-regex-literals.js +1 -0
  261. package/lib/rules/prefer-rest-params.js +1 -0
  262. package/lib/rules/prefer-spread.js +1 -0
  263. package/lib/rules/prefer-template.js +1 -0
  264. package/lib/rules/quote-props.js +1 -0
  265. package/lib/rules/quotes.js +1 -0
  266. package/lib/rules/radix.js +1 -0
  267. package/lib/rules/require-atomic-updates.js +15 -2
  268. package/lib/rules/require-await.js +1 -0
  269. package/lib/rules/require-jsdoc.js +1 -0
  270. package/lib/rules/require-unicode-regexp.js +1 -0
  271. package/lib/rules/require-yield.js +1 -0
  272. package/lib/rules/rest-spread-spacing.js +1 -0
  273. package/lib/rules/semi-spacing.js +1 -0
  274. package/lib/rules/semi-style.js +9 -2
  275. package/lib/rules/semi.js +19 -9
  276. package/lib/rules/sort-imports.js +1 -0
  277. package/lib/rules/sort-keys.js +1 -0
  278. package/lib/rules/sort-vars.js +1 -0
  279. package/lib/rules/space-before-blocks.js +1 -0
  280. package/lib/rules/space-before-function-paren.js +1 -0
  281. package/lib/rules/space-in-parens.js +1 -0
  282. package/lib/rules/space-infix-ops.js +1 -0
  283. package/lib/rules/space-unary-ops.js +1 -0
  284. package/lib/rules/spaced-comment.js +1 -0
  285. package/lib/rules/strict.js +1 -0
  286. package/lib/rules/switch-colon-spacing.js +1 -0
  287. package/lib/rules/symbol-description.js +1 -0
  288. package/lib/rules/template-curly-spacing.js +1 -0
  289. package/lib/rules/template-tag-spacing.js +1 -0
  290. package/lib/rules/unicode-bom.js +1 -0
  291. package/lib/rules/use-isnan.js +1 -0
  292. package/lib/rules/utils/ast-utils.js +15 -3
  293. package/lib/rules/valid-jsdoc.js +1 -0
  294. package/lib/rules/valid-typeof.js +1 -0
  295. package/lib/rules/vars-on-top.js +26 -12
  296. package/lib/rules/wrap-iife.js +1 -0
  297. package/lib/rules/wrap-regex.js +1 -0
  298. package/lib/rules/yield-star-spacing.js +1 -0
  299. package/lib/rules/yoda.js +1 -0
  300. package/lib/shared/types.js +10 -0
  301. package/package.json +11 -11
@@ -68,6 +68,7 @@ const KNOWN_NODES = new Set([
68
68
  "ReturnStatement",
69
69
  "SequenceExpression",
70
70
  "SpreadElement",
71
+ "StaticBlock",
71
72
  "Super",
72
73
  "SwitchCase",
73
74
  "SwitchStatement",
@@ -493,6 +494,7 @@ const ELEMENT_LIST_SCHEMA = {
493
494
  ]
494
495
  };
495
496
 
497
+ /** @type {import('../shared/types').Rule} */
496
498
  module.exports = {
497
499
  meta: {
498
500
  type: "layout",
@@ -583,6 +585,16 @@ module.exports = {
583
585
  },
584
586
  additionalProperties: false
585
587
  },
588
+ StaticBlock: {
589
+ type: "object",
590
+ properties: {
591
+ body: {
592
+ type: "integer",
593
+ minimum: 0
594
+ }
595
+ },
596
+ additionalProperties: false
597
+ },
586
598
  CallExpression: {
587
599
  type: "object",
588
600
  properties: {
@@ -646,6 +658,9 @@ module.exports = {
646
658
  parameters: DEFAULT_PARAMETER_INDENT,
647
659
  body: DEFAULT_FUNCTION_BODY_INDENT
648
660
  },
661
+ StaticBlock: {
662
+ body: DEFAULT_FUNCTION_BODY_INDENT
663
+ },
649
664
  CallExpression: {
650
665
  arguments: DEFAULT_PARAMETER_INDENT
651
666
  },
@@ -1397,6 +1412,13 @@ module.exports = {
1397
1412
  }
1398
1413
  },
1399
1414
 
1415
+ StaticBlock(node) {
1416
+ const openingCurly = sourceCode.getFirstToken(node, { skip: 1 }); // skip the `static` token
1417
+ const closingCurly = sourceCode.getLastToken(node);
1418
+
1419
+ addElementListIndent(node.body, openingCurly, closingCurly, options.StaticBlock.body);
1420
+ },
1421
+
1400
1422
  SwitchStatement(node) {
1401
1423
  const openingCurly = sourceCode.getTokenAfter(node.discriminant, astUtils.isOpeningBraceToken);
1402
1424
  const closingCurly = sourceCode.getLastToken(node);
@@ -42,6 +42,7 @@ function isInitialized(node) {
42
42
  // Rule Definition
43
43
  //------------------------------------------------------------------------------
44
44
 
45
+ /** @type {import('../shared/types').Rule} */
45
46
  module.exports = {
46
47
  meta: {
47
48
  type: "suggestion",
@@ -36,6 +36,7 @@ const QUOTE_SETTINGS = {
36
36
  // Rule Definition
37
37
  //------------------------------------------------------------------------------
38
38
 
39
+ /** @type {import('../shared/types').Rule} */
39
40
  module.exports = {
40
41
  meta: {
41
42
  type: "layout",
@@ -133,6 +133,7 @@ function initOptions(toOptions, fromOptions) {
133
133
  // Rule Definition
134
134
  //------------------------------------------------------------------------------
135
135
 
136
+ /** @type {import('../shared/types').Rule} */
136
137
  module.exports = {
137
138
  meta: {
138
139
  type: "layout",
@@ -427,19 +428,7 @@ module.exports = {
427
428
  * @returns {void}
428
429
  */
429
430
  function report(property, side, whitespace, expected, mode) {
430
- const diff = whitespace.length - expected,
431
- nextColon = getNextColon(property.key),
432
- tokenBeforeColon = sourceCode.getTokenBefore(nextColon, { includeComments: true }),
433
- tokenAfterColon = sourceCode.getTokenAfter(nextColon, { includeComments: true }),
434
- isKeySide = side === "key",
435
- isExtra = diff > 0,
436
- diffAbs = Math.abs(diff),
437
- spaces = Array(diffAbs + 1).join(" ");
438
-
439
- const locStart = isKeySide ? tokenBeforeColon.loc.end : nextColon.loc.start;
440
- const locEnd = isKeySide ? nextColon.loc.start : tokenAfterColon.loc.start;
441
- const missingLoc = isKeySide ? tokenBeforeColon.loc : tokenAfterColon.loc;
442
- const loc = isExtra ? { start: locStart, end: locEnd } : missingLoc;
431
+ const diff = whitespace.length - expected;
443
432
 
444
433
  if ((
445
434
  diff && mode === "strict" ||
@@ -447,6 +436,19 @@ module.exports = {
447
436
  diff > 0 && !expected && mode === "minimum") &&
448
437
  !(expected && containsLineTerminator(whitespace))
449
438
  ) {
439
+ const nextColon = getNextColon(property.key),
440
+ tokenBeforeColon = sourceCode.getTokenBefore(nextColon, { includeComments: true }),
441
+ tokenAfterColon = sourceCode.getTokenAfter(nextColon, { includeComments: true }),
442
+ isKeySide = side === "key",
443
+ isExtra = diff > 0,
444
+ diffAbs = Math.abs(diff),
445
+ spaces = Array(diffAbs + 1).join(" ");
446
+
447
+ const locStart = isKeySide ? tokenBeforeColon.loc.end : nextColon.loc.start;
448
+ const locEnd = isKeySide ? nextColon.loc.start : tokenAfterColon.loc.start;
449
+ const missingLoc = isKeySide ? tokenBeforeColon.loc : tokenAfterColon.loc;
450
+ const loc = isExtra ? { start: locStart, end: locEnd } : missingLoc;
451
+
450
452
  let fix;
451
453
 
452
454
  if (isExtra) {
@@ -61,6 +61,7 @@ function isCloseParenOfTemplate(token) {
61
61
  // Rule Definition
62
62
  //------------------------------------------------------------------------------
63
63
 
64
+ /** @type {import('../shared/types').Rule} */
64
65
  module.exports = {
65
66
  meta: {
66
67
  type: "layout",
@@ -590,6 +591,7 @@ module.exports = {
590
591
  ImportNamespaceSpecifier: checkSpacingForImportNamespaceSpecifier,
591
592
  MethodDefinition: checkSpacingForProperty,
592
593
  PropertyDefinition: checkSpacingForProperty,
594
+ StaticBlock: checkSpacingAroundFirstToken,
593
595
  Property: checkSpacingForProperty,
594
596
 
595
597
  // To avoid conflicts with `space-infix-ops`, e.g. `a > this.b`
@@ -10,6 +10,7 @@ const astUtils = require("./utils/ast-utils");
10
10
  // Rule Definition
11
11
  //------------------------------------------------------------------------------
12
12
 
13
+ /** @type {import('../shared/types').Rule} */
13
14
  module.exports = {
14
15
  meta: {
15
16
  type: "layout",
@@ -15,6 +15,7 @@ const astUtils = require("./utils/ast-utils");
15
15
  // Rule Definition
16
16
  //------------------------------------------------------------------------------
17
17
 
18
+ /** @type {import('../shared/types').Rule} */
18
19
  module.exports = {
19
20
  meta: {
20
21
  type: "layout",
@@ -49,6 +49,7 @@ function getCommentLineNums(comments) {
49
49
  // Rule Definition
50
50
  //------------------------------------------------------------------------------
51
51
 
52
+ /** @type {import('../shared/types').Rule} */
52
53
  module.exports = {
53
54
  meta: {
54
55
  type: "layout",
@@ -185,10 +186,39 @@ module.exports = {
185
186
  /**
186
187
  * Returns the parent node that contains the given token.
187
188
  * @param {token} token The token to check.
188
- * @returns {ASTNode} The parent node that contains the given token.
189
+ * @returns {ASTNode|null} The parent node that contains the given token.
189
190
  */
190
191
  function getParentNodeOfToken(token) {
191
- return sourceCode.getNodeByRangeIndex(token.range[0]);
192
+ const node = sourceCode.getNodeByRangeIndex(token.range[0]);
193
+
194
+ /*
195
+ * For the purpose of this rule, the comment token is in a `StaticBlock` node only
196
+ * if it's inside the braces of that `StaticBlock` node.
197
+ *
198
+ * Example where this function returns `null`:
199
+ *
200
+ * static
201
+ * // comment
202
+ * {
203
+ * }
204
+ *
205
+ * Example where this function returns `StaticBlock` node:
206
+ *
207
+ * static
208
+ * {
209
+ * // comment
210
+ * }
211
+ *
212
+ */
213
+ if (node && node.type === "StaticBlock") {
214
+ const openingBrace = sourceCode.getFirstToken(node, { skip: 1 }); // skip the `static` token
215
+
216
+ return token.range[0] >= openingBrace.range[0]
217
+ ? node
218
+ : null;
219
+ }
220
+
221
+ return node;
192
222
  }
193
223
 
194
224
  /**
@@ -200,8 +230,15 @@ module.exports = {
200
230
  function isCommentAtParentStart(token, nodeType) {
201
231
  const parent = getParentNodeOfToken(token);
202
232
 
203
- return parent && isParentNodeType(parent, nodeType) &&
204
- token.loc.start.line - parent.loc.start.line === 1;
233
+ if (parent && isParentNodeType(parent, nodeType)) {
234
+ const parentStartNodeOrToken = parent.type === "StaticBlock"
235
+ ? sourceCode.getFirstToken(parent, { skip: 1 }) // opening brace of the static block
236
+ : parent;
237
+
238
+ return token.loc.start.line - parentStartNodeOrToken.loc.start.line === 1;
239
+ }
240
+
241
+ return false;
205
242
  }
206
243
 
207
244
  /**
@@ -213,7 +250,7 @@ module.exports = {
213
250
  function isCommentAtParentEnd(token, nodeType) {
214
251
  const parent = getParentNodeOfToken(token);
215
252
 
216
- return parent && isParentNodeType(parent, nodeType) &&
253
+ return !!parent && isParentNodeType(parent, nodeType) &&
217
254
  parent.loc.end.line - token.loc.end.line === 1;
218
255
  }
219
256
 
@@ -223,7 +260,12 @@ module.exports = {
223
260
  * @returns {boolean} True if the comment is at block start.
224
261
  */
225
262
  function isCommentAtBlockStart(token) {
226
- return isCommentAtParentStart(token, "ClassBody") || isCommentAtParentStart(token, "BlockStatement") || isCommentAtParentStart(token, "SwitchCase");
263
+ return (
264
+ isCommentAtParentStart(token, "ClassBody") ||
265
+ isCommentAtParentStart(token, "BlockStatement") ||
266
+ isCommentAtParentStart(token, "StaticBlock") ||
267
+ isCommentAtParentStart(token, "SwitchCase")
268
+ );
227
269
  }
228
270
 
229
271
  /**
@@ -232,7 +274,13 @@ module.exports = {
232
274
  * @returns {boolean} True if the comment is at block end.
233
275
  */
234
276
  function isCommentAtBlockEnd(token) {
235
- return isCommentAtParentEnd(token, "ClassBody") || isCommentAtParentEnd(token, "BlockStatement") || isCommentAtParentEnd(token, "SwitchCase") || isCommentAtParentEnd(token, "SwitchStatement");
277
+ return (
278
+ isCommentAtParentEnd(token, "ClassBody") ||
279
+ isCommentAtParentEnd(token, "BlockStatement") ||
280
+ isCommentAtParentEnd(token, "StaticBlock") ||
281
+ isCommentAtParentEnd(token, "SwitchCase") ||
282
+ isCommentAtParentEnd(token, "SwitchStatement")
283
+ );
236
284
  }
237
285
 
238
286
  /**
@@ -12,6 +12,7 @@ const astUtils = require("./utils/ast-utils");
12
12
  // Rule Definition
13
13
  //------------------------------------------------------------------------------
14
14
 
15
+ /** @type {import('../shared/types').Rule} */
15
16
  module.exports = {
16
17
  meta: {
17
18
  type: "layout",
@@ -14,6 +14,7 @@ const astUtils = require("./utils/ast-utils");
14
14
  // Rule Definition
15
15
  //------------------------------------------------------------------------------
16
16
 
17
+ /** @type {import('../shared/types').Rule} */
17
18
  module.exports = {
18
19
  meta: {
19
20
  type: "layout",
@@ -13,6 +13,7 @@
13
13
  // Rule Definition
14
14
  //------------------------------------------------------------------------------
15
15
 
16
+ /** @type {import('../shared/types').Rule} */
16
17
  module.exports = {
17
18
  meta: {
18
19
  type: "suggestion",
@@ -9,6 +9,7 @@
9
9
  // Rule Definition
10
10
  //------------------------------------------------------------------------------
11
11
 
12
+ /** @type {import('../shared/types').Rule} */
12
13
  module.exports = {
13
14
  meta: {
14
15
  type: "suggestion",
@@ -118,6 +119,7 @@ module.exports = {
118
119
  FunctionDeclaration: startFunction,
119
120
  FunctionExpression: startFunction,
120
121
  ArrowFunctionExpression: startFunction,
122
+ StaticBlock: startFunction,
121
123
 
122
124
  IfStatement(node) {
123
125
  if (node.parent.type !== "IfStatement") {
@@ -146,6 +148,7 @@ module.exports = {
146
148
  "FunctionDeclaration:exit": endFunction,
147
149
  "FunctionExpression:exit": endFunction,
148
150
  "ArrowFunctionExpression:exit": endFunction,
151
+ "StaticBlock:exit": endFunction,
149
152
  "Program:exit": endFunction
150
153
  };
151
154
 
@@ -63,6 +63,7 @@ const OPTIONS_OR_INTEGER_SCHEMA = {
63
63
  // Rule Definition
64
64
  //------------------------------------------------------------------------------
65
65
 
66
+ /** @type {import('../shared/types').Rule} */
66
67
  module.exports = {
67
68
  meta: {
68
69
  type: "layout",
@@ -65,6 +65,7 @@ function getCommentLineNumbers(comments) {
65
65
  // Rule Definition
66
66
  //------------------------------------------------------------------------------
67
67
 
68
+ /** @type {import('../shared/types').Rule} */
68
69
  module.exports = {
69
70
  meta: {
70
71
  type: "suggestion",
@@ -28,6 +28,7 @@ function range(start, end) {
28
28
  // Rule Definition
29
29
  //------------------------------------------------------------------------------
30
30
 
31
+ /** @type {import('../shared/types').Rule} */
31
32
  module.exports = {
32
33
  meta: {
33
34
  type: "suggestion",
@@ -9,6 +9,7 @@
9
9
  // Rule Definition
10
10
  //------------------------------------------------------------------------------
11
11
 
12
+ /** @type {import('../shared/types').Rule} */
12
13
  module.exports = {
13
14
  meta: {
14
15
  type: "suggestion",
@@ -16,6 +16,7 @@ const { upperCaseFirst } = require("../shared/string-utils");
16
16
  // Rule Definition
17
17
  //------------------------------------------------------------------------------
18
18
 
19
+ /** @type {import('../shared/types').Rule} */
19
20
  module.exports = {
20
21
  meta: {
21
22
  type: "suggestion",
@@ -14,6 +14,7 @@ const astUtils = require("./utils/ast-utils");
14
14
  // Rule Definition
15
15
  //------------------------------------------------------------------------------
16
16
 
17
+ /** @type {import('../shared/types').Rule} */
17
18
  module.exports = {
18
19
  meta: {
19
20
  type: "layout",
@@ -16,6 +16,7 @@ const { upperCaseFirst } = require("../shared/string-utils");
16
16
  // Rule Definition
17
17
  //------------------------------------------------------------------------------
18
18
 
19
+ /** @type {import('../shared/types').Rule} */
19
20
  module.exports = {
20
21
  meta: {
21
22
  type: "suggestion",
@@ -123,6 +124,14 @@ module.exports = {
123
124
  function endFunction(node) {
124
125
  const count = functionStack.pop();
125
126
 
127
+ /*
128
+ * This rule does not apply to class static blocks, but we have to track them so
129
+ * that stataments in them do not count as statements in the enclosing function.
130
+ */
131
+ if (node.type === "StaticBlock") {
132
+ return;
133
+ }
134
+
126
135
  if (ignoreTopLevelFunctions && functionStack.length === 0) {
127
136
  topLevelFunctions.push({ node, count });
128
137
  } else {
@@ -148,12 +157,14 @@ module.exports = {
148
157
  FunctionDeclaration: startFunction,
149
158
  FunctionExpression: startFunction,
150
159
  ArrowFunctionExpression: startFunction,
160
+ StaticBlock: startFunction,
151
161
 
152
162
  BlockStatement: countStatements,
153
163
 
154
164
  "FunctionDeclaration:exit": endFunction,
155
165
  "FunctionExpression:exit": endFunction,
156
166
  "ArrowFunctionExpression:exit": endFunction,
167
+ "StaticBlock:exit": endFunction,
157
168
 
158
169
  "Program:exit"() {
159
170
  if (topLevelFunctions.length === 1) {
@@ -10,6 +10,7 @@ const astUtils = require("./utils/ast-utils");
10
10
  // Rule Definition
11
11
  //------------------------------------------------------------------------------
12
12
 
13
+ /** @type {import('../shared/types').Rule} */
13
14
  module.exports = {
14
15
  meta: {
15
16
  type: "suggestion",
@@ -11,6 +11,7 @@ const astUtils = require("./utils/ast-utils");
11
11
  // Rule Definition
12
12
  //------------------------------------------------------------------------------
13
13
 
14
+ /** @type {import('../shared/types').Rule} */
14
15
  module.exports = {
15
16
  meta: {
16
17
  type: "layout",
@@ -76,6 +76,7 @@ function calculateCapIsNewExceptions(config) {
76
76
  // Rule Definition
77
77
  //------------------------------------------------------------------------------
78
78
 
79
+ /** @type {import('../shared/types').Rule} */
79
80
  module.exports = {
80
81
  meta: {
81
82
  type: "suggestion",
@@ -19,6 +19,7 @@ const astUtils = require("./utils/ast-utils");
19
19
  // Rule Definition
20
20
  //------------------------------------------------------------------------------
21
21
 
22
+ /** @type {import('../shared/types').Rule} */
22
23
  module.exports = {
23
24
  meta: {
24
25
  type: "layout",
@@ -16,6 +16,7 @@ const astUtils = require("./utils/ast-utils");
16
16
  // Rule Definition
17
17
  //------------------------------------------------------------------------------
18
18
 
19
+ /** @type {import('../shared/types').Rule} */
19
20
  module.exports = {
20
21
  meta: {
21
22
  type: "layout",
@@ -9,6 +9,7 @@
9
9
  // Rule Definition
10
10
  //------------------------------------------------------------------------------
11
11
 
12
+ /** @type {import('../shared/types').Rule} */
12
13
  module.exports = {
13
14
  meta: {
14
15
  type: "layout",
@@ -12,6 +12,7 @@ const astUtils = require("./utils/ast-utils");
12
12
  // Rule Definition
13
13
  //------------------------------------------------------------------------------
14
14
 
15
+ /** @type {import('../shared/types').Rule} */
15
16
  module.exports = {
16
17
  meta: {
17
18
  type: "layout",
@@ -82,6 +82,7 @@ function isGlobalThisReferenceOrGlobalWindow(scope, node) {
82
82
  // Rule Definition
83
83
  //------------------------------------------------------------------------------
84
84
 
85
+ /** @type {import('../shared/types').Rule} */
85
86
  module.exports = {
86
87
  meta: {
87
88
  type: "suggestion",
@@ -9,6 +9,7 @@
9
9
  // Rule Definition
10
10
  //------------------------------------------------------------------------------
11
11
 
12
+ /** @type {import('../shared/types').Rule} */
12
13
  module.exports = {
13
14
  meta: {
14
15
  type: "suggestion",
@@ -8,6 +8,7 @@
8
8
  // Rule Definition
9
9
  //------------------------------------------------------------------------------
10
10
 
11
+ /** @type {import('../shared/types').Rule} */
11
12
  module.exports = {
12
13
  meta: {
13
14
  type: "problem",
@@ -53,6 +53,7 @@ function isLooped(node, parent) {
53
53
  }
54
54
  }
55
55
 
56
+ /** @type {import('../shared/types').Rule} */
56
57
  module.exports = {
57
58
  meta: {
58
59
  type: "problem",
@@ -20,6 +20,7 @@ const BITWISE_OPERATORS = [
20
20
  // Rule Definition
21
21
  //------------------------------------------------------------------------------
22
22
 
23
+ /** @type {import('../shared/types').Rule} */
23
24
  module.exports = {
24
25
  meta: {
25
26
  type: "suggestion",
@@ -9,6 +9,7 @@
9
9
  // Rule Definition
10
10
  //------------------------------------------------------------------------------
11
11
 
12
+ /** @type {import('../shared/types').Rule} */
12
13
  module.exports = {
13
14
  meta: {
14
15
  deprecated: true,
@@ -9,6 +9,7 @@
9
9
  // Rule Definition
10
10
  //------------------------------------------------------------------------------
11
11
 
12
+ /** @type {import('../shared/types').Rule} */
12
13
  module.exports = {
13
14
  meta: {
14
15
  type: "suggestion",
@@ -8,6 +8,7 @@
8
8
  // Rule Definition
9
9
  //------------------------------------------------------------------------------
10
10
 
11
+ /** @type {import('../shared/types').Rule} */
11
12
  module.exports = {
12
13
  meta: {
13
14
  type: "suggestion",
@@ -16,6 +16,7 @@ const astUtils = require("./utils/ast-utils");
16
16
  // Rule Definition
17
17
  //------------------------------------------------------------------------------
18
18
 
19
+ /** @type {import('../shared/types').Rule} */
19
20
  module.exports = {
20
21
  meta: {
21
22
  type: "suggestion",
@@ -11,6 +11,7 @@ const astUtils = require("./utils/ast-utils");
11
11
  // Rule Definition
12
12
  //------------------------------------------------------------------------------
13
13
 
14
+ /** @type {import('../shared/types').Rule} */
14
15
  module.exports = {
15
16
  meta: {
16
17
  type: "problem",
@@ -8,6 +8,7 @@
8
8
  // Rule Definition
9
9
  //------------------------------------------------------------------------------
10
10
 
11
+ /** @type {import('../shared/types').Rule} */
11
12
  module.exports = {
12
13
  meta: {
13
14
  type: "problem",
@@ -28,6 +28,7 @@ const NODE_DESCRIPTIONS = {
28
28
  // Rule Definition
29
29
  //------------------------------------------------------------------------------
30
30
 
31
+ /** @type {import('../shared/types').Rule} */
31
32
  module.exports = {
32
33
  meta: {
33
34
  type: "problem",
@@ -25,6 +25,7 @@ function isConditional(node) {
25
25
  // Rule Definition
26
26
  //------------------------------------------------------------------------------
27
27
 
28
+ /** @type {import('../shared/types').Rule} */
28
29
  module.exports = {
29
30
  meta: {
30
31
  type: "suggestion",
@@ -15,6 +15,7 @@ const astUtils = require("./utils/ast-utils");
15
15
  // Rule Definition
16
16
  //------------------------------------------------------------------------------
17
17
 
18
+ /** @type {import('../shared/types').Rule} */
18
19
  module.exports = {
19
20
  meta: {
20
21
  type: "suggestion",
@@ -11,6 +11,7 @@ const astUtils = require("./utils/ast-utils");
11
11
  // Rule Definition
12
12
  //------------------------------------------------------------------------------
13
13
 
14
+ /** @type {import('../shared/types').Rule} */
14
15
  module.exports = {
15
16
  meta: {
16
17
  type: "problem",
@@ -13,6 +13,7 @@
13
13
  // Rule Definition
14
14
  //------------------------------------------------------------------------------
15
15
 
16
+ /** @type {import('../shared/types').Rule} */
16
17
  module.exports = {
17
18
  meta: {
18
19
  type: "problem",
@@ -138,6 +139,7 @@ module.exports = {
138
139
  case "ArrowFunctionExpression":
139
140
  case "FunctionExpression":
140
141
  case "ObjectExpression":
142
+ case "ClassExpression":
141
143
  return true;
142
144
  case "TemplateLiteral":
143
145
  return (inBooleanPosition && node.quasis.some(quasi => quasi.value.cooked.length)) ||
@@ -179,7 +181,8 @@ module.exports = {
179
181
  isLeftShortCircuit ||
180
182
  isRightShortCircuit;
181
183
  }
182
-
184
+ case "NewExpression":
185
+ return inBooleanPosition;
183
186
  case "AssignmentExpression":
184
187
  if (node.operator === "=") {
185
188
  return isConstant(node.right, inBooleanPosition);
@@ -9,6 +9,7 @@
9
9
  // Rule Definition
10
10
  //------------------------------------------------------------------------------
11
11
 
12
+ /** @type {import('../shared/types').Rule} */
12
13
  module.exports = {
13
14
  meta: {
14
15
  type: "problem",