eslint-plugin-unicorn 67.0.0 → 68.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 (157) hide show
  1. package/index.js +4 -0
  2. package/package.json +6 -3
  3. package/readme.md +153 -16
  4. package/rules/ast/is-empty-node.js +1 -5
  5. package/rules/better-dom-traversing.js +17 -8
  6. package/rules/class-reference-in-static-methods.js +14 -2
  7. package/rules/consistent-assert.js +1 -1
  8. package/rules/consistent-boolean-name.js +15 -3
  9. package/rules/consistent-compound-words.js +7 -5
  10. package/rules/consistent-conditional-object-spread.js +354 -0
  11. package/rules/consistent-destructuring.js +5 -0
  12. package/rules/consistent-existence-index-check.js +1 -1
  13. package/rules/consistent-json-file-read.js +4 -16
  14. package/rules/consistent-optional-chaining.js +3 -20
  15. package/rules/default-export-style.js +569 -0
  16. package/rules/expiring-todo-comments.js +1 -1
  17. package/rules/explicit-length-check.js +7 -32
  18. package/rules/import-style.js +8 -6
  19. package/rules/index.js +38 -1
  20. package/rules/logical-assignment-operators.js +17 -4
  21. package/rules/{prevent-abbreviations.js → name-replacements.js} +11 -9
  22. package/rules/new-for-builtins.js +39 -5
  23. package/rules/no-accessor-recursion.js +7 -0
  24. package/rules/no-accidental-bitwise-operator.js +97 -0
  25. package/rules/no-array-callback-reference.js +1 -7
  26. package/rules/no-array-concat-in-loop.js +45 -0
  27. package/rules/no-array-front-mutation.js +64 -0
  28. package/rules/no-array-sort-for-min-max.js +225 -0
  29. package/rules/no-array-splice.js +78 -64
  30. package/rules/no-boolean-sort-comparator.js +215 -0
  31. package/rules/no-break-in-nested-loop.js +33 -0
  32. package/rules/no-chained-comparison.js +116 -0
  33. package/rules/no-collection-bracket-access.js +165 -0
  34. package/rules/no-confusing-array-splice.js +2 -21
  35. package/rules/no-confusing-array-with.js +2 -20
  36. package/rules/no-constant-zero-expression.js +91 -0
  37. package/rules/no-declarations-before-early-exit.js +29 -36
  38. package/rules/no-double-comparison.js +117 -0
  39. package/rules/no-duplicate-if-branches.js +143 -0
  40. package/rules/no-duplicate-logical-operands.js +151 -0
  41. package/rules/no-for-each.js +11 -12
  42. package/rules/no-for-loop.js +3 -15
  43. package/rules/no-impossible-length-comparison.js +166 -0
  44. package/rules/no-incorrect-query-selector.js +8 -4
  45. package/rules/no-incorrect-template-string-interpolation.js +22 -11
  46. package/rules/no-instanceof-builtins.js +14 -1
  47. package/rules/no-invalid-argument-count.js +110 -54
  48. package/rules/no-invalid-character-comparison.js +121 -0
  49. package/rules/no-invalid-fetch-options.js +3 -1
  50. package/rules/no-keyword-prefix.js +14 -4
  51. package/rules/no-late-current-target-access.js +7 -39
  52. package/rules/no-loop-iterable-mutation.js +541 -0
  53. package/rules/no-manually-wrapped-comments.js +10 -2
  54. package/rules/no-misrefactored-assignment.js +102 -0
  55. package/rules/no-named-default.js +35 -2
  56. package/rules/no-nonstandard-builtin-properties.js +1381 -0
  57. package/rules/no-process-exit.js +16 -12
  58. package/rules/no-redundant-comparison.js +5 -12
  59. package/rules/no-selector-as-dom-name.js +150 -0
  60. package/rules/no-thenable.js +27 -11
  61. package/rules/no-uncalled-method.js +2 -8
  62. package/rules/no-undeclared-class-members.js +8 -6
  63. package/rules/no-unnecessary-boolean-comparison.js +131 -0
  64. package/rules/no-unnecessary-splice.js +15 -20
  65. package/rules/no-unreadable-for-of-expression.js +2 -1
  66. package/rules/no-unsafe-property-key.js +10 -15
  67. package/rules/no-unused-properties.js +4 -3
  68. package/rules/no-useless-coercion.js +71 -15
  69. package/rules/no-useless-compound-assignment.js +110 -0
  70. package/rules/no-useless-delete-check.js +353 -0
  71. package/rules/no-useless-else.js +16 -65
  72. package/rules/no-useless-error-capture-stack-trace.js +1 -1
  73. package/rules/no-useless-fallback-in-spread.js +7 -118
  74. package/rules/no-useless-logical-operand.js +248 -0
  75. package/rules/no-useless-undefined.js +11 -28
  76. package/rules/no-xor-as-exponentiation.js +59 -0
  77. package/rules/prefer-array-find.js +95 -5
  78. package/rules/prefer-array-flat-map.js +9 -21
  79. package/rules/prefer-array-flat.js +1 -24
  80. package/rules/prefer-array-from-async.js +273 -0
  81. package/rules/prefer-array-iterable-methods.js +157 -0
  82. package/rules/prefer-array-some.js +56 -31
  83. package/rules/prefer-at.js +1 -24
  84. package/rules/prefer-await.js +29 -0
  85. package/rules/prefer-boolean-return.js +224 -0
  86. package/rules/prefer-continue.js +361 -0
  87. package/rules/prefer-default-parameters.js +10 -6
  88. package/rules/prefer-dispose.js +1 -5
  89. package/rules/prefer-early-return.js +160 -30
  90. package/rules/prefer-else-if.js +50 -53
  91. package/rules/prefer-event-target.js +3 -13
  92. package/rules/prefer-flat-math-min-max.js +103 -0
  93. package/rules/prefer-global-this.js +1 -1
  94. package/rules/prefer-hoisting-branch-code.js +422 -0
  95. package/rules/prefer-identifier-import-export-specifiers.js +6 -11
  96. package/rules/prefer-includes-over-repeated-comparisons.js +5 -1
  97. package/rules/prefer-includes.js +6 -0
  98. package/rules/prefer-logical-operator-over-ternary.js +12 -20
  99. package/rules/prefer-math-constants.js +103 -0
  100. package/rules/prefer-math-min-max.js +1 -5
  101. package/rules/prefer-minimal-ternary.js +26 -2
  102. package/rules/prefer-node-protocol.js +1 -0
  103. package/rules/prefer-number-properties.js +2 -5
  104. package/rules/prefer-object-from-entries.js +6 -1
  105. package/rules/prefer-object-iterable-methods.js +36 -11
  106. package/rules/prefer-optional-catch-binding.js +30 -24
  107. package/rules/prefer-private-class-fields.js +2 -8
  108. package/rules/prefer-promise-with-resolvers.js +248 -0
  109. package/rules/prefer-query-selector.js +79 -17
  110. package/rules/prefer-queue-microtask.js +7 -9
  111. package/rules/prefer-regexp-escape.js +263 -0
  112. package/rules/prefer-set-size.js +10 -2
  113. package/rules/prefer-short-arrow-method.js +3 -3
  114. package/rules/prefer-single-replace.js +218 -0
  115. package/rules/prefer-spread.js +14 -21
  116. package/rules/prefer-string-replace-all.js +5 -0
  117. package/rules/prefer-structured-clone.js +2 -2
  118. package/rules/prefer-switch.js +1 -0
  119. package/rules/prefer-ternary.js +4 -2
  120. package/rules/prefer-type-literal-last.js +22 -54
  121. package/rules/prefer-unary-minus.js +103 -0
  122. package/rules/prefer-url-can-parse.js +308 -0
  123. package/rules/prefer-while-loop-condition.js +252 -0
  124. package/rules/require-passive-events.js +11 -4
  125. package/rules/require-proxy-trap-boolean-return.js +40 -126
  126. package/rules/rule/to-eslint-listener.js +5 -3
  127. package/rules/shared/array-concat-in-loop.js +151 -0
  128. package/rules/shared/identifier-checks.js +4 -16
  129. package/rules/shared/{abbreviations.js → name-replacements.js} +57 -0
  130. package/rules/shared/no-array-mutate-rule.js +19 -2
  131. package/rules/shared/regexp-escape.js +81 -0
  132. package/rules/shared/splice-replacements.js +1 -18
  133. package/rules/string-content.js +11 -4
  134. package/rules/template-indent.js +2 -8
  135. package/rules/throw-new-error.js +7 -0
  136. package/rules/utils/block-scope.js +42 -0
  137. package/rules/utils/builtins.js +50 -1
  138. package/rules/utils/comments.js +16 -0
  139. package/rules/utils/comparison.js +17 -0
  140. package/rules/utils/contains-suspension-point.js +35 -0
  141. package/rules/utils/get-const-variable-initializer.js +31 -0
  142. package/rules/utils/global-reference-tracker.js +14 -1
  143. package/rules/utils/has-optional-chain-element.js +36 -4
  144. package/rules/utils/index.js +32 -2
  145. package/rules/utils/is-boolean.js +23 -0
  146. package/rules/utils/is-function-self-used-inside.js +1 -5
  147. package/rules/utils/is-weak-map.js +21 -0
  148. package/rules/utils/is-weak-set.js +21 -0
  149. package/rules/utils/length-or-size.js +53 -0
  150. package/rules/utils/member-expression.js +18 -0
  151. package/rules/utils/needs-semicolon.js +1 -5
  152. package/rules/utils/numeric.js +20 -0
  153. package/rules/utils/should-add-parentheses-to-logical-expression-child.js +8 -14
  154. package/rules/utils/should-add-parentheses-to-member-expression-object.js +1 -5
  155. package/rules/utils/should-add-parentheses-to-unary-expression.js +8 -2
  156. package/rules/utils/track-branch-exits.js +79 -0
  157. package/rules/utils/types.js +22 -0
package/index.js CHANGED
@@ -28,6 +28,10 @@ const deprecatedRules = createDeprecatedRules({
28
28
  message: 'Replaced by `unicorn/prefer-single-call` which covers more cases.',
29
29
  replacedBy: ['unicorn/prefer-single-call'],
30
30
  },
31
+ 'prevent-abbreviations': {
32
+ message: 'Renamed to `unicorn/name-replacements`.',
33
+ replacedBy: ['unicorn/name-replacements'],
34
+ },
31
35
  'prefer-json-parse-buffer': {
32
36
  message: 'Renamed to `unicorn/consistent-json-file-read`.',
33
37
  replacedBy: ['unicorn/consistent-json-file-read'],
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "eslint-plugin-unicorn",
3
- "version": "67.0.0",
4
- "description": "More than 200 powerful ESLint rules",
3
+ "version": "68.0.0",
4
+ "description": "More than 300 powerful ESLint rules",
5
5
  "license": "MIT",
6
- "repository": "sindresorhus/eslint-plugin-unicorn",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/sindresorhus/eslint-plugin-unicorn.git"
9
+ },
7
10
  "funding": "https://github.com/sindresorhus/eslint-plugin-unicorn?sponsor=1",
8
11
  "author": {
9
12
  "name": "Sindre Sorhus",
package/readme.md CHANGED
@@ -3,13 +3,13 @@
3
3
  <!-- markdownlint-disable-next-line no-inline-html -->
4
4
  <img src="https://cloud.githubusercontent.com/assets/170270/18659176/1cc373d0-7f33-11e6-890f-0ba35362ee7e.jpg" width="180" align="right" alt="Unicorn">
5
5
 
6
- > More than 200 powerful ESLint rules
7
-
8
- You might want to check out [XO](https://github.com/xojs/xo), which includes this plugin.
6
+ > More than 300 powerful ESLint rules
9
7
 
10
8
  Most rules target JavaScript and TypeScript, but [some also lint CSS, HTML, JSON, and Markdown](#non-javascript-files) when used with the matching ESLint language plugin.
11
9
 
12
- [**Propose or contribute a new rule ➡**](.github/contributing.md)
10
+ [**Propose a new rule ➡**](.github/contributing.md)
11
+
12
+ *We do not accept pull requests because of too much AI slop.*
13
13
 
14
14
  ## Install
15
15
 
@@ -19,6 +19,8 @@ npm install --save-dev eslint eslint-plugin-unicorn
19
19
 
20
20
  **Requires ESLint `>=10.4`, [flat config](https://eslint.org/docs/latest/use/configure/configuration-files), and [ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm).**
21
21
 
22
+ *You might want to check out [XO](https://github.com/xojs/xo), which includes this plugin.*
23
+
22
24
  ## Usage
23
25
 
24
26
  Use a [preset config](#preset-configs) or configure each rule in `eslint.config.js`.
@@ -26,17 +28,45 @@ Use a [preset config](#preset-configs) or configure each rule in `eslint.config.
26
28
  If you don't use a preset, set the same `languageOptions` as shown below.
27
29
 
28
30
  ```js
29
- import eslintPluginUnicorn from 'eslint-plugin-unicorn';
31
+ import unicorn from 'eslint-plugin-unicorn';
32
+ import {defineConfig} from 'eslint/config';
33
+ import globals from 'globals';
34
+
35
+ export default defineConfig([
36
+ {
37
+ files: ['**/*.js'],
38
+ languageOptions: {
39
+ globals: globals.builtin,
40
+ },
41
+ plugins: {
42
+ unicorn,
43
+ },
44
+ rules: {
45
+ 'unicorn/prefer-module': 'error',
46
+ 'unicorn/…': 'error',
47
+ },
48
+ },
49
+ // …
50
+ ]);
51
+ ```
52
+
53
+ For TypeScript, scope Unicorn to TypeScript files and configure a TypeScript parser for the same config object:
54
+
55
+ ```js
56
+ import typescriptEslintParser from '@typescript-eslint/parser';
57
+ import unicorn from 'eslint-plugin-unicorn';
30
58
  import {defineConfig} from 'eslint/config';
31
59
  import globals from 'globals';
32
60
 
33
61
  export default defineConfig([
34
62
  {
63
+ files: ['**/*.ts'],
35
64
  languageOptions: {
36
65
  globals: globals.builtin,
66
+ parser: typescriptEslintParser,
37
67
  },
38
68
  plugins: {
39
- unicorn: eslintPluginUnicorn,
69
+ unicorn,
40
70
  },
41
71
  rules: {
42
72
  'unicorn/prefer-module': 'error',
@@ -69,6 +99,7 @@ export default defineConfig([
69
99
  | [consistent-boolean-name](docs/rules/consistent-boolean-name.md) | Enforce consistent naming for boolean names. | ✅ | 🔧 | 💡 | |
70
100
  | [consistent-class-member-order](docs/rules/consistent-class-member-order.md) | Enforce consistent class member order. | ✅ | | 💡 | |
71
101
  | [consistent-compound-words](docs/rules/consistent-compound-words.md) | Enforce consistent spelling of compound words in identifiers. | ✅ ☑️ | | 💡 | |
102
+ | [consistent-conditional-object-spread](docs/rules/consistent-conditional-object-spread.md) | Enforce consistent conditional object spread style. | ✅ | 🔧 | | |
72
103
  | [consistent-date-clone](docs/rules/consistent-date-clone.md) | Prefer passing `Date` directly to the constructor when cloning. | ✅ ☑️ | 🔧 | | |
73
104
  | [consistent-destructuring](docs/rules/consistent-destructuring.md) | Use destructured variables over properties. | | | 💡 | |
74
105
  | [consistent-empty-array-spread](docs/rules/consistent-empty-array-spread.md) | Prefer consistent types when spreading a ternary in an array literal. | ✅ | 🔧 | | |
@@ -80,6 +111,7 @@ export default defineConfig([
80
111
  | [consistent-optional-chaining](docs/rules/consistent-optional-chaining.md) | Enforce consistent optional chaining for same-base member access. | ✅ ☑️ | | 💡 | |
81
112
  | [consistent-template-literal-escape](docs/rules/consistent-template-literal-escape.md) | Enforce consistent style for escaping `${` in template literals. | ✅ | 🔧 | | |
82
113
  | [custom-error-definition](docs/rules/custom-error-definition.md) | Enforce correct `Error` subclassing. | | 🔧 | | |
114
+ | [default-export-style](docs/rules/default-export-style.md) | Enforce consistent default export declarations. | ✅ | 🔧 | 💡 | |
83
115
  | [dom-node-dataset](docs/rules/dom-node-dataset.md) | Enforce consistent style for DOM element dataset access. | ✅ ☑️ | 🔧 | | |
84
116
  | [empty-brace-spaces](docs/rules/empty-brace-spaces.md) | Enforce no spaces between braces. | ✅ | 🔧 | | |
85
117
  | [error-message](docs/rules/error-message.md) | Enforce passing a `message` value when creating a built-in error. | ✅ ☑️ | | | |
@@ -93,30 +125,42 @@ export default defineConfig([
93
125
  | [isolated-functions](docs/rules/isolated-functions.md) | Prevent usage of variables from outside the scope of isolated functions. | ✅ | | | |
94
126
  | [logical-assignment-operators](docs/rules/logical-assignment-operators.md) | Require or disallow logical assignment operator shorthand | ✅ | 🔧 | 💡 | |
95
127
  | [max-nested-calls](docs/rules/max-nested-calls.md) | Limit the depth of nested calls. | ✅ | | | |
96
- | [new-for-builtins](docs/rules/new-for-builtins.md) | Enforce the use of `new` for all builtins, except `String`, `Number`, `Boolean`, `Symbol` and `BigInt`. | ✅ ☑️ | 🔧 | 💡 | |
128
+ | [name-replacements](docs/rules/name-replacements.md) | Enforce replacements for variable, property, and filenames. | ✅ | 🔧 | 💡 | |
129
+ | [new-for-builtins](docs/rules/new-for-builtins.md) | Enforce correct use of `new` for builtin constructors. | ✅ ☑️ | 🔧 | 💡 | |
97
130
  | [no-abusive-eslint-disable](docs/rules/no-abusive-eslint-disable.md) | Enforce specifying rules to disable in `eslint-disable` comments. | ✅ ☑️ | | | |
98
131
  | [no-accessor-recursion](docs/rules/no-accessor-recursion.md) | Disallow recursive access to `this` within getters and setters. | ✅ ☑️ | | | |
132
+ | [no-accidental-bitwise-operator](docs/rules/no-accidental-bitwise-operator.md) | Disallow bitwise operators where a logical operator was likely intended. | ✅ ☑️ | | 💡 | |
99
133
  | [no-anonymous-default-export](docs/rules/no-anonymous-default-export.md) | Disallow anonymous functions and classes as the default export. | ✅ ☑️ | | 💡 | |
100
134
  | [no-array-callback-reference](docs/rules/no-array-callback-reference.md) | Prevent passing a function reference directly to iterator methods. | ✅ | | 💡 | |
135
+ | [no-array-concat-in-loop](docs/rules/no-array-concat-in-loop.md) | Disallow array accumulation with `Array#concat()` in loops. | ✅ | | | |
101
136
  | [no-array-fill-with-reference-type](docs/rules/no-array-fill-with-reference-type.md) | Disallow using reference values as `Array#fill()` values. | ✅ ☑️ | | | |
102
137
  | [no-array-from-fill](docs/rules/no-array-from-fill.md) | Disallow `.fill()` after `Array.from({length: …})`. | ✅ ☑️ | | | |
138
+ | [no-array-front-mutation](docs/rules/no-array-front-mutation.md) | Disallow front-of-array mutation. | | | | |
103
139
  | [no-array-method-this-argument](docs/rules/no-array-method-this-argument.md) | Disallow using the `this` argument in array methods. | ✅ ☑️ | 🔧 | 💡 | |
104
140
  | [no-array-reduce](docs/rules/no-array-reduce.md) | Disallow `Array#reduce()` and `Array#reduceRight()`. | ✅ | 🔧 | 💡 | |
105
141
  | [no-array-reverse](docs/rules/no-array-reverse.md) | Prefer `Array#toReversed()` over `Array#reverse()`. | ✅ ☑️ | | 💡 | |
106
142
  | [no-array-sort](docs/rules/no-array-sort.md) | Prefer `Array#toSorted()` over `Array#sort()`. | ✅ ☑️ | | 💡 | |
143
+ | [no-array-sort-for-min-max](docs/rules/no-array-sort-for-min-max.md) | Disallow sorting arrays to get the minimum or maximum value. | ✅ ☑️ | | 💡 | |
107
144
  | [no-array-splice](docs/rules/no-array-splice.md) | Prefer `Array#toSpliced()` over `Array#splice()`. | ✅ | | 💡 | |
108
145
  | [no-asterisk-prefix-in-documentation-comments](docs/rules/no-asterisk-prefix-in-documentation-comments.md) | Disallow asterisk prefixes in documentation comments. | | 🔧 | | |
109
146
  | [no-await-expression-member](docs/rules/no-await-expression-member.md) | Disallow member access from await expression. | ✅ | 🔧 | | |
110
147
  | [no-await-in-promise-methods](docs/rules/no-await-in-promise-methods.md) | Disallow using `await` in `Promise` method parameters. | ✅ ☑️ | | 💡 | |
111
148
  | [no-blob-to-file](docs/rules/no-blob-to-file.md) | Disallow unnecessary `Blob` to `File` conversion. | ✅ ☑️ | | 💡 | |
149
+ | [no-boolean-sort-comparator](docs/rules/no-boolean-sort-comparator.md) | Disallow boolean-returning sort comparators. | ✅ ☑️ | | 💡 | |
112
150
  | [no-break-in-nested-loop](docs/rules/no-break-in-nested-loop.md) | Disallow `break` and `continue` in nested loops and switches inside loops. | ✅ | | | |
113
151
  | [no-canvas-to-image](docs/rules/no-canvas-to-image.md) | Prefer drawing canvases directly instead of converting them to images. | ✅ ☑️ | | | |
152
+ | [no-chained-comparison](docs/rules/no-chained-comparison.md) | Disallow chained comparisons such as `a < b < c`. | ✅ ☑️ | | 💡 | |
153
+ | [no-collection-bracket-access](docs/rules/no-collection-bracket-access.md) | Disallow accessing `Map`, `Set`, `WeakMap`, and `WeakSet` entries with bracket notation. | ✅ ☑️ | | 💡 | |
114
154
  | [no-computed-property-existence-check](docs/rules/no-computed-property-existence-check.md) | Disallow dynamic object property existence checks. | ✅ | | 💡 | |
115
155
  | [no-confusing-array-splice](docs/rules/no-confusing-array-splice.md) | Disallow confusing uses of `Array#{splice,toSpliced}()`. | ✅ | | 💡 | |
116
156
  | [no-confusing-array-with](docs/rules/no-confusing-array-with.md) | Disallow confusing uses of `Array#with()`. | ✅ | | | |
117
157
  | [no-console-spaces](docs/rules/no-console-spaces.md) | Do not use leading/trailing space between `console.log` parameters. | ✅ ☑️ | 🔧 | | |
158
+ | [no-constant-zero-expression](docs/rules/no-constant-zero-expression.md) | Disallow arithmetic and bitwise operations that always evaluate to `0`. | ✅ ☑️ | | 💡 | |
118
159
  | [no-declarations-before-early-exit](docs/rules/no-declarations-before-early-exit.md) | Disallow declarations before conditional early exits when they are only used after the exit. | ✅ ☑️ | 🔧 | | |
119
160
  | [no-document-cookie](docs/rules/no-document-cookie.md) | Do not use `document.cookie` directly. | ✅ ☑️ | | | |
161
+ | [no-double-comparison](docs/rules/no-double-comparison.md) | Disallow two comparisons of the same operands that can be combined into one. | ✅ ☑️ | | 💡 | |
162
+ | [no-duplicate-if-branches](docs/rules/no-duplicate-if-branches.md) | Disallow duplicate adjacent branches in if chains. | ✅ | | | |
163
+ | [no-duplicate-logical-operands](docs/rules/no-duplicate-logical-operands.md) | Disallow adjacent duplicate operands in logical expressions. | ✅ ☑️ | 🔧 | 💡 | |
120
164
  | [no-duplicate-loops](docs/rules/no-duplicate-loops.md) | Disallow `.map()` and `.filter()` in `for…of` and `for await…of` loop headers. | ✅ | | | |
121
165
  | [no-duplicate-set-values](docs/rules/no-duplicate-set-values.md) | Disallow duplicate values in `Set` constructor array literals. | ✅ | | | |
122
166
  | [no-empty-file](docs/rules/no-empty-file.md) | Disallow empty files. | ✅ ☑️ | | | |
@@ -126,19 +170,23 @@ export default defineConfig([
126
170
  | [no-for-loop](docs/rules/no-for-loop.md) | Do not use a `for` loop that can be replaced with a `for-of` loop. | ✅ | 🔧 | | |
127
171
  | [no-global-object-property-assignment](docs/rules/no-global-object-property-assignment.md) | Disallow assigning properties on the global object. | ✅ ☑️ | | | |
128
172
  | [no-immediate-mutation](docs/rules/no-immediate-mutation.md) | Disallow immediate mutation after variable assignment. | ✅ | 🔧 | 💡 | |
173
+ | [no-impossible-length-comparison](docs/rules/no-impossible-length-comparison.md) | Disallow impossible comparisons against `.length` or `.size`. | ✅ ☑️ | | | |
129
174
  | [no-incorrect-query-selector](docs/rules/no-incorrect-query-selector.md) | Disallow incorrect `querySelector()` and `querySelectorAll()` usage. | ✅ | 🔧 | | |
130
- | [no-incorrect-template-string-interpolation](docs/rules/no-incorrect-template-string-interpolation.md) | Disallow incorrect template literal interpolation syntax. | ✅ ☑️ | | 💡 | |
175
+ | [no-incorrect-template-string-interpolation](docs/rules/no-incorrect-template-string-interpolation.md) | Disallow incorrect template literal interpolation syntax. | ✅ | | 💡 | |
131
176
  | [no-instanceof-builtins](docs/rules/no-instanceof-builtins.md) | Disallow `instanceof` with built-in objects | ✅ ☑️ | 🔧 | 💡 | |
132
177
  | [no-invalid-argument-count](docs/rules/no-invalid-argument-count.md) | Disallow calling functions and constructors with an invalid number of arguments. | ✅ ☑️ | | | |
178
+ | [no-invalid-character-comparison](docs/rules/no-invalid-character-comparison.md) | Disallow comparing a single character from a string to a multi-character string. | ✅ ☑️ | | | |
133
179
  | [no-invalid-fetch-options](docs/rules/no-invalid-fetch-options.md) | Disallow invalid options in `fetch()` and `new Request()`. | ✅ ☑️ | | | |
134
180
  | [no-invalid-file-input-accept](docs/rules/no-invalid-file-input-accept.md) | Disallow invalid `accept` values on file inputs. | | 🔧 | | |
135
181
  | [no-invalid-remove-event-listener](docs/rules/no-invalid-remove-event-listener.md) | Prevent calling `EventTarget#removeEventListener()` with the result of an expression. | ✅ ☑️ | | | |
136
182
  | [no-keyword-prefix](docs/rules/no-keyword-prefix.md) | Disallow identifiers starting with `new` or `class`. | | | | |
137
183
  | [no-late-current-target-access](docs/rules/no-late-current-target-access.md) | Disallow accessing `event.currentTarget` after the synchronous event dispatch has finished. | ✅ | | | |
138
184
  | [no-lonely-if](docs/rules/no-lonely-if.md) | Disallow `if` statements as the only statement in `if` blocks without `else`. | ✅ ☑️ | 🔧 | | |
185
+ | [no-loop-iterable-mutation](docs/rules/no-loop-iterable-mutation.md) | Disallow mutating a loop iterable during iteration. | ✅ | | | |
139
186
  | [no-magic-array-flat-depth](docs/rules/no-magic-array-flat-depth.md) | Disallow a magic number as the `depth` argument in `Array#flat(…).` | ✅ ☑️ | | | |
140
187
  | [no-manually-wrapped-comments](docs/rules/no-manually-wrapped-comments.md) | Disallow manually wrapped comments. | | 🔧 | | |
141
188
  | [no-mismatched-map-key](docs/rules/no-mismatched-map-key.md) | Disallow checking a Map key before accessing a different key. | ✅ | | | |
189
+ | [no-misrefactored-assignment](docs/rules/no-misrefactored-assignment.md) | Disallow misrefactored compound assignments where the target is duplicated in the right-hand side. | ✅ ☑️ | | 💡 | |
142
190
  | [no-named-default](docs/rules/no-named-default.md) | Disallow named usage of default import and export. | ✅ ☑️ | 🔧 | | |
143
191
  | [no-negated-array-predicate](docs/rules/no-negated-array-predicate.md) | Disallow negated array predicate calls. | ✅ ☑️ | 🔧 | | |
144
192
  | [no-negated-comparison](docs/rules/no-negated-comparison.md) | Disallow negated comparisons. | ✅ ☑️ | 🔧 | 💡 | |
@@ -148,6 +196,7 @@ export default defineConfig([
148
196
  | [no-new-array](docs/rules/no-new-array.md) | Disallow `new Array()`. | ✅ ☑️ | 🔧 | 💡 | |
149
197
  | [no-new-buffer](docs/rules/no-new-buffer.md) | Enforce the use of `Buffer.from()` and `Buffer.alloc()` instead of the deprecated `new Buffer()`. | ✅ ☑️ | 🔧 | 💡 | |
150
198
  | [no-non-function-verb-prefix](docs/rules/no-non-function-verb-prefix.md) | Disallow non-function values with function-style verb prefixes. | ✅ | | | 💭 |
199
+ | [no-nonstandard-builtin-properties](docs/rules/no-nonstandard-builtin-properties.md) | Disallow non-standard properties on built-in objects. | ✅ ☑️ | | | |
151
200
  | [no-null](docs/rules/no-null.md) | Disallow the use of the `null` literal. | ✅ | 🔧 | 💡 | |
152
201
  | [no-object-as-default-parameter](docs/rules/no-object-as-default-parameter.md) | Disallow the use of objects as default parameters. | ✅ ☑️ | | | |
153
202
  | [no-object-methods-with-collections](docs/rules/no-object-methods-with-collections.md) | Disallow `Object` methods with `Map` or `Set`. | ✅ | | 💡 | |
@@ -155,6 +204,7 @@ export default defineConfig([
155
204
  | [no-process-exit](docs/rules/no-process-exit.md) | Disallow `process.exit()`. | ✅ ☑️ | | | |
156
205
  | [no-redundant-comparison](docs/rules/no-redundant-comparison.md) | Disallow comparisons made redundant by an equality check in the same logical AND. | ✅ ☑️ | 🔧 | 💡 | |
157
206
  | [no-return-array-push](docs/rules/no-return-array-push.md) | Disallow using the return value of `Array#push()` and `Array#unshift()`. | ✅ | | 💡 | |
207
+ | [no-selector-as-dom-name](docs/rules/no-selector-as-dom-name.md) | Disallow selector syntax in DOM names. | ✅ | 🔧 | | |
158
208
  | [no-single-promise-in-promise-methods](docs/rules/no-single-promise-in-promise-methods.md) | Disallow passing single-element arrays to `Promise` methods. | ✅ ☑️ | 🔧 | 💡 | |
159
209
  | [no-static-only-class](docs/rules/no-static-only-class.md) | Disallow classes that only have static members. | ✅ ☑️ | 🔧 | | |
160
210
  | [no-subtraction-comparison](docs/rules/no-subtraction-comparison.md) | Prefer comparing values directly over subtracting and comparing to `0`. | ✅ ☑️ | 🔧 | 💡 | |
@@ -169,6 +219,7 @@ export default defineConfig([
169
219
  | [no-unnecessary-array-flat-depth](docs/rules/no-unnecessary-array-flat-depth.md) | Disallow using `1` as the `depth` argument of `Array#flat()`. | ✅ ☑️ | 🔧 | | |
170
220
  | [no-unnecessary-array-splice-count](docs/rules/no-unnecessary-array-splice-count.md) | Disallow using `.length` or `Infinity` as the `deleteCount` or `skipCount` argument of `Array#{splice,toSpliced}()`. | ✅ ☑️ | 🔧 | | |
171
221
  | [no-unnecessary-await](docs/rules/no-unnecessary-await.md) | Disallow awaiting non-promise values. | ✅ ☑️ | 🔧 | | |
222
+ | [no-unnecessary-boolean-comparison](docs/rules/no-unnecessary-boolean-comparison.md) | Disallow unnecessary comparisons against boolean literals. | ✅ | 🔧 | | |
172
223
  | [no-unnecessary-global-this](docs/rules/no-unnecessary-global-this.md) | Disallow unnecessary `globalThis` references. | ✅ ☑️ | 🔧 | | |
173
224
  | [no-unnecessary-nested-ternary](docs/rules/no-unnecessary-nested-ternary.md) | Disallow unnecessary nested ternary expressions. | ✅ ☑️ | 🔧 | | |
174
225
  | [no-unnecessary-polyfills](docs/rules/no-unnecessary-polyfills.md) | Enforce the use of built-in methods instead of unnecessary polyfills. | ✅ ☑️ | | | |
@@ -188,13 +239,16 @@ export default defineConfig([
188
239
  | [no-useless-boolean-cast](docs/rules/no-useless-boolean-cast.md) | Disallow unnecessary `Boolean()` casts in array predicate callbacks. | ✅ ☑️ | 🔧 | | |
189
240
  | [no-useless-coercion](docs/rules/no-useless-coercion.md) | Disallow useless type coercions of values that are already of the target type. | ✅ ☑️ | 🔧 | | |
190
241
  | [no-useless-collection-argument](docs/rules/no-useless-collection-argument.md) | Disallow useless values or fallbacks in `Set`, `Map`, `WeakSet`, or `WeakMap`. | ✅ ☑️ | 🔧 | 💡 | |
242
+ | [no-useless-compound-assignment](docs/rules/no-useless-compound-assignment.md) | Disallow useless compound assignments such as `x += 0`. | ✅ ☑️ | | 💡 | |
191
243
  | [no-useless-concat](docs/rules/no-useless-concat.md) | Disallow useless concatenation of literals. | ✅ ☑️ | 🔧 | | |
192
244
  | [no-useless-continue](docs/rules/no-useless-continue.md) | Disallow useless `continue` statements. | ✅ ☑️ | 🔧 | | |
245
+ | [no-useless-delete-check](docs/rules/no-useless-delete-check.md) | Disallow unnecessary existence checks before deletion. | ✅ ☑️ | 🔧 | 💡 | |
193
246
  | [no-useless-else](docs/rules/no-useless-else.md) | Disallow `else` after a statement that exits. | ✅ | 🔧 | | |
194
247
  | [no-useless-error-capture-stack-trace](docs/rules/no-useless-error-capture-stack-trace.md) | Disallow unnecessary `Error.captureStackTrace(…)`. | ✅ ☑️ | 🔧 | | |
195
248
  | [no-useless-fallback-in-spread](docs/rules/no-useless-fallback-in-spread.md) | Disallow useless fallback when spreading in object literals. | ✅ ☑️ | 🔧 | | |
196
249
  | [no-useless-iterator-to-array](docs/rules/no-useless-iterator-to-array.md) | Disallow unnecessary `.toArray()` on iterators. | ✅ ☑️ | 🔧 | 💡 | |
197
250
  | [no-useless-length-check](docs/rules/no-useless-length-check.md) | Disallow useless array length check. | ✅ ☑️ | 🔧 | | |
251
+ | [no-useless-logical-operand](docs/rules/no-useless-logical-operand.md) | Disallow unnecessary operands in logical expressions involving boolean literals. | ✅ ☑️ | 🔧 | | |
198
252
  | [no-useless-override](docs/rules/no-useless-override.md) | Disallow useless overrides of class methods. | ✅ ☑️ | 🔧 | | |
199
253
  | [no-useless-promise-resolve-reject](docs/rules/no-useless-promise-resolve-reject.md) | Disallow returning/yielding `Promise.resolve/reject()` in async functions or promise callbacks | ✅ ☑️ | 🔧 | | |
200
254
  | [no-useless-recursion](docs/rules/no-useless-recursion.md) | Disallow simple recursive function calls that can be replaced with a loop. | ✅ | | | |
@@ -202,6 +256,7 @@ export default defineConfig([
202
256
  | [no-useless-switch-case](docs/rules/no-useless-switch-case.md) | Disallow useless case in switch statements. | ✅ ☑️ | | 💡 | |
203
257
  | [no-useless-template-literals](docs/rules/no-useless-template-literals.md) | Disallow useless template literal expressions. | ✅ ☑️ | 🔧 | 💡 | |
204
258
  | [no-useless-undefined](docs/rules/no-useless-undefined.md) | Disallow useless `undefined`. | ✅ ☑️ | 🔧 | 💡 | |
259
+ | [no-xor-as-exponentiation](docs/rules/no-xor-as-exponentiation.md) | Disallow the bitwise XOR operator where exponentiation was likely intended. | ✅ ☑️ | | 💡 | |
205
260
  | [no-zero-fractions](docs/rules/no-zero-fractions.md) | Disallow number literals with zero fractions or dangling dots. | ✅ ☑️ | 🔧 | | |
206
261
  | [number-literal-case](docs/rules/number-literal-case.md) | Enforce proper case for numeric literals. | ✅ ☑️ | 🔧 | | |
207
262
  | [numeric-separators-style](docs/rules/numeric-separators-style.md) | Enforce the style of numeric separators by correctly grouping digits. | ✅ ☑️ | 🔧 | | |
@@ -211,8 +266,10 @@ export default defineConfig([
211
266
  | [prefer-array-find](docs/rules/prefer-array-find.md) | Prefer `.find(…)` and `.findLast(…)` over the first or last element from `.filter(…)`. | ✅ ☑️ | 🔧 | 💡 | |
212
267
  | [prefer-array-flat](docs/rules/prefer-array-flat.md) | Prefer `Array#flat()` over legacy techniques to flatten arrays. | ✅ ☑️ | 🔧 | | |
213
268
  | [prefer-array-flat-map](docs/rules/prefer-array-flat-map.md) | Prefer `.flatMap(…)` over `.map(…).flat()` and `.filter(…).flatMap(…)`. | ✅ ☑️ | 🔧 | 💡 | |
269
+ | [prefer-array-from-async](docs/rules/prefer-array-from-async.md) | Prefer `Array.fromAsync()` over `for await…of` array accumulation. | ✅ | 🔧 | | |
214
270
  | [prefer-array-from-map](docs/rules/prefer-array-from-map.md) | Prefer using the `Array.from()` mapping function argument. | ✅ ☑️ | 🔧 | 💡 | |
215
271
  | [prefer-array-index-of](docs/rules/prefer-array-index-of.md) | Prefer `Array#{indexOf,lastIndexOf}()` over `Array#{findIndex,findLastIndex}()` when looking for the index of an item. | ✅ ☑️ | 🔧 | 💡 | |
272
+ | [prefer-array-iterable-methods](docs/rules/prefer-array-iterable-methods.md) | Prefer iterating an array directly or with `Array#keys()` over `Array#entries()` when the index or value is unused. | ✅ | 🔧 | | |
216
273
  | [prefer-array-last-methods](docs/rules/prefer-array-last-methods.md) | Prefer last-oriented array methods over `Array#reverse()` or `Array#toReversed()` followed by a method. | ✅ ☑️ | | 💡 | |
217
274
  | [prefer-array-slice](docs/rules/prefer-array-slice.md) | Prefer `Array#slice()` over `Array#splice()` when reading from the returned array. | ✅ | | 💡 | |
218
275
  | [prefer-array-some](docs/rules/prefer-array-some.md) | Prefer `.some(…)` over `.filter(…).length` check and `.{find,findLast,findIndex,findLastIndex}(…)`. | ✅ ☑️ | 🔧 | 💡 | |
@@ -220,9 +277,11 @@ export default defineConfig([
220
277
  | [prefer-await](docs/rules/prefer-await.md) | Prefer `await` over promise chaining. | ✅ ☑️ | | | |
221
278
  | [prefer-bigint-literals](docs/rules/prefer-bigint-literals.md) | Prefer `BigInt` literals over the constructor. | ✅ ☑️ | 🔧 | 💡 | |
222
279
  | [prefer-blob-reading-methods](docs/rules/prefer-blob-reading-methods.md) | Prefer `Blob#arrayBuffer()` over `FileReader#readAsArrayBuffer(…)` and `Blob#text()` over `FileReader#readAsText(…)`. | ✅ ☑️ | | | |
280
+ | [prefer-boolean-return](docs/rules/prefer-boolean-return.md) | Prefer directly returning boolean expressions over `if` statements. | ✅ ☑️ | 🔧 | | |
223
281
  | [prefer-class-fields](docs/rules/prefer-class-fields.md) | Prefer class field declarations over `this` assignments in constructors. | ✅ ☑️ | 🔧 | 💡 | |
224
282
  | [prefer-classlist-toggle](docs/rules/prefer-classlist-toggle.md) | Prefer using `Element#classList.toggle()` to toggle class names. | ✅ ☑️ | 🔧 | 💡 | |
225
283
  | [prefer-code-point](docs/rules/prefer-code-point.md) | Prefer `String#codePointAt(…)` over `String#charCodeAt(…)` and `String.fromCodePoint(…)` over `String.fromCharCode(…)`. | ✅ ☑️ | | 💡 | |
284
+ | [prefer-continue](docs/rules/prefer-continue.md) | Prefer early continues over whole-loop conditional wrapping. | ✅ | 🔧 | | |
226
285
  | [prefer-date-now](docs/rules/prefer-date-now.md) | Prefer `Date.now()` to get the number of milliseconds since the Unix Epoch. | ✅ ☑️ | 🔧 | | |
227
286
  | [prefer-default-parameters](docs/rules/prefer-default-parameters.md) | Prefer default parameters over reassignment. | ✅ ☑️ | | 💡 | |
228
287
  | [prefer-direct-iteration](docs/rules/prefer-direct-iteration.md) | Prefer direct iteration over default iterator method calls. | ✅ ☑️ | 🔧 | | |
@@ -235,10 +294,12 @@ export default defineConfig([
235
294
  | [prefer-else-if](docs/rules/prefer-else-if.md) | Prefer `else if` over adjacent `if` statements with related conditions. | ✅ | 🔧 | 💡 | |
236
295
  | [prefer-event-target](docs/rules/prefer-event-target.md) | Prefer `EventTarget` over `EventEmitter`. | ✅ ☑️ | | | |
237
296
  | [prefer-export-from](docs/rules/prefer-export-from.md) | Prefer `export…from` when re-exporting. | ✅ | 🔧 | 💡 | |
297
+ | [prefer-flat-math-min-max](docs/rules/prefer-flat-math-min-max.md) | Prefer flat `Math.min()` and `Math.max()` calls over nested calls. | ✅ ☑️ | 🔧 | | |
238
298
  | [prefer-get-or-insert-computed](docs/rules/prefer-get-or-insert-computed.md) | Prefer `.getOrInsertComputed()` when the default value has side effects. | ✅ | 🔧 | | |
239
299
  | [prefer-global-number-constants](docs/rules/prefer-global-number-constants.md) | Prefer global numeric constants over `Number` static properties. | ✅ ☑️ | 🔧 | | |
240
300
  | [prefer-global-this](docs/rules/prefer-global-this.md) | Prefer `globalThis` over `window`, `self`, and `global`. | ✅ ☑️ | 🔧 | | |
241
301
  | [prefer-has-check](docs/rules/prefer-has-check.md) | Prefer `.has()` when checking existence. | ✅ ☑️ | 🔧 | | |
302
+ | [prefer-hoisting-branch-code](docs/rules/prefer-hoisting-branch-code.md) | Prefer moving code shared by all branches of an `if` statement out of the branches. | ✅ | 🔧 | 💡 | |
242
303
  | [prefer-https](docs/rules/prefer-https.md) | Prefer HTTPS over HTTP. | ✅ | 🔧 | | |
243
304
  | [prefer-identifier-import-export-specifiers](docs/rules/prefer-identifier-import-export-specifiers.md) | Prefer identifiers over string literals in import and export specifiers. | ✅ ☑️ | 🔧 | | |
244
305
  | [prefer-import-meta-properties](docs/rules/prefer-import-meta-properties.md) | Prefer `import.meta.{dirname,filename}` over legacy techniques for getting file paths. | | 🔧 | | |
@@ -253,6 +314,7 @@ export default defineConfig([
253
314
  | [prefer-logical-operator-over-ternary](docs/rules/prefer-logical-operator-over-ternary.md) | Prefer using a logical operator over a ternary. | ✅ ☑️ | | 💡 | |
254
315
  | [prefer-map-from-entries](docs/rules/prefer-map-from-entries.md) | Prefer `new Map()` over `Object.fromEntries()` when using the result as a map. | ✅ ☑️ | 🔧 | | |
255
316
  | [prefer-math-abs](docs/rules/prefer-math-abs.md) | Prefer `Math.abs()` over manual absolute value expressions and symmetric range checks. | ✅ ☑️ | 🔧 | | |
317
+ | [prefer-math-constants](docs/rules/prefer-math-constants.md) | Prefer `Math` constants over their approximate numeric values. | ✅ ☑️ | | 💡 | |
256
318
  | [prefer-math-min-max](docs/rules/prefer-math-min-max.md) | Prefer `Math.min()` and `Math.max()` over ternaries for simple comparisons. | ✅ ☑️ | 🔧 | | |
257
319
  | [prefer-math-trunc](docs/rules/prefer-math-trunc.md) | Prefer `Math.trunc()` for truncating numbers. | ✅ ☑️ | 🔧 | 💡 | |
258
320
  | [prefer-minimal-ternary](docs/rules/prefer-minimal-ternary.md) | Prefer moving ternaries into the minimal varying part of an expression. | ✅ ☑️ | | | |
@@ -272,21 +334,24 @@ export default defineConfig([
272
334
  | [prefer-optional-catch-binding](docs/rules/prefer-optional-catch-binding.md) | Prefer omitting the `catch` binding parameter. | ✅ ☑️ | 🔧 | | |
273
335
  | [prefer-path2d](docs/rules/prefer-path2d.md) | Prefer `Path2D` for repeatedly drawn canvas paths. | ✅ ☑️ | | | |
274
336
  | [prefer-private-class-fields](docs/rules/prefer-private-class-fields.md) | Prefer private class fields over the underscore-prefix convention. | ✅ | 🔧 | | |
337
+ | [prefer-promise-with-resolvers](docs/rules/prefer-promise-with-resolvers.md) | Prefer `Promise.withResolvers()` when extracting resolver functions from `new Promise()`. | ✅ ☑️ | 🔧 | | |
275
338
  | [prefer-prototype-methods](docs/rules/prefer-prototype-methods.md) | Prefer borrowing methods from the prototype instead of the instance. | ✅ ☑️ | 🔧 | | |
276
339
  | [prefer-query-selector](docs/rules/prefer-query-selector.md) | Prefer `.querySelector()` and `.querySelectorAll()` over older DOM query methods. | ✅ | 🔧 | | |
277
340
  | [prefer-queue-microtask](docs/rules/prefer-queue-microtask.md) | Prefer `queueMicrotask()` over `process.nextTick()`, `setImmediate()`, and `setTimeout(…, 0)`. | ✅ ☑️ | 🔧 | | |
278
341
  | [prefer-reflect-apply](docs/rules/prefer-reflect-apply.md) | Prefer `Reflect.apply()` over `Function#apply()`. | ✅ ☑️ | 🔧 | | |
342
+ | [prefer-regexp-escape](docs/rules/prefer-regexp-escape.md) | Prefer `RegExp.escape()` for escaping strings to use in regular expressions. | | 🔧 | 💡 | |
279
343
  | [prefer-regexp-test](docs/rules/prefer-regexp-test.md) | Prefer `RegExp#test()` over `String#match()`, `String#search()`, and `RegExp#exec()`. | ✅ ☑️ | 🔧 | 💡 | |
280
344
  | [prefer-response-static-json](docs/rules/prefer-response-static-json.md) | Prefer `Response.json()` over `new Response(JSON.stringify())`. | ✅ ☑️ | 🔧 | | |
281
345
  | [prefer-scoped-selector](docs/rules/prefer-scoped-selector.md) | Prefer `:scope` when using element query selector methods. | ✅ | | 💡 | |
282
346
  | [prefer-set-has](docs/rules/prefer-set-has.md) | Prefer `Set#has()` over `Array#includes()` when checking for existence or non-existence. | ✅ ☑️ | 🔧 | 💡 | |
283
347
  | [prefer-set-size](docs/rules/prefer-set-size.md) | Prefer using `Set#size` instead of `Array#length`. | ✅ ☑️ | 🔧 | | |
284
- | [prefer-short-arrow-method](docs/rules/prefer-short-arrow-method.md) | Prefer arrow function properties over methods with a single return. || 🔧 | | |
348
+ | [prefer-short-arrow-method](docs/rules/prefer-short-arrow-method.md) | Prefer arrow function properties over methods with a single return. | | 🔧 | | |
285
349
  | [prefer-simple-condition-first](docs/rules/prefer-simple-condition-first.md) | Prefer simple conditions first in logical expressions. | ✅ ☑️ | 🔧 | 💡 | |
286
350
  | [prefer-simple-sort-comparator](docs/rules/prefer-simple-sort-comparator.md) | Prefer a simple comparison function for `Array#sort()`. | ✅ ☑️ | | 💡 | |
287
351
  | [prefer-single-array-predicate](docs/rules/prefer-single-array-predicate.md) | Prefer a single `Array#some()` or `Array#every()` with a combined predicate. | ✅ ☑️ | | 💡 | |
288
352
  | [prefer-single-call](docs/rules/prefer-single-call.md) | Enforce combining multiple `Array#{push,unshift}()`, `Element#classList.{add,remove}()`, and `importScripts()` into one call. | ✅ ☑️ | 🔧 | 💡 | |
289
353
  | [prefer-single-object-destructuring](docs/rules/prefer-single-object-destructuring.md) | Prefer a single object destructuring declaration per local const source. | ✅ | 🔧 | | |
354
+ | [prefer-single-replace](docs/rules/prefer-single-replace.md) | Enforce combining multiple single-character replacements into a single `String#replaceAll()` with a regular expression. | ✅ ☑️ | 🔧 | | |
290
355
  | [prefer-smaller-scope](docs/rules/prefer-smaller-scope.md) | Prefer declaring variables in the smallest possible scope. | ✅ | 🔧 | | |
291
356
  | [prefer-split-limit](docs/rules/prefer-split-limit.md) | Prefer `String#split()` with a limit. | ✅ ☑️ | 🔧 | | |
292
357
  | [prefer-spread](docs/rules/prefer-spread.md) | Prefer the spread operator over `Array.from(…)`, `Array#concat(…)`, `Array#{slice,toSpliced}()`, and trivial `for…of` copies. | ✅ | 🔧 | 💡 | |
@@ -301,14 +366,16 @@ export default defineConfig([
301
366
  | [prefer-structured-clone](docs/rules/prefer-structured-clone.md) | Prefer using `structuredClone` to create a deep clone. | ✅ ☑️ | | 💡 | |
302
367
  | [prefer-switch](docs/rules/prefer-switch.md) | Prefer `switch` over multiple `else-if`. | ✅ ☑️ | 🔧 | | |
303
368
  | [prefer-temporal](docs/rules/prefer-temporal.md) | Prefer `Temporal` over `Date`. | | 🔧 | 💡 | |
304
- | [prefer-ternary](docs/rules/prefer-ternary.md) | Prefer ternary expressions over simple `if-else` statements that return or assign values. | ✅ ☑️ | 🔧 | 💡 | |
369
+ | [prefer-ternary](docs/rules/prefer-ternary.md) | Prefer ternary expressions over simple `if` statements that return or assign values. | ✅ ☑️ | 🔧 | 💡 | |
305
370
  | [prefer-top-level-await](docs/rules/prefer-top-level-await.md) | Prefer top-level await over top-level promises and async function calls. | ✅ ☑️ | | 💡 | |
306
371
  | [prefer-type-error](docs/rules/prefer-type-error.md) | Enforce throwing `TypeError` in type checking conditions. | ✅ ☑️ | 🔧 | | |
307
- | [prefer-type-literal-last](docs/rules/prefer-type-literal-last.md) | Require type literals to be last in union and intersection types. | ✅ ☑️ | 🔧 | | |
372
+ | [prefer-type-literal-last](docs/rules/prefer-type-literal-last.md) | Require type literals to be last in union types. | ✅ | 🔧 | | |
308
373
  | [prefer-uint8array-base64](docs/rules/prefer-uint8array-base64.md) | Prefer `Uint8Array#toBase64()` and `Uint8Array.fromBase64()` over `atob()`, `btoa()`, and `Buffer` base64 conversions. | ✅ ☑️ | | 💡 | |
374
+ | [prefer-unary-minus](docs/rules/prefer-unary-minus.md) | Prefer the unary minus operator over multiplying or dividing by `-1`. | ✅ ☑️ | 🔧 | | |
309
375
  | [prefer-unicode-code-point-escapes](docs/rules/prefer-unicode-code-point-escapes.md) | Prefer Unicode code point escapes over legacy escape sequences. | ✅ ☑️ | 🔧 | 💡 | |
376
+ | [prefer-url-can-parse](docs/rules/prefer-url-can-parse.md) | Prefer `URL.canParse()` over constructing a `URL` in a try/catch for validation. | ✅ ☑️ | 🔧 | | |
310
377
  | [prefer-url-href](docs/rules/prefer-url-href.md) | Prefer `URL#href` over stringifying a `URL`. | ✅ ☑️ | 🔧 | | |
311
- | [prevent-abbreviations](docs/rules/prevent-abbreviations.md) | Prevent abbreviations. | ✅ | 🔧 | 💡 | |
378
+ | [prefer-while-loop-condition](docs/rules/prefer-while-loop-condition.md) | Prefer putting the condition in the while statement. | ✅ ☑️ | 🔧 | | |
312
379
  | [relative-url-style](docs/rules/relative-url-style.md) | Enforce consistent relative URL style. | ✅ ☑️ | 🔧 | 💡 | |
313
380
  | [require-array-join-separator](docs/rules/require-array-join-separator.md) | Enforce using the separator argument with `Array#join()`. | ✅ ☑️ | 🔧 | | |
314
381
  | [require-array-sort-compare](docs/rules/require-array-sort-compare.md) | Require a compare function when calling `Array#sort()` or `Array#toSorted()`. | ✅ ☑️ | | 💡 | |
@@ -333,6 +400,74 @@ export default defineConfig([
333
400
 
334
401
  While most rules target JavaScript and TypeScript, some also lint other file types when used with the corresponding [ESLint language plugin](https://eslint.org/docs/latest/use/configure/plugins#specifying-a-language) such as [`@eslint/css`](https://github.com/eslint/css), [`@eslint/json`](https://github.com/eslint/json), [`@eslint/markdown`](https://github.com/eslint/markdown), or [`@html-eslint/eslint-plugin`](https://github.com/yeonjuan/html-eslint). Each such rule declares this with the `meta.languages` field.
335
402
 
403
+ When linting JSON, CSS, Markdown, HTML, or other non-JavaScript languages in the same ESLint config, scope Unicorn's JavaScript rule config objects with `files`. Include TypeScript/JSX extensions there only if your config already provides the matching parser/language setup for those files.
404
+
405
+ For example, keep Unicorn's JavaScript rules scoped separately, and enable only compatible Unicorn rules in each non-JavaScript language config:
406
+
407
+ ```js
408
+ import css from '@eslint/css';
409
+ import json from '@eslint/json';
410
+ import markdown from '@eslint/markdown';
411
+ import html from '@html-eslint/eslint-plugin';
412
+ import unicorn from 'eslint-plugin-unicorn';
413
+ import {defineConfig} from 'eslint/config';
414
+
415
+ export default defineConfig([
416
+ {
417
+ files: ['**/*.js'],
418
+ extends: [unicorn.configs.recommended],
419
+ },
420
+ {
421
+ files: ['**/*.json'],
422
+ plugins: {
423
+ json,
424
+ unicorn,
425
+ },
426
+ language: 'json/json',
427
+ rules: {
428
+ 'unicorn/no-empty-file': 'error',
429
+ 'unicorn/prefer-https': 'error',
430
+ },
431
+ },
432
+ {
433
+ files: ['**/*.css'],
434
+ plugins: {
435
+ css,
436
+ unicorn,
437
+ },
438
+ language: 'css/css',
439
+ rules: {
440
+ 'unicorn/prefer-https': 'error',
441
+ 'unicorn/text-encoding-identifier-case': 'error',
442
+ },
443
+ },
444
+ {
445
+ files: ['**/*.html'],
446
+ plugins: {
447
+ html,
448
+ unicorn,
449
+ },
450
+ language: 'html/html',
451
+ rules: {
452
+ 'unicorn/no-invalid-file-input-accept': 'error',
453
+ 'unicorn/prefer-https': 'error',
454
+ },
455
+ },
456
+ {
457
+ files: ['**/*.md'],
458
+ plugins: {
459
+ markdown,
460
+ unicorn,
461
+ },
462
+ language: 'markdown/commonmark',
463
+ rules: {
464
+ 'unicorn/expiring-todo-comments': 'error',
465
+ 'unicorn/prefer-https': 'error',
466
+ },
467
+ },
468
+ ]);
469
+ ```
470
+
336
471
  <!-- Do not manually modify this list. Run: `npm run fix:non-js-languages` -->
337
472
  <!-- begin auto-generated non-js languages list -->
338
473
 
@@ -370,13 +505,14 @@ See the [ESLint docs](https://eslint.org/docs/latest/use/configure/configuration
370
505
  This plugin exports a `recommended` config that enforces good practices.
371
506
 
372
507
  ```js
373
- import eslintPluginUnicorn from 'eslint-plugin-unicorn';
508
+ import unicorn from 'eslint-plugin-unicorn';
374
509
  import {defineConfig} from 'eslint/config';
375
510
 
376
511
  export default defineConfig([
377
512
  // …
378
513
  {
379
- extends: [eslintPluginUnicorn.configs.recommended],
514
+ files: ['**/*.js'],
515
+ extends: [unicorn.configs.recommended],
380
516
  rules: {
381
517
  'unicorn/prefer-module': 'warn',
382
518
  },
@@ -389,13 +525,14 @@ export default defineConfig([
389
525
  This plugin exports an `all` config that enables every rule, except deprecated ones.
390
526
 
391
527
  ```js
392
- import eslintPluginUnicorn from 'eslint-plugin-unicorn';
528
+ import unicorn from 'eslint-plugin-unicorn';
393
529
  import {defineConfig} from 'eslint/config';
394
530
 
395
531
  export default defineConfig([
396
532
  // …
397
533
  {
398
- extends: [eslintPluginUnicorn.configs.all],
534
+ files: ['**/*.js'],
535
+ extends: [unicorn.configs.all],
399
536
  rules: {
400
537
  'unicorn/prefer-module': 'warn',
401
538
  },
@@ -9,9 +9,5 @@ export default function isEmptyNode(node, additionalEmpty) {
9
9
  return true;
10
10
  }
11
11
 
12
- if (additionalEmpty?.(node)) {
13
- return true;
14
- }
15
-
16
- return false;
12
+ return Boolean(additionalEmpty?.(node));
17
13
  }
@@ -4,7 +4,12 @@ import {
4
4
  isMemberExpression,
5
5
  isNumericLiteral,
6
6
  } from './ast/index.js';
7
- import {escapeString, getParenthesizedText, isNodeValueNotDomNode} from './utils/index.js';
7
+ import {
8
+ escapeString,
9
+ getParenthesizedRange,
10
+ getParenthesizedText,
11
+ isNodeValueNotDomNode,
12
+ } from './utils/index.js';
8
13
 
9
14
  const MESSAGE_ID_FIRST_CHILD = 'first-child';
10
15
  const MESSAGE_ID_FIRST_ELEMENT_CHILD = 'first-element-child';
@@ -87,18 +92,24 @@ const isNestedIndexedDomCollection = node =>
87
92
  const hasCommentsInside = (node, sourceCode) =>
88
93
  sourceCode.getCommentsInside(node).length > 0;
89
94
 
90
- const getFirstChildSuggestion = (node, replacement, messageId, sourceCode) => {
95
+ const getFirstChildSuggestion = (node, replacement, messageId, context) => {
96
+ const {sourceCode} = context;
91
97
  if (hasCommentsInside(node, sourceCode)) {
92
98
  return;
93
99
  }
94
100
 
101
+ // Replace the property name (`childNodes`/`children`) and drop the `[index]` access
102
+ // separately, so parentheses around the collection (e.g. `(element.childNodes)[0]`) are preserved.
103
+ const [, objectEnd] = getParenthesizedRange(node.object, context);
95
104
  const [, end] = sourceCode.getRange(node);
96
- const [start] = sourceCode.getRange(node.object.property);
97
105
 
98
106
  return [
99
107
  {
100
108
  messageId,
101
- fix: fixer => fixer.replaceTextRange([start, end], replacement),
109
+ fix: fixer => [
110
+ fixer.replaceText(node.object.property, replacement),
111
+ fixer.removeRange([objectEnd, end]),
112
+ ],
102
113
  },
103
114
  ];
104
115
  };
@@ -222,8 +233,6 @@ const getMergeQuerySelectorSuggestion = (node, querySelectorChain, context) => {
222
233
 
223
234
  /** @param {import('eslint').Rule.RuleContext} context */
224
235
  const create = context => {
225
- const {sourceCode} = context;
226
-
227
236
  context.on('MemberExpression', node => {
228
237
  const collectionName = getIndexedDomCollectionName(node);
229
238
  if (
@@ -243,7 +252,7 @@ const create = context => {
243
252
  return {
244
253
  node,
245
254
  messageId: MESSAGE_ID_FIRST_CHILD,
246
- suggest: getFirstChildSuggestion(node, 'firstChild', SUGGESTION_ID_FIRST_CHILD, sourceCode),
255
+ suggest: getFirstChildSuggestion(node, 'firstChild', SUGGESTION_ID_FIRST_CHILD, context),
247
256
  };
248
257
  }
249
258
 
@@ -251,7 +260,7 @@ const create = context => {
251
260
  return {
252
261
  node,
253
262
  messageId: MESSAGE_ID_FIRST_ELEMENT_CHILD,
254
- suggest: getFirstChildSuggestion(node, 'firstElementChild', SUGGESTION_ID_FIRST_ELEMENT_CHILD, sourceCode),
263
+ suggest: getFirstChildSuggestion(node, 'firstElementChild', SUGGESTION_ID_FIRST_ELEMENT_CHILD, context),
255
264
  };
256
265
  }
257
266
 
@@ -92,6 +92,12 @@ const isSameVariable = (sourceCode, reference, binding) =>
92
92
  findVariable(sourceCode.getScope(reference), reference)
93
93
  === findVariable(sourceCode.getScope(binding), binding);
94
94
 
95
+ // Whether the class/superclass name resolves to the class binding at `node`'s location.
96
+ // If it's shadowed by a local variable, the name can't be used to reference the class.
97
+ const isReferenceNameAvailable = (sourceCode, node, referenceNode) =>
98
+ findVariable(sourceCode.getScope(node), referenceNode.name)
99
+ === findVariable(sourceCode.getScope(referenceNode), referenceNode);
100
+
95
101
  const isAssignmentTargetRoot = (parent, node) =>
96
102
  (
97
103
  parent.type === 'AssignmentExpression'
@@ -331,7 +337,10 @@ const create = context => {
331
337
  }
332
338
 
333
339
  const classReferenceNode = getClassReferenceNode(getClass(staticMethod));
334
- if (!classReferenceNode) {
340
+ if (
341
+ !classReferenceNode
342
+ || !isReferenceNameAvailable(sourceCode, node, classReferenceNode)
343
+ ) {
335
344
  return problemWithoutSuggestion(node, MESSAGE_ID_CLASS_UNAVAILABLE);
336
345
  }
337
346
 
@@ -355,7 +364,10 @@ const create = context => {
355
364
  }
356
365
 
357
366
  const superClassReferenceNode = getSimpleSuperClassReferenceNode(getClass(staticMethod));
358
- if (!superClassReferenceNode) {
367
+ if (
368
+ !superClassReferenceNode
369
+ || !isReferenceNameAvailable(sourceCode, node, superClassReferenceNode)
370
+ ) {
359
371
  return problemWithoutSuggestion(node, MESSAGE_ID_SUPER_CLASS_UNAVAILABLE);
360
372
  }
361
373
 
@@ -60,7 +60,7 @@ const create = context => {
60
60
  const variables = context.sourceCode.getDeclaredVariables(specifier);
61
61
 
62
62
  /* c8 ignore next 3 */
63
- if (!Array.isArray(variables) && variables.length === 1) {
63
+ if (!Array.isArray(variables) || variables.length !== 1) {
64
64
  continue;
65
65
  }
66
66