From 7d804e3ce8ecb9d51b16d558eeae6dc12a81ec4c Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Fri, 21 Oct 2022 09:07:32 -0400 Subject: [PATCH] Automate docs with eslint-doc-generator (#1930) --- docs/rules/better-regex.md | 10 +- docs/rules/catch-error-name.md | 10 +- docs/rules/consistent-destructuring.md | 10 +- docs/rules/consistent-function-scoping.md | 8 +- docs/rules/custom-error-definition.md | 8 +- docs/rules/empty-brace-spaces.md | 10 +- docs/rules/error-message.md | 8 +- docs/rules/escape-case.md | 10 +- docs/rules/expiring-todo-comments.md | 8 +- docs/rules/explicit-length-check.md | 10 +- docs/rules/filename-case.md | 8 +- docs/rules/import-style.md | 8 +- docs/rules/new-for-builtins.md | 10 +- docs/rules/no-abusive-eslint-disable.md | 8 +- docs/rules/no-array-callback-reference.md | 10 +- docs/rules/no-array-for-each.md | 10 +- docs/rules/no-array-method-this-argument.md | 10 +- docs/rules/no-array-push-push.md | 10 +- docs/rules/no-array-reduce.md | 8 +- docs/rules/no-await-expression-member.md | 10 +- docs/rules/no-console-spaces.md | 10 +- docs/rules/no-document-cookie.md | 8 +- docs/rules/no-empty-file.md | 8 +- docs/rules/no-for-loop.md | 10 +- docs/rules/no-hex-escape.md | 10 +- docs/rules/no-instanceof-array.md | 10 +- .../rules/no-invalid-remove-event-listener.md | 8 +- docs/rules/no-keyword-prefix.md | 5 +- docs/rules/no-lonely-if.md | 10 +- docs/rules/no-nested-ternary.md | 10 +- docs/rules/no-new-array.md | 10 +- docs/rules/no-new-buffer.md | 10 +- docs/rules/no-null.md | 10 +- docs/rules/no-object-as-default-parameter.md | 8 +- docs/rules/no-process-exit.md | 8 +- docs/rules/no-static-only-class.md | 10 +- docs/rules/no-thenable.md | 8 +- docs/rules/no-this-assignment.md | 8 +- docs/rules/no-unnecessary-await.md | 10 +- .../no-unreadable-array-destructuring.md | 10 +- docs/rules/no-unreadable-iife.md | 8 +- docs/rules/no-unsafe-regex.md | 5 +- docs/rules/no-unused-properties.md | 5 +- docs/rules/no-useless-fallback-in-spread.md | 10 +- docs/rules/no-useless-length-check.md | 10 +- .../no-useless-promise-resolve-reject.md | 10 +- docs/rules/no-useless-spread.md | 10 +- docs/rules/no-useless-switch-case.md | 10 +- docs/rules/no-useless-undefined.md | 10 +- docs/rules/no-zero-fractions.md | 10 +- docs/rules/number-literal-case.md | 10 +- docs/rules/numeric-separators-style.md | 10 +- docs/rules/prefer-add-event-listener.md | 10 +- docs/rules/prefer-array-find.md | 10 +- docs/rules/prefer-array-flat-map.md | 10 +- docs/rules/prefer-array-flat.md | 10 +- docs/rules/prefer-array-index-of.md | 10 +- docs/rules/prefer-array-some.md | 10 +- docs/rules/prefer-at.md | 8 +- docs/rules/prefer-code-point.md | 10 +- docs/rules/prefer-date-now.md | 10 +- docs/rules/prefer-default-parameters.md | 10 +- docs/rules/prefer-dom-node-append.md | 10 +- docs/rules/prefer-dom-node-dataset.md | 10 +- docs/rules/prefer-dom-node-remove.md | 10 +- docs/rules/prefer-dom-node-text-content.md | 10 +- docs/rules/prefer-event-target.md | 5 +- docs/rules/prefer-export-from.md | 10 +- docs/rules/prefer-includes.md | 10 +- docs/rules/prefer-json-parse-buffer.md | 8 +- docs/rules/prefer-keyboard-event-key.md | 10 +- .../prefer-logical-operator-over-ternary.md | 10 +- docs/rules/prefer-math-trunc.md | 10 +- docs/rules/prefer-modern-dom-apis.md | 10 +- docs/rules/prefer-modern-math-apis.md | 10 +- docs/rules/prefer-module.md | 10 +- .../rules/prefer-native-coercion-functions.md | 10 +- docs/rules/prefer-negative-index.md | 10 +- docs/rules/prefer-node-protocol.md | 10 +- docs/rules/prefer-number-properties.md | 10 +- docs/rules/prefer-object-from-entries.md | 10 +- docs/rules/prefer-optional-catch-binding.md | 10 +- docs/rules/prefer-prototype-methods.md | 10 +- docs/rules/prefer-query-selector.md | 10 +- docs/rules/prefer-reflect-apply.md | 10 +- docs/rules/prefer-regexp-test.md | 10 +- docs/rules/prefer-set-has.md | 10 +- docs/rules/prefer-spread.md | 10 +- docs/rules/prefer-string-replace-all.md | 8 +- docs/rules/prefer-string-slice.md | 10 +- docs/rules/prefer-string-starts-ends-with.md | 10 +- docs/rules/prefer-string-trim-start-end.md | 10 +- docs/rules/prefer-switch.md | 10 +- docs/rules/prefer-ternary.md | 10 +- docs/rules/prefer-top-level-await.md | 10 +- docs/rules/prefer-type-error.md | 10 +- docs/rules/prevent-abbreviations.md | 10 +- docs/rules/relative-url-style.md | 10 +- docs/rules/require-array-join-separator.md | 10 +- ...require-number-to-fixed-digits-argument.md | 10 +- .../require-post-message-target-origin.md | 8 +- docs/rules/string-content.md | 8 +- docs/rules/switch-case-braces.md | 10 +- docs/rules/template-indent.md | 10 +- docs/rules/text-encoding-identifier-case.md | 10 +- docs/rules/throw-new-error.md | 10 +- package.json | 7 +- readme.md | 234 +++++++++--------- scripts/create-rule.mjs | 6 +- scripts/generate-rule-notices.mjs | 19 -- scripts/generate-rules-table.mjs | 12 - scripts/rule-notices.mjs | 27 -- scripts/rules-table.mjs | 33 --- scripts/template/documentation.md.jst | 7 +- scripts/utils.mjs | 76 ------ test/package.mjs | 137 ---------- .../rule-description-to-document-title.mjs | 14 -- 117 files changed, 621 insertions(+), 949 deletions(-) delete mode 100644 scripts/generate-rule-notices.mjs delete mode 100644 scripts/generate-rules-table.mjs delete mode 100644 scripts/rule-notices.mjs delete mode 100644 scripts/rules-table.mjs delete mode 100644 scripts/utils.mjs delete mode 100644 test/utils/rule-description-to-document-title.mjs diff --git a/docs/rules/better-regex.md b/docs/rules/better-regex.md index a57f03f0e0..163b8e912c 100644 --- a/docs/rules/better-regex.md +++ b/docs/rules/better-regex.md @@ -1,11 +1,11 @@ # Improve regexes by making them shorter, consistent, and safer - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Note: This rule uses [`regexp-tree`](https://github.com/DmitrySoshnikov/regexp-tree) and [`clean-regexp`](https://github.com/samverschueren/clean-regexp) under the hood. diff --git a/docs/rules/catch-error-name.md b/docs/rules/catch-error-name.md index 7e5a1f198f..5de7904f5c 100644 --- a/docs/rules/catch-error-name.md +++ b/docs/rules/catch-error-name.md @@ -1,11 +1,11 @@ # Enforce a specific parameter name in catch clauses - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Applies to diff --git a/docs/rules/consistent-destructuring.md b/docs/rules/consistent-destructuring.md index 6a655fe9e0..7ab30f05a3 100644 --- a/docs/rules/consistent-destructuring.md +++ b/docs/rules/consistent-destructuring.md @@ -1,11 +1,11 @@ # Use destructured variables over properties - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Enforces the use of already destructured objects and their variables over accessing each property individually. Previous destructurings are easily missed which leads to an inconsistent code style. diff --git a/docs/rules/consistent-function-scoping.md b/docs/rules/consistent-function-scoping.md index 4cd85b135a..2a6e2dc6ea 100644 --- a/docs/rules/consistent-function-scoping.md +++ b/docs/rules/consistent-function-scoping.md @@ -1,9 +1,9 @@ # Move function definitions to the highest possible scope - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + A function definition should be placed as close to the top-level scope as possible without breaking its captured values. This improves readability, [directly improves performance](https://stackoverflow.com/a/81329/207247) and allows JavaScript engines to [better optimize performance](https://ponyfoo.com/articles/javascript-performance-pitfalls-v8#optimization-limit). diff --git a/docs/rules/custom-error-definition.md b/docs/rules/custom-error-definition.md index 1e99612122..caf66de183 100644 --- a/docs/rules/custom-error-definition.md +++ b/docs/rules/custom-error-definition.md @@ -1,9 +1,9 @@ # Enforce correct `Error` subclassing - - -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Enforces the only valid way of `Error` subclassing. It works with any super class that ends in `Error`. diff --git a/docs/rules/empty-brace-spaces.md b/docs/rules/empty-brace-spaces.md index 7f1b38a99e..ce573d85e3 100644 --- a/docs/rules/empty-brace-spaces.md +++ b/docs/rules/empty-brace-spaces.md @@ -1,11 +1,11 @@ # Enforce no spaces between braces - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + ## Fail diff --git a/docs/rules/error-message.md b/docs/rules/error-message.md index 5170c16953..ad1b873def 100644 --- a/docs/rules/error-message.md +++ b/docs/rules/error-message.md @@ -1,9 +1,9 @@ # Enforce passing a `message` value when creating a built-in error - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + This rule enforces a `message` value to be passed in when creating an instance of a built-in [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object, which leads to more readable and debuggable code. diff --git a/docs/rules/escape-case.md b/docs/rules/escape-case.md index bd9dbee229..2da5ebf693 100644 --- a/docs/rules/escape-case.md +++ b/docs/rules/escape-case.md @@ -1,11 +1,11 @@ # Require escape sequences to use uppercase values - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Enforces defining escape sequence values with uppercase characters rather than lowercase ones. This promotes readability by making the escaped value more distinguishable from the identifier. diff --git a/docs/rules/expiring-todo-comments.md b/docs/rules/expiring-todo-comments.md index 0a83d45b3e..18430df952 100644 --- a/docs/rules/expiring-todo-comments.md +++ b/docs/rules/expiring-todo-comments.md @@ -1,9 +1,9 @@ # Add expiration conditions to TODO comments - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + This rule makes it possible to pass arguments to TODO, FIXME and XXX comments to trigger ESLint to report. diff --git a/docs/rules/explicit-length-check.md b/docs/rules/explicit-length-check.md index b4d6b61747..10db789383 100644 --- a/docs/rules/explicit-length-check.md +++ b/docs/rules/explicit-length-check.md @@ -1,11 +1,11 @@ # Enforce explicitly comparing the `length` or `size` property of a value - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Enforce explicitly checking the length of an object and enforce the comparison style. diff --git a/docs/rules/filename-case.md b/docs/rules/filename-case.md index fa598df50c..c65f572c63 100644 --- a/docs/rules/filename-case.md +++ b/docs/rules/filename-case.md @@ -1,9 +1,9 @@ # Enforce a case style for filenames - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + Enforces all linted files to have their names in a certain case style and lowercase file extension. The default is `kebabCase`. diff --git a/docs/rules/import-style.md b/docs/rules/import-style.md index 9b592acaa4..04fecad5f6 100644 --- a/docs/rules/import-style.md +++ b/docs/rules/import-style.md @@ -1,9 +1,9 @@ # Enforce specific import styles per module - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + Sometimes a module contains unrelated functions, like `util`, thus it is a good practice to enforce destructuring or named imports here. Other times, in modules like `path`, it is good to use default import as they have similar functions, all likely to be utilized. diff --git a/docs/rules/new-for-builtins.md b/docs/rules/new-for-builtins.md index 4a037b43c3..b66ff69a83 100644 --- a/docs/rules/new-for-builtins.md +++ b/docs/rules/new-for-builtins.md @@ -1,11 +1,11 @@ # Enforce the use of `new` for all builtins, except `String`, `Number`, `Boolean`, `Symbol` and `BigInt` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + They work the same, but `new` should be preferred for consistency with other constructors. diff --git a/docs/rules/no-abusive-eslint-disable.md b/docs/rules/no-abusive-eslint-disable.md index c5af1d6fe0..69b14daf77 100644 --- a/docs/rules/no-abusive-eslint-disable.md +++ b/docs/rules/no-abusive-eslint-disable.md @@ -1,9 +1,9 @@ # Enforce specifying rules to disable in `eslint-disable` comments - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + This rule makes you specify the rules you want to disable when using `eslint-disable`, `eslint-disable-line` or `eslint-disable-next-line` comments. diff --git a/docs/rules/no-array-callback-reference.md b/docs/rules/no-array-callback-reference.md index f943d1bf4e..3372c5cf13 100644 --- a/docs/rules/no-array-callback-reference.md +++ b/docs/rules/no-array-callback-reference.md @@ -1,11 +1,11 @@ # Prevent passing a function reference directly to iterator methods - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ’‘ *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ’‘ This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Suppose you have a `unicorn` module: diff --git a/docs/rules/no-array-for-each.md b/docs/rules/no-array-for-each.md index 36f56eaac4..3380cc220d 100644 --- a/docs/rules/no-array-for-each.md +++ b/docs/rules/no-array-for-each.md @@ -1,11 +1,11 @@ # Prefer `for…of` over the `forEach` method - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Benefits of [`for…of` statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) over the `forEach` method can include: diff --git a/docs/rules/no-array-method-this-argument.md b/docs/rules/no-array-method-this-argument.md index f3e3ac7b2f..0d70781bca 100644 --- a/docs/rules/no-array-method-this-argument.md +++ b/docs/rules/no-array-method-this-argument.md @@ -1,11 +1,11 @@ # Disallow using the `this` argument in array methods - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + The rule disallows using the `thisArg` argument in array methods: diff --git a/docs/rules/no-array-push-push.md b/docs/rules/no-array-push-push.md index 4229a4ae66..aed71f436e 100644 --- a/docs/rules/no-array-push-push.md +++ b/docs/rules/no-array-push-push.md @@ -1,11 +1,11 @@ # Enforce combining multiple `Array#push()` into one call - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + [`Array#push()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) accepts multiple arguments. Multiple calls should be combined into one. diff --git a/docs/rules/no-array-reduce.md b/docs/rules/no-array-reduce.md index 0548866ffe..6b2144606a 100644 --- a/docs/rules/no-array-reduce.md +++ b/docs/rules/no-array-reduce.md @@ -1,9 +1,9 @@ # Disallow `Array#reduce()` and `Array#reduceRight()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + `Array#reduce()` and `Array#reduceRight()` usually result in [hard-to-read](https://twitter.com/jaffathecake/status/1213077702300852224) and [less performant](https://www.richsnapp.com/article/2019/06-09-reduce-spread-anti-pattern) code. In almost every case, it can be replaced by `.map`, `.filter`, or a `for-of` loop. diff --git a/docs/rules/no-await-expression-member.md b/docs/rules/no-await-expression-member.md index cb6e422afe..71920eb368 100644 --- a/docs/rules/no-await-expression-member.md +++ b/docs/rules/no-await-expression-member.md @@ -1,11 +1,11 @@ # Disallow member access from await expression - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + When accessing a member from an await expression, the await expression has to be parenthesized, which is not readable. diff --git a/docs/rules/no-console-spaces.md b/docs/rules/no-console-spaces.md index 40d515ce4c..7ee50b53df 100644 --- a/docs/rules/no-console-spaces.md +++ b/docs/rules/no-console-spaces.md @@ -1,11 +1,11 @@ # Do not use leading/trailing space between `console.log` parameters - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + The [`console.log()` method](https://developer.mozilla.org/en-US/docs/Web/API/Console/log) and similar methods joins the parameters with a space, so adding a leading/trailing space to a parameter, results in two spaces being added. diff --git a/docs/rules/no-document-cookie.md b/docs/rules/no-document-cookie.md index f5a74966f4..a68cd4e7e0 100644 --- a/docs/rules/no-document-cookie.md +++ b/docs/rules/no-document-cookie.md @@ -1,9 +1,9 @@ # Do not use `document.cookie` directly - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + It's not recommended to use [`document.cookie`](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie) directly as it's easy to get the string wrong. Instead, you should use the [Cookie Store API](https://developer.mozilla.org/en-US/docs/Web/API/Cookie_Store_API) or a [cookie library](https://www.npmjs.com/search?q=cookie). diff --git a/docs/rules/no-empty-file.md b/docs/rules/no-empty-file.md index 4e788d7cdf..5753e1e832 100644 --- a/docs/rules/no-empty-file.md +++ b/docs/rules/no-empty-file.md @@ -1,9 +1,9 @@ # Disallow empty files - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + Meaningless files clutter a codebase. diff --git a/docs/rules/no-for-loop.md b/docs/rules/no-for-loop.md index a15d1e4884..ea2ba58820 100644 --- a/docs/rules/no-for-loop.md +++ b/docs/rules/no-for-loop.md @@ -1,11 +1,11 @@ # Do not use a `for` loop that can be replaced with a `for-of` loop - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + There's no reason to use old school for loops anymore for the common case. You can instead use for-of loop (with `.entries()` if you need to access the index). diff --git a/docs/rules/no-hex-escape.md b/docs/rules/no-hex-escape.md index 03aea3d007..e8b93f4b19 100644 --- a/docs/rules/no-hex-escape.md +++ b/docs/rules/no-hex-escape.md @@ -1,11 +1,11 @@ # Enforce the use of Unicode escapes instead of hexadecimal escapes - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Enforces a convention of using [Unicode escapes](https://mathiasbynens.be/notes/javascript-escapes#unicode) instead of [hexadecimal escapes](https://mathiasbynens.be/notes/javascript-escapes#hexadecimal) for consistency and clarity. diff --git a/docs/rules/no-instanceof-array.md b/docs/rules/no-instanceof-array.md index 4f0855ae94..21e57ca552 100644 --- a/docs/rules/no-instanceof-array.md +++ b/docs/rules/no-instanceof-array.md @@ -1,11 +1,11 @@ # Require `Array.isArray()` instead of `instanceof Array` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + The `instanceof Array` check doesn't work across realms/contexts, for example, frames/windows in browsers or the `vm` module in Node.js. diff --git a/docs/rules/no-invalid-remove-event-listener.md b/docs/rules/no-invalid-remove-event-listener.md index a8cfa13828..468eacc140 100644 --- a/docs/rules/no-invalid-remove-event-listener.md +++ b/docs/rules/no-invalid-remove-event-listener.md @@ -1,9 +1,9 @@ # Prevent calling `EventTarget#removeEventListener()` with the result of an expression - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + The [`removeEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener) function must be called with a reference to the same function that was passed to [`addEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener). Calling `removeEventListener` with an inline function or the result of an inline `.bind()` call is indicative of an error, and won't actually remove the listener. diff --git a/docs/rules/no-keyword-prefix.md b/docs/rules/no-keyword-prefix.md index 38e8880e7b..a7542e8d94 100644 --- a/docs/rules/no-keyword-prefix.md +++ b/docs/rules/no-keyword-prefix.md @@ -1,8 +1,7 @@ # Disallow identifiers starting with `new` or `class` - - - + + `new Foo` and `newFoo` look very similar. Use alternatives that do not look like keyword usage. diff --git a/docs/rules/no-lonely-if.md b/docs/rules/no-lonely-if.md index cce9f803cf..ee00f11d30 100644 --- a/docs/rules/no-lonely-if.md +++ b/docs/rules/no-lonely-if.md @@ -1,11 +1,11 @@ # Disallow `if` statements as the only statement in `if` blocks without `else` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + This rule adds onto the built-in [`no-lonely-if`](https://eslint.org/docs/rules/no-lonely-if) rule, which only disallows `if` statements in `else`, not in `if`. It is recommended to use `unicorn/no-lonely-if` together with the core ESLint `no-lonely-if` rule. diff --git a/docs/rules/no-nested-ternary.md b/docs/rules/no-nested-ternary.md index 9dcef9339e..d5ef816c25 100644 --- a/docs/rules/no-nested-ternary.md +++ b/docs/rules/no-nested-ternary.md @@ -1,11 +1,11 @@ # Disallow nested ternary expressions - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Improved version of the [`no-nested-ternary`](https://eslint.org/docs/rules/no-nested-ternary) ESLint rule, which allows cases where the nested ternary is only one level and wrapped in parens. diff --git a/docs/rules/no-new-array.md b/docs/rules/no-new-array.md index d45574e14d..b95d626a60 100644 --- a/docs/rules/no-new-array.md +++ b/docs/rules/no-new-array.md @@ -1,11 +1,11 @@ # Disallow `new Array()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + The ESLint built-in rule [`no-array-constructor`](https://eslint.org/docs/rules/no-array-constructor) enforces using an array literal instead of the `Array` constructor, but it still allows using the `Array` constructor with **one** argument. This rule fills that gap. diff --git a/docs/rules/no-new-buffer.md b/docs/rules/no-new-buffer.md index 2c1d2237b5..ab2172e150 100644 --- a/docs/rules/no-new-buffer.md +++ b/docs/rules/no-new-buffer.md @@ -1,11 +1,11 @@ # Enforce the use of `Buffer.from()` and `Buffer.alloc()` instead of the deprecated `new Buffer()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Enforces the use of [Buffer.from](https://nodejs.org/api/buffer.html#static-method-bufferfromarray) and [Buffer.alloc()](https://nodejs.org/api/buffer.html#static-method-bufferallocsize-fill-encoding) instead of [new Buffer()](https://nodejs.org/api/buffer.html#new-bufferarray), which has been deprecated since Node.js 4. diff --git a/docs/rules/no-null.md b/docs/rules/no-null.md index 469ced4ffe..28cf150275 100644 --- a/docs/rules/no-null.md +++ b/docs/rules/no-null.md @@ -1,11 +1,11 @@ # Disallow the use of the `null` literal - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Disallow the use of the `null` literal, to encourage using `undefined` instead. diff --git a/docs/rules/no-object-as-default-parameter.md b/docs/rules/no-object-as-default-parameter.md index 88f65798fd..dc70d6b601 100644 --- a/docs/rules/no-object-as-default-parameter.md +++ b/docs/rules/no-object-as-default-parameter.md @@ -1,9 +1,9 @@ # Disallow the use of objects as default parameters - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + Default parameters should not be passed to a function through an object literal. The `foo = {a: false}` parameter works fine if only used with one option. As soon as additional options are added, you risk replacing the whole `foo = {a: false, b: true}` object when passing only one option: `{a: true}`. For this reason, object destructuring should be used instead. diff --git a/docs/rules/no-process-exit.md b/docs/rules/no-process-exit.md index 3f5a8716fa..ab399d8330 100644 --- a/docs/rules/no-process-exit.md +++ b/docs/rules/no-process-exit.md @@ -1,9 +1,9 @@ # Disallow `process.exit()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + This rule is an extension to ESLint's [`no-process-exit` rule](https://eslint.org/docs/rules/no-process-exit), that allows `process.exit()` to be called in files that start with a [hashbang](https://en.wikipedia.org/wiki/Shebang_(Unix)) β†’ `#!/usr/bin/env node`. It also allows `process.exit()` to be called in `process.on('', func)` event handlers and in files that imports `worker_threads`. diff --git a/docs/rules/no-static-only-class.md b/docs/rules/no-static-only-class.md index 359bcad878..67969f0b9a 100644 --- a/docs/rules/no-static-only-class.md +++ b/docs/rules/no-static-only-class.md @@ -1,11 +1,11 @@ # Disallow classes that only have static members - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + A class with only static members could just be an object instead. diff --git a/docs/rules/no-thenable.md b/docs/rules/no-thenable.md index dce99cc3bd..503d5305a0 100644 --- a/docs/rules/no-thenable.md +++ b/docs/rules/no-thenable.md @@ -1,9 +1,9 @@ # Disallow `then` property - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + If an object is defined as "thenable", once it's accidentally used in an await expression, it may cause problems: diff --git a/docs/rules/no-this-assignment.md b/docs/rules/no-this-assignment.md index 7ea94ed66b..c10c6b38f6 100644 --- a/docs/rules/no-this-assignment.md +++ b/docs/rules/no-this-assignment.md @@ -1,9 +1,9 @@ # Disallow assigning `this` to a variable - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + `this` should be used directly. If you want a reference to `this` from a higher scope, consider using [arrow function expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) or [`Function#bind()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind). diff --git a/docs/rules/no-unnecessary-await.md b/docs/rules/no-unnecessary-await.md index 5974107e67..d68b204b52 100644 --- a/docs/rules/no-unnecessary-await.md +++ b/docs/rules/no-unnecessary-await.md @@ -1,11 +1,11 @@ # Disallow awaiting non-promise values - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + The [`await` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await) should only be used on [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) values. diff --git a/docs/rules/no-unreadable-array-destructuring.md b/docs/rules/no-unreadable-array-destructuring.md index e9456a8f84..6b277dbff2 100644 --- a/docs/rules/no-unreadable-array-destructuring.md +++ b/docs/rules/no-unreadable-array-destructuring.md @@ -1,11 +1,11 @@ # Disallow unreadable array destructuring - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Destructuring is very useful, but it can also make some code harder to read. This rule prevents ignoring consecutive values when destructuring from an array. diff --git a/docs/rules/no-unreadable-iife.md b/docs/rules/no-unreadable-iife.md index 621d22c89a..513b966c9d 100644 --- a/docs/rules/no-unreadable-iife.md +++ b/docs/rules/no-unreadable-iife.md @@ -1,9 +1,9 @@ # Disallow unreadable IIFEs - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* - +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). + + + [IIFE](https://en.wikipedia.org/wiki/Immediately_invoked_function_expression) with parenthesized arrow function body is considered unreadable. diff --git a/docs/rules/no-unsafe-regex.md b/docs/rules/no-unsafe-regex.md index afa546165b..aff8ac9f9b 100644 --- a/docs/rules/no-unsafe-regex.md +++ b/docs/rules/no-unsafe-regex.md @@ -1,8 +1,7 @@ # Disallow unsafe regular expressions - - - + + Uses [safe-regex](https://github.com/substack/safe-regex) to disallow potentially [catastrophic](https://regular-expressions.info/catastrophic.html) [exponential-time](https://perlgeek.de/blog-en/perl-tips/in-search-of-an-exponetial-regexp.html) regular expressions. diff --git a/docs/rules/no-unused-properties.md b/docs/rules/no-unused-properties.md index f3b6e40bce..8991309121 100644 --- a/docs/rules/no-unused-properties.md +++ b/docs/rules/no-unused-properties.md @@ -1,8 +1,7 @@ # Disallow unused object properties - - - + + Unused properties, much like unused variables, are often a result of incomplete refactoring and may confuse readers. diff --git a/docs/rules/no-useless-fallback-in-spread.md b/docs/rules/no-useless-fallback-in-spread.md index d408194c4e..ce30d2725e 100644 --- a/docs/rules/no-useless-fallback-in-spread.md +++ b/docs/rules/no-useless-fallback-in-spread.md @@ -1,11 +1,11 @@ # Disallow useless fallback when spreading in object literals - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Spreading [falsy values](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) in object literals won't add any unexpected properties, so it's unnecessary to add an empty object as fallback. diff --git a/docs/rules/no-useless-length-check.md b/docs/rules/no-useless-length-check.md index d248087968..29b168aebe 100644 --- a/docs/rules/no-useless-length-check.md +++ b/docs/rules/no-useless-length-check.md @@ -1,11 +1,11 @@ # Disallow useless array length check - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + - `Array#some()` returns `false` for an empty array. There is no need to check if the array is not empty. - `Array#every()` returns `true` for an empty array. There is no need to check if the array is empty. diff --git a/docs/rules/no-useless-promise-resolve-reject.md b/docs/rules/no-useless-promise-resolve-reject.md index a6e438e5fb..38f37220d1 100644 --- a/docs/rules/no-useless-promise-resolve-reject.md +++ b/docs/rules/no-useless-promise-resolve-reject.md @@ -1,11 +1,11 @@ # Disallow returning/yielding `Promise.resolve/reject()` in async functions or promise callbacks - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Wrapping a return value in `Promise.resolve` in an async function or a `Promise#then`/`catch`/`finally` callback is unnecessary as all return values in async functions and promise callback functions are already wrapped in a `Promise`. Similarly, returning an error wrapped in `Promise.reject` is equivalent to simply `throw`ing the error. This is the same for `yield`ing in async generators as well. diff --git a/docs/rules/no-useless-spread.md b/docs/rules/no-useless-spread.md index fc864bb662..11617e7a53 100644 --- a/docs/rules/no-useless-spread.md +++ b/docs/rules/no-useless-spread.md @@ -1,11 +1,11 @@ # Disallow unnecessary spread - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + - Using spread syntax in the following cases is unnecessary: diff --git a/docs/rules/no-useless-switch-case.md b/docs/rules/no-useless-switch-case.md index c2fdc9959c..9f095b21d5 100644 --- a/docs/rules/no-useless-switch-case.md +++ b/docs/rules/no-useless-switch-case.md @@ -1,11 +1,11 @@ # Disallow useless case in switch statements - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ’‘ *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ’‘ This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + An empty case before the last default case is useless. diff --git a/docs/rules/no-useless-undefined.md b/docs/rules/no-useless-undefined.md index 4dc3022691..6daea32390 100644 --- a/docs/rules/no-useless-undefined.md +++ b/docs/rules/no-useless-undefined.md @@ -1,11 +1,11 @@ # Disallow useless `undefined` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + ## Fail diff --git a/docs/rules/no-zero-fractions.md b/docs/rules/no-zero-fractions.md index 49b5f28b07..4363958940 100644 --- a/docs/rules/no-zero-fractions.md +++ b/docs/rules/no-zero-fractions.md @@ -1,11 +1,11 @@ # Disallow number literals with zero fractions or dangling dots - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + There is no difference in JavaScript between, for example, `1`, `1.0` and `1.`, so prefer the former for consistency. diff --git a/docs/rules/number-literal-case.md b/docs/rules/number-literal-case.md index 4af4962bda..862decf20e 100644 --- a/docs/rules/number-literal-case.md +++ b/docs/rules/number-literal-case.md @@ -1,11 +1,11 @@ # Enforce proper case for numeric literals - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Differentiating the casing of the identifier and value clearly separates them and makes your code more readable. diff --git a/docs/rules/numeric-separators-style.md b/docs/rules/numeric-separators-style.md index 8d9c4af4f6..6740c5ff80 100644 --- a/docs/rules/numeric-separators-style.md +++ b/docs/rules/numeric-separators-style.md @@ -1,11 +1,11 @@ # Enforce the style of numeric separators by correctly grouping digits - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Enforces a convention of grouping digits using [numeric separators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Numeric_separators). Long numbers can become really hard to read, so cutting it into groups of digits, separated with a `_`, is important to keep your code clear. This rule also enforces a proper usage of the numeric separator, by checking if the groups of digits are of the correct size. diff --git a/docs/rules/prefer-add-event-listener.md b/docs/rules/prefer-add-event-listener.md index d5f45cb50f..28da1ff89f 100644 --- a/docs/rules/prefer-add-event-listener.md +++ b/docs/rules/prefer-add-event-listener.md @@ -1,11 +1,11 @@ # Prefer `.addEventListener()` and `.removeEventListener()` over `on`-functions - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Enforces the use of `.addEventListener()` and `.removeEventListener()` over their `on`-function counterparts. For example, `foo.addEventListener('click', handler);` is preferred over `foo.onclick = handler;` for HTML DOM Events. There are [numerous advantages of using `addEventListener`](https://stackoverflow.com/questions/6348494/addeventlistener-vs-onclick/35093997#35093997). Some of these advantages include registering unlimited event handlers and optionally having the event handler invoked only once. diff --git a/docs/rules/prefer-array-find.md b/docs/rules/prefer-array-find.md index 809935548a..b36fe7c582 100644 --- a/docs/rules/prefer-array-find.md +++ b/docs/rules/prefer-array-find.md @@ -1,11 +1,11 @@ # Prefer `.find(…)` and `.findLast(…)` over the first or last element from `.filter(…)` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) and [`Array#findLast()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) breaks the loop as soon as it finds a match and doesn't create a new array. diff --git a/docs/rules/prefer-array-flat-map.md b/docs/rules/prefer-array-flat-map.md index 3edfd68730..b9070301af 100644 --- a/docs/rules/prefer-array-flat-map.md +++ b/docs/rules/prefer-array-flat-map.md @@ -1,11 +1,11 @@ # Prefer `.flatMap(…)` over `.map(…).flat()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + [`Array#flatMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) performs [`Array#map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) and [`Array#flat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) in one step. diff --git a/docs/rules/prefer-array-flat.md b/docs/rules/prefer-array-flat.md index e2e45aecf9..32fbeb03fa 100644 --- a/docs/rules/prefer-array-flat.md +++ b/docs/rules/prefer-array-flat.md @@ -1,11 +1,11 @@ # Prefer `Array#flat()` over legacy techniques to flatten arrays - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + ES2019 introduced a new method [`Array#flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) that flatten arrays. diff --git a/docs/rules/prefer-array-index-of.md b/docs/rules/prefer-array-index-of.md index bfc44271c1..b580247631 100644 --- a/docs/rules/prefer-array-index-of.md +++ b/docs/rules/prefer-array-index-of.md @@ -1,11 +1,11 @@ # Prefer `Array#{indexOf,lastIndexOf}()` over `Array#{findIndex,findLastIndex}()` when looking for the index of an item - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + [`Array#findIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) and [`Array#findLastIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) are intended for more complex needs. If you are just looking for the index where the given item is present, then the code can be simplified to use [`Array#indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) or [`Array#lastIndexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf) . This applies to any search with a literal, a variable, or any expression that doesn't have any explicit side effects. However, if the expression you are looking for relies on an item related to the function (its arguments, the function self, etc.), the case is still valid. diff --git a/docs/rules/prefer-array-some.md b/docs/rules/prefer-array-some.md index 3501176b88..96e256936c 100644 --- a/docs/rules/prefer-array-some.md +++ b/docs/rules/prefer-array-some.md @@ -1,11 +1,11 @@ # Prefer `.some(…)` over `.filter(…).length` check and `.{find,findLast}(…)` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Prefer using [`Array#some`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) over: diff --git a/docs/rules/prefer-at.md b/docs/rules/prefer-at.md index bb22e96797..955a01ee7f 100644 --- a/docs/rules/prefer-at.md +++ b/docs/rules/prefer-at.md @@ -1,9 +1,9 @@ # Prefer `.at()` method for index access and `String#charAt()` - - -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Prefer [`Array#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at), [`String#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at), and `{TypedArray,NodeList,CSSRuleList,…}#at()` for index access and `String#charAt()`. diff --git a/docs/rules/prefer-code-point.md b/docs/rules/prefer-code-point.md index 7978aad34b..6e27dd719a 100644 --- a/docs/rules/prefer-code-point.md +++ b/docs/rules/prefer-code-point.md @@ -1,11 +1,11 @@ # Prefer `String#codePointAt(…)` over `String#charCodeAt(…)` and `String.fromCodePoint(…)` over `String.fromCharCode(…)` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ’‘ *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ’‘ This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Unicode is better supported in [`String#codePointAt()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt) and [`String.fromCodePoint()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint). diff --git a/docs/rules/prefer-date-now.md b/docs/rules/prefer-date-now.md index 6398953dd7..f235ac56c3 100644 --- a/docs/rules/prefer-date-now.md +++ b/docs/rules/prefer-date-now.md @@ -1,11 +1,11 @@ # Prefer `Date.now()` to get the number of milliseconds since the Unix Epoch - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + [`Date.now()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now) is shorter and nicer than [`new Date().getTime()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime), and avoids unnecessary instantiation of `Date` objects. diff --git a/docs/rules/prefer-default-parameters.md b/docs/rules/prefer-default-parameters.md index 82eb746c56..d72b52fd49 100644 --- a/docs/rules/prefer-default-parameters.md +++ b/docs/rules/prefer-default-parameters.md @@ -1,11 +1,11 @@ # Prefer default parameters over reassignment - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Instead of reassigning a function parameter, default parameters should be used. The `foo = foo || 123` statement evaluates to `123` when `foo` is falsy, possibly leading to confusing behavior, whereas default parameters only apply when passed an `undefined` value. This rule only reports reassignments to literal values. diff --git a/docs/rules/prefer-dom-node-append.md b/docs/rules/prefer-dom-node-append.md index 21762c21a6..779174f5c8 100644 --- a/docs/rules/prefer-dom-node-append.md +++ b/docs/rules/prefer-dom-node-append.md @@ -1,11 +1,11 @@ # Prefer `Node#append()` over `Node#appendChild()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Enforces the use of, for example, `document.body.append(div);` over `document.body.appendChild(div);` for DOM nodes. There are [some advantages of using `Node#append()`](https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append), like the ability to append multiple nodes and to append both [`DOMString`](https://developer.mozilla.org/en-US/docs/Web/API/DOMString) and DOM node objects. diff --git a/docs/rules/prefer-dom-node-dataset.md b/docs/rules/prefer-dom-node-dataset.md index 3ad9f5e0e4..0ff0b753a7 100644 --- a/docs/rules/prefer-dom-node-dataset.md +++ b/docs/rules/prefer-dom-node-dataset.md @@ -1,11 +1,11 @@ # Prefer using `.dataset` on DOM elements over calling attribute methods - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Use [`.dataset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) on DOM elements over `getAttribute(…)`, `.setAttribute(…)`, `.removeAttribute(…)` and `.hasAttribute(…)`. diff --git a/docs/rules/prefer-dom-node-remove.md b/docs/rules/prefer-dom-node-remove.md index 4a3eeae40c..f33fb6b76f 100644 --- a/docs/rules/prefer-dom-node-remove.md +++ b/docs/rules/prefer-dom-node-remove.md @@ -1,11 +1,11 @@ # Prefer `childNode.remove()` over `parentNode.removeChild(childNode)` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Enforces the use of, for example, `child.remove();` over `child.parentNode.removeChild(child);`. The DOM function [`Node#remove()`](https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove) is preferred over the indirect removal of an object with [`Node#removeChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild). diff --git a/docs/rules/prefer-dom-node-text-content.md b/docs/rules/prefer-dom-node-text-content.md index 50a859ea80..79ed06539c 100644 --- a/docs/rules/prefer-dom-node-text-content.md +++ b/docs/rules/prefer-dom-node-text-content.md @@ -1,11 +1,11 @@ # Prefer `.textContent` over `.innerText` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ’‘ *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ’‘ This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Enforces the use of `.textContent` over `.innerText` for DOM nodes. diff --git a/docs/rules/prefer-event-target.md b/docs/rules/prefer-event-target.md index a8a7477990..7c2ec0fdba 100644 --- a/docs/rules/prefer-event-target.md +++ b/docs/rules/prefer-event-target.md @@ -1,8 +1,7 @@ # Prefer `EventTarget` over `EventEmitter` - - - + + While [`EventEmitter`](https://nodejs.org/api/events.html#class-eventemitter) is only available in Node.js, [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) is also available in *Deno* and browsers. diff --git a/docs/rules/prefer-export-from.md b/docs/rules/prefer-export-from.md index 86e2ab5132..78a9bd9f24 100644 --- a/docs/rules/prefer-export-from.md +++ b/docs/rules/prefer-export-from.md @@ -1,11 +1,11 @@ # Prefer `export…from` when re-exporting - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + When re-exporting from a module, it's unnecessary to import and then export. It can be done in a single `export…from` declaration. diff --git a/docs/rules/prefer-includes.md b/docs/rules/prefer-includes.md index 150102263f..b52907073b 100644 --- a/docs/rules/prefer-includes.md +++ b/docs/rules/prefer-includes.md @@ -1,11 +1,11 @@ # Prefer `.includes()` over `.indexOf()` and `Array#some()` when checking for existence or non-existence - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + All built-ins have `.includes()` in addition to `.indexOf()`. Prefer `.includes()` over comparing the value of `.indexOf()`. diff --git a/docs/rules/prefer-json-parse-buffer.md b/docs/rules/prefer-json-parse-buffer.md index 39e5dd38a9..f5d02ed8d3 100644 --- a/docs/rules/prefer-json-parse-buffer.md +++ b/docs/rules/prefer-json-parse-buffer.md @@ -1,9 +1,9 @@ # Prefer reading a JSON file as a buffer - - -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + When reading and parsing a JSON file, it's unnecessary to read it as a string, because [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) can also parse [`Buffer`](https://nodejs.org/api/buffer.html#buffer). diff --git a/docs/rules/prefer-keyboard-event-key.md b/docs/rules/prefer-keyboard-event-key.md index 0045b7cef2..57e4df90ae 100644 --- a/docs/rules/prefer-keyboard-event-key.md +++ b/docs/rules/prefer-keyboard-event-key.md @@ -1,11 +1,11 @@ # Prefer `KeyboardEvent#key` over `KeyboardEvent#keyCode` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Enforces the use of [`KeyboardEvent#key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) over [`KeyboardEvent#keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) which is deprecated. The `.key` property is also more semantic and readable. diff --git a/docs/rules/prefer-logical-operator-over-ternary.md b/docs/rules/prefer-logical-operator-over-ternary.md index e4efe87490..4cd9ca48c7 100644 --- a/docs/rules/prefer-logical-operator-over-ternary.md +++ b/docs/rules/prefer-logical-operator-over-ternary.md @@ -1,11 +1,11 @@ # Prefer using a logical operator over a ternary - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ’‘ *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ’‘ This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Disallow ternary operators when simpler logical operator alternatives exist. diff --git a/docs/rules/prefer-math-trunc.md b/docs/rules/prefer-math-trunc.md index 7d4ad7da41..4b9d81124e 100644 --- a/docs/rules/prefer-math-trunc.md +++ b/docs/rules/prefer-math-trunc.md @@ -1,11 +1,11 @@ # Enforce the use of `Math.trunc` instead of bitwise operators - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Enforces a convention of using [`Math.trunc()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc) instead of bitwise operations for clarity and more reliable results. It prevents the use of the following bitwise operations: diff --git a/docs/rules/prefer-modern-dom-apis.md b/docs/rules/prefer-modern-dom-apis.md index 2680d616ae..54a1b6fc3e 100644 --- a/docs/rules/prefer-modern-dom-apis.md +++ b/docs/rules/prefer-modern-dom-apis.md @@ -1,11 +1,11 @@ # Prefer `.before()` over `.insertBefore()`, `.replaceWith()` over `.replaceChild()`, prefer one of `.before()`, `.after()`, `.append()` or `.prepend()` over `insertAdjacentText()` and `insertAdjacentElement()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Enforces the use of: diff --git a/docs/rules/prefer-modern-math-apis.md b/docs/rules/prefer-modern-math-apis.md index 10f00645b0..2cd28410b0 100644 --- a/docs/rules/prefer-modern-math-apis.md +++ b/docs/rules/prefer-modern-math-apis.md @@ -1,11 +1,11 @@ # Prefer modern `Math` APIs over legacy patterns - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Math additions in ES2015: diff --git a/docs/rules/prefer-module.md b/docs/rules/prefer-module.md index fbf6c2972f..3ea4cb8c83 100644 --- a/docs/rules/prefer-module.md +++ b/docs/rules/prefer-module.md @@ -1,11 +1,11 @@ # Prefer JavaScript modules (ESM) over CommonJS - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Prefer using the [JavaScript module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) format over the legacy CommonJS module format. diff --git a/docs/rules/prefer-native-coercion-functions.md b/docs/rules/prefer-native-coercion-functions.md index 7ba6aab7e4..2ab0a7af39 100644 --- a/docs/rules/prefer-native-coercion-functions.md +++ b/docs/rules/prefer-native-coercion-functions.md @@ -1,11 +1,11 @@ # Prefer using `String`, `Number`, `BigInt`, `Boolean`, and `Symbol` directly - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + If a function is equivalent to [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt), [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean), or [`Symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), you should use the built-in one directly. Wrapping the built-in in a function is moot. diff --git a/docs/rules/prefer-negative-index.md b/docs/rules/prefer-negative-index.md index e2aab8b214..4456cc97a1 100644 --- a/docs/rules/prefer-negative-index.md +++ b/docs/rules/prefer-negative-index.md @@ -1,11 +1,11 @@ # Prefer negative index over `.length - index` for `{String,Array,TypedArray}#{slice,at}()` and `Array#splice()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Prefer negative index over calculating from `.length` for [`String#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice), [`Array#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice), [`TypedArray#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice), [`String#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at), [`Array#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at), [`TypedArray#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at), and [`Array#splice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) diff --git a/docs/rules/prefer-node-protocol.md b/docs/rules/prefer-node-protocol.md index 211f6a9c68..a8ea96f36d 100644 --- a/docs/rules/prefer-node-protocol.md +++ b/docs/rules/prefer-node-protocol.md @@ -1,11 +1,11 @@ # Prefer using the `node:` protocol when importing Node.js builtin modules - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + When importing builtin modules, it's better to use the [`node:` protocol](https://nodejs.org/api/esm.html#node-imports) as it makes it perfectly clear that the package is a Node.js builtin module. diff --git a/docs/rules/prefer-number-properties.md b/docs/rules/prefer-number-properties.md index c779a02bb0..1d900641d1 100644 --- a/docs/rules/prefer-number-properties.md +++ b/docs/rules/prefer-number-properties.md @@ -1,11 +1,11 @@ # Prefer `Number` static properties over global ones - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Enforces the use of: diff --git a/docs/rules/prefer-object-from-entries.md b/docs/rules/prefer-object-from-entries.md index 9928f398d1..1a25044048 100644 --- a/docs/rules/prefer-object-from-entries.md +++ b/docs/rules/prefer-object-from-entries.md @@ -1,11 +1,11 @@ # Prefer using `Object.fromEntries(…)` to transform a list of key-value pairs into an object - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + When transforming a list of key-value pairs into an object, [`Object.fromEntries(…)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries) should be preferred. diff --git a/docs/rules/prefer-optional-catch-binding.md b/docs/rules/prefer-optional-catch-binding.md index c47b7901af..6fb60635c6 100644 --- a/docs/rules/prefer-optional-catch-binding.md +++ b/docs/rules/prefer-optional-catch-binding.md @@ -1,11 +1,11 @@ # Prefer omitting the `catch` binding parameter - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + If the `catch` binding parameter is not used, it should be omitted. diff --git a/docs/rules/prefer-prototype-methods.md b/docs/rules/prefer-prototype-methods.md index 7c9f518525..24890b97d9 100644 --- a/docs/rules/prefer-prototype-methods.md +++ b/docs/rules/prefer-prototype-methods.md @@ -1,11 +1,11 @@ # Prefer borrowing methods from the prototype instead of the instance - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + When β€œborrowing” a method from `Array` or `Object`, it's clearer to get it from the prototype than from an instance. diff --git a/docs/rules/prefer-query-selector.md b/docs/rules/prefer-query-selector.md index 13ce2bd0bf..0bb2de83d0 100644 --- a/docs/rules/prefer-query-selector.md +++ b/docs/rules/prefer-query-selector.md @@ -1,11 +1,11 @@ # Prefer `.querySelector()` over `.getElementById()`, `.querySelectorAll()` over `.getElementsByClassName()` and `.getElementsByTagName()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + It's better to use the same method to query DOM elements. diff --git a/docs/rules/prefer-reflect-apply.md b/docs/rules/prefer-reflect-apply.md index 257348af22..a6c65aea8f 100644 --- a/docs/rules/prefer-reflect-apply.md +++ b/docs/rules/prefer-reflect-apply.md @@ -1,11 +1,11 @@ # Prefer `Reflect.apply()` over `Function#apply()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + [`Reflect.apply()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply) is arguably less verbose and easier to understand. In addition, when you accept arbitrary methods, it's not safe to assume `.apply()` exists or is not overridden. diff --git a/docs/rules/prefer-regexp-test.md b/docs/rules/prefer-regexp-test.md index 05cbf46ea1..1419216b1f 100644 --- a/docs/rules/prefer-regexp-test.md +++ b/docs/rules/prefer-regexp-test.md @@ -1,11 +1,11 @@ # Prefer `RegExp#test()` over `String#match()` and `RegExp#exec()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + When you want to know whether a pattern is found in a string, use [`RegExp#test()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test) instead of [`String#match()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) and [`RegExp#exec()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec). diff --git a/docs/rules/prefer-set-has.md b/docs/rules/prefer-set-has.md index bb0d217092..86c044346c 100644 --- a/docs/rules/prefer-set-has.md +++ b/docs/rules/prefer-set-has.md @@ -1,11 +1,11 @@ # Prefer `Set#has()` over `Array#includes()` when checking for existence or non-existence - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + [`Set#has()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has) is faster than [`Array#includes()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes). diff --git a/docs/rules/prefer-spread.md b/docs/rules/prefer-spread.md index 7b402b60fb..6c4962cc85 100644 --- a/docs/rules/prefer-spread.md +++ b/docs/rules/prefer-spread.md @@ -1,11 +1,11 @@ # Prefer the spread operator over `Array.from(…)`, `Array#concat(…)`, `Array#slice()` and `String#split('')` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Enforces the use of [the spread operator (`...`)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) over diff --git a/docs/rules/prefer-string-replace-all.md b/docs/rules/prefer-string-replace-all.md index 07b0f22c77..21f2f0837f 100644 --- a/docs/rules/prefer-string-replace-all.md +++ b/docs/rules/prefer-string-replace-all.md @@ -1,9 +1,9 @@ # Prefer `String#replaceAll()` over regex searches with the global flag - - -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + The [`String#replaceAll()`](https://github.com/tc39/proposal-string-replaceall) method is both faster and safer as you don't have to escape the regex if the string is not a literal. diff --git a/docs/rules/prefer-string-slice.md b/docs/rules/prefer-string-slice.md index bb58ddabc7..824ea9a578 100644 --- a/docs/rules/prefer-string-slice.md +++ b/docs/rules/prefer-string-slice.md @@ -1,11 +1,11 @@ # Prefer `String#slice()` over `String#substr()` and `String#substring()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + [`String#substr()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) and [`String#substring()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) are the two lesser known legacy ways to slice a string. It's better to use [`String#slice()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) as it's a more popular option with clearer behavior that has a consistent [`Array` counterpart](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice). diff --git a/docs/rules/prefer-string-starts-ends-with.md b/docs/rules/prefer-string-starts-ends-with.md index 874ad9fb9a..0fac79178f 100644 --- a/docs/rules/prefer-string-starts-ends-with.md +++ b/docs/rules/prefer-string-starts-ends-with.md @@ -1,11 +1,11 @@ # Prefer `String#startsWith()` & `String#endsWith()` over `RegExp#test()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Prefer [`String#startsWith()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) and [`String#endsWith()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith) over using a regex with `/^foo/` or `/foo$/`. diff --git a/docs/rules/prefer-string-trim-start-end.md b/docs/rules/prefer-string-trim-start-end.md index 1c76726f21..d406cf677c 100644 --- a/docs/rules/prefer-string-trim-start-end.md +++ b/docs/rules/prefer-string-trim-start-end.md @@ -1,11 +1,11 @@ # Prefer `String#trimStart()` / `String#trimEnd()` over `String#trimLeft()` / `String#trimRight()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + [`String#trimLeft()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimLeft) and [`String#trimRight()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimRight) are aliases of [`String#trimStart()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart) and [`String#trimEnd()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd) diff --git a/docs/rules/prefer-switch.md b/docs/rules/prefer-switch.md index 1147647f71..6092d7d4bb 100644 --- a/docs/rules/prefer-switch.md +++ b/docs/rules/prefer-switch.md @@ -1,11 +1,11 @@ # Prefer `switch` over multiple `else-if` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + A switch statement is easier to read than multiple if statements with simple equality comparisons. diff --git a/docs/rules/prefer-ternary.md b/docs/rules/prefer-ternary.md index 1a9238067c..3a31309833 100644 --- a/docs/rules/prefer-ternary.md +++ b/docs/rules/prefer-ternary.md @@ -1,11 +1,11 @@ # Prefer ternary expressions over simple `if-else` statements - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + This rule enforces the use of ternary expressions over 'simple' `if-else` statements, where 'simple' means the consequent and alternate are each one line and have the same basic type and form. diff --git a/docs/rules/prefer-top-level-await.md b/docs/rules/prefer-top-level-await.md index adb7ed096b..a08192c94e 100644 --- a/docs/rules/prefer-top-level-await.md +++ b/docs/rules/prefer-top-level-await.md @@ -1,11 +1,11 @@ # Prefer top-level await over top-level promises and async function calls - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ’‘ *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ’‘ This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + [Top-level await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#top_level_await) is more readable and can prevent unhandled rejections. diff --git a/docs/rules/prefer-type-error.md b/docs/rules/prefer-type-error.md index 92339bc6cb..bd25726a00 100644 --- a/docs/rules/prefer-type-error.md +++ b/docs/rules/prefer-type-error.md @@ -1,11 +1,11 @@ # Enforce throwing `TypeError` in type checking conditions - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + This rule enforces you to throw a `TypeError` after a type checking if-statement, instead of a generic `Error`. diff --git a/docs/rules/prevent-abbreviations.md b/docs/rules/prevent-abbreviations.md index ab3ffe398f..072a010db0 100644 --- a/docs/rules/prevent-abbreviations.md +++ b/docs/rules/prevent-abbreviations.md @@ -1,11 +1,11 @@ # Prevent abbreviations - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + Using complete words results in more readable code. Not everyone knows all your abbreviations. Code is written only once, but read many times. diff --git a/docs/rules/relative-url-style.md b/docs/rules/relative-url-style.md index 15abba27ec..900c011d5e 100644 --- a/docs/rules/relative-url-style.md +++ b/docs/rules/relative-url-style.md @@ -1,11 +1,11 @@ # Enforce consistent relative URL style - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + When using a relative URL in [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL), the URL should either never or always use the `./` prefix consistently. diff --git a/docs/rules/require-array-join-separator.md b/docs/rules/require-array-join-separator.md index 36b8a070c9..e445aa3b9e 100644 --- a/docs/rules/require-array-join-separator.md +++ b/docs/rules/require-array-join-separator.md @@ -1,11 +1,11 @@ # Enforce using the separator argument with `Array#join()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + It's better to make it clear what the separator is when calling [Array#join()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join), instead of relying on the default comma (`','`) separator. diff --git a/docs/rules/require-number-to-fixed-digits-argument.md b/docs/rules/require-number-to-fixed-digits-argument.md index 31cb1de370..9df5c6d4a3 100644 --- a/docs/rules/require-number-to-fixed-digits-argument.md +++ b/docs/rules/require-number-to-fixed-digits-argument.md @@ -1,11 +1,11 @@ # Enforce using the digits argument with `Number#toFixed()` - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + It's better to make it clear what the value of the `digits` argument is when calling [Number#toFixed()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed), instead of relying on the default value of `0`. diff --git a/docs/rules/require-post-message-target-origin.md b/docs/rules/require-post-message-target-origin.md index 9274c9c4f9..012da5c3e5 100644 --- a/docs/rules/require-post-message-target-origin.md +++ b/docs/rules/require-post-message-target-origin.md @@ -1,9 +1,9 @@ # Enforce using the `targetOrigin` argument with `window.postMessage()` - - -πŸ’‘ *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ’‘ This rule is manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + When calling [`window.postMessage()`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) without the `targetOrigin` argument, the message cannot be received by any window. diff --git a/docs/rules/string-content.md b/docs/rules/string-content.md index 5ff2f146c5..ffb681f634 100644 --- a/docs/rules/string-content.md +++ b/docs/rules/string-content.md @@ -1,9 +1,9 @@ # Enforce better string content - - -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + Enforce certain things about the contents of strings. For example, you can enforce using `’` instead of `'` to avoid escaping. Or you could block some words. The possibilities are endless. diff --git a/docs/rules/switch-case-braces.md b/docs/rules/switch-case-braces.md index 166fbef5d9..e895cf4c5d 100644 --- a/docs/rules/switch-case-braces.md +++ b/docs/rules/switch-case-braces.md @@ -1,11 +1,11 @@ # Enforce consistent brace style for `case` clauses - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + 1. Forbid braces for empty clauses. 1. Enforce braces for non-empty clauses. diff --git a/docs/rules/template-indent.md b/docs/rules/template-indent.md index ec12914722..dfd1dbeb17 100644 --- a/docs/rules/template-indent.md +++ b/docs/rules/template-indent.md @@ -1,11 +1,11 @@ # Fix whitespace-insensitive template indentation - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + [Tagged templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) often look ugly/jarring because their indentation doesn't match the code they're found in. In many cases, whitespace is insignificant, or a library like [strip-indent](https://www.npmjs.com/package/strip-indent) is used to remove the margin. See [proposal-string-dedent](https://github.com/tc39/proposal-string-dedent) (stage 1 at the time of writing) for a proposal on fixing this in JavaScript. diff --git a/docs/rules/text-encoding-identifier-case.md b/docs/rules/text-encoding-identifier-case.md index fc1d00ea64..ea1f03f27c 100644 --- a/docs/rules/text-encoding-identifier-case.md +++ b/docs/rules/text-encoding-identifier-case.md @@ -1,11 +1,11 @@ # Enforce consistent case for text encoding identifiers - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).* - +πŸ”§πŸ’‘ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + + + - Enforce `'utf8'` for [UTF-8](https://en.wikipedia.org/wiki/UTF-8) encoding. - Enforce `'ascii'` for [ASCII](https://en.wikipedia.org/wiki/ASCII) encoding. diff --git a/docs/rules/throw-new-error.md b/docs/rules/throw-new-error.md index f32804a137..9ee659af39 100644 --- a/docs/rules/throw-new-error.md +++ b/docs/rules/throw-new-error.md @@ -1,11 +1,11 @@ # Require `new` when throwing an error - - -βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* +βœ… This rule is enabled in the `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs). -πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* - +πŸ”§ This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + + While it's possible to create a new error without using the `new` keyword, it's better to be explicit. diff --git a/package.json b/package.json index 700dddcdad..9465cc573a 100644 --- a/package.json +++ b/package.json @@ -14,14 +14,14 @@ "node": ">=14.18" }, "scripts": { - "create-rule": "node ./scripts/create-rule.mjs && npm run generate-rule-notices && npm run generate-rules-table", + "create-rule": "node ./scripts/create-rule.mjs && npm run fix:eslint-docs", "fix": "run-p --continue-on-error fix:*", + "fix:eslint-docs": "eslint-doc-generator --ignore-deprecated-rules --ignore-config all --rule-doc-title-format desc --url-configs \"https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs\"", "fix:js": "npm run lint:js -- --fix", "fix:md": "npm run lint:md -- --fix", - "generate-rule-notices": "node ./scripts/generate-rule-notices.mjs", - "generate-rules-table": "node ./scripts/generate-rules-table.mjs", "integration": "node ./test/integration/test.mjs", "lint": "run-p --continue-on-error lint:*", + "lint:eslint-docs": "npm run fix:eslint-docs -- --check", "lint:js": "xo", "lint:md": "markdownlint \"**/*.md\"", "lint:package-json": "npmPkgJsonLint .", @@ -73,6 +73,7 @@ "enquirer": "^2.3.6", "eslint": "^8.23.1", "eslint-ava-rule-tester": "^4.0.0", + "eslint-doc-generator": "^0.13.0", "eslint-plugin-eslint-plugin": "^5.0.6", "eslint-plugin-internal-rules": "file:./scripts/internal-rules/", "eslint-remote-tester": "^3.0.0", diff --git a/readme.md b/readme.md index 57e1d9b24c..9c5ecd24de 100644 --- a/readme.md +++ b/readme.md @@ -43,123 +43,123 @@ Use a [preset config](#preset-configs) or configure each rules in `package.json` ## Rules -Each rule has emojis denoting: - -- βœ… if it belongs to the `recommended` configuration -- πŸ”§ if some problems reported by the rule are automatically fixable by the `--fix` [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) option -- πŸ’‘ if some problems reported by the rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions) - - - -| Name                                         | Description | βœ… | πŸ”§ | πŸ’‘ | -| :-- | :-- | :-- | :-- | :-- | -| [better-regex](docs/rules/better-regex.md) | Improve regexes by making them shorter, consistent, and safer. | βœ… | πŸ”§ | | -| [catch-error-name](docs/rules/catch-error-name.md) | Enforce a specific parameter name in catch clauses. | βœ… | πŸ”§ | | -| [consistent-destructuring](docs/rules/consistent-destructuring.md) | Use destructured variables over properties. | βœ… | πŸ”§ | πŸ’‘ | -| [consistent-function-scoping](docs/rules/consistent-function-scoping.md) | Move function definitions to the highest possible scope. | βœ… | | | -| [custom-error-definition](docs/rules/custom-error-definition.md) | Enforce correct `Error` subclassing. | | πŸ”§ | | -| [empty-brace-spaces](docs/rules/empty-brace-spaces.md) | Enforce no spaces between braces. | βœ… | πŸ”§ | | -| [error-message](docs/rules/error-message.md) | Enforce passing a `message` value when creating a built-in error. | βœ… | | | -| [escape-case](docs/rules/escape-case.md) | Require escape sequences to use uppercase values. | βœ… | πŸ”§ | | -| [expiring-todo-comments](docs/rules/expiring-todo-comments.md) | Add expiration conditions to TODO comments. | βœ… | | | -| [explicit-length-check](docs/rules/explicit-length-check.md) | Enforce explicitly comparing the `length` or `size` property of a value. | βœ… | πŸ”§ | πŸ’‘ | -| [filename-case](docs/rules/filename-case.md) | Enforce a case style for filenames. | βœ… | | | -| [import-style](docs/rules/import-style.md) | Enforce specific import styles per module. | βœ… | | | -| [new-for-builtins](docs/rules/new-for-builtins.md) | Enforce the use of `new` for all builtins, except `String`, `Number`, `Boolean`, `Symbol` and `BigInt`. | βœ… | πŸ”§ | | -| [no-abusive-eslint-disable](docs/rules/no-abusive-eslint-disable.md) | Enforce specifying rules to disable in `eslint-disable` comments. | βœ… | | | -| [no-array-callback-reference](docs/rules/no-array-callback-reference.md) | Prevent passing a function reference directly to iterator methods. | βœ… | | πŸ’‘ | -| [no-array-for-each](docs/rules/no-array-for-each.md) | Prefer `for…of` over the `forEach` method. | βœ… | πŸ”§ | πŸ’‘ | -| [no-array-method-this-argument](docs/rules/no-array-method-this-argument.md) | Disallow using the `this` argument in array methods. | βœ… | πŸ”§ | πŸ’‘ | -| [no-array-push-push](docs/rules/no-array-push-push.md) | Enforce combining multiple `Array#push()` into one call. | βœ… | πŸ”§ | πŸ’‘ | -| [no-array-reduce](docs/rules/no-array-reduce.md) | Disallow `Array#reduce()` and `Array#reduceRight()`. | βœ… | | | -| [no-await-expression-member](docs/rules/no-await-expression-member.md) | Disallow member access from await expression. | βœ… | πŸ”§ | | -| [no-console-spaces](docs/rules/no-console-spaces.md) | Do not use leading/trailing space between `console.log` parameters. | βœ… | πŸ”§ | | -| [no-document-cookie](docs/rules/no-document-cookie.md) | Do not use `document.cookie` directly. | βœ… | | | -| [no-empty-file](docs/rules/no-empty-file.md) | Disallow empty files. | βœ… | | | -| [no-for-loop](docs/rules/no-for-loop.md) | Do not use a `for` loop that can be replaced with a `for-of` loop. | βœ… | πŸ”§ | | -| [no-hex-escape](docs/rules/no-hex-escape.md) | Enforce the use of Unicode escapes instead of hexadecimal escapes. | βœ… | πŸ”§ | | -| [no-instanceof-array](docs/rules/no-instanceof-array.md) | Require `Array.isArray()` instead of `instanceof Array`. | βœ… | πŸ”§ | | -| [no-invalid-remove-event-listener](docs/rules/no-invalid-remove-event-listener.md) | Prevent calling `EventTarget#removeEventListener()` with the result of an expression. | βœ… | | | -| [no-keyword-prefix](docs/rules/no-keyword-prefix.md) | Disallow identifiers starting with `new` or `class`. | | | | -| [no-lonely-if](docs/rules/no-lonely-if.md) | Disallow `if` statements as the only statement in `if` blocks without `else`. | βœ… | πŸ”§ | | -| [no-nested-ternary](docs/rules/no-nested-ternary.md) | Disallow nested ternary expressions. | βœ… | πŸ”§ | | -| [no-new-array](docs/rules/no-new-array.md) | Disallow `new Array()`. | βœ… | πŸ”§ | πŸ’‘ | -| [no-new-buffer](docs/rules/no-new-buffer.md) | Enforce the use of `Buffer.from()` and `Buffer.alloc()` instead of the deprecated `new Buffer()`. | βœ… | πŸ”§ | πŸ’‘ | -| [no-null](docs/rules/no-null.md) | Disallow the use of the `null` literal. | βœ… | πŸ”§ | πŸ’‘ | -| [no-object-as-default-parameter](docs/rules/no-object-as-default-parameter.md) | Disallow the use of objects as default parameters. | βœ… | | | -| [no-process-exit](docs/rules/no-process-exit.md) | Disallow `process.exit()`. | βœ… | | | -| [no-static-only-class](docs/rules/no-static-only-class.md) | Disallow classes that only have static members. | βœ… | πŸ”§ | | -| [no-thenable](docs/rules/no-thenable.md) | Disallow `then` property. | βœ… | | | -| [no-this-assignment](docs/rules/no-this-assignment.md) | Disallow assigning `this` to a variable. | βœ… | | | -| [no-unnecessary-await](docs/rules/no-unnecessary-await.md) | Disallow awaiting non-promise values. | βœ… | πŸ”§ | | -| [no-unreadable-array-destructuring](docs/rules/no-unreadable-array-destructuring.md) | Disallow unreadable array destructuring. | βœ… | πŸ”§ | | -| [no-unreadable-iife](docs/rules/no-unreadable-iife.md) | Disallow unreadable IIFEs. | βœ… | | | -| [no-unsafe-regex](docs/rules/no-unsafe-regex.md) | Disallow unsafe regular expressions. | | | | -| [no-unused-properties](docs/rules/no-unused-properties.md) | Disallow unused object properties. | | | | -| [no-useless-fallback-in-spread](docs/rules/no-useless-fallback-in-spread.md) | Disallow useless fallback when spreading in object literals. | βœ… | πŸ”§ | | -| [no-useless-length-check](docs/rules/no-useless-length-check.md) | Disallow useless array length check. | βœ… | πŸ”§ | | -| [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 | βœ… | πŸ”§ | | -| [no-useless-spread](docs/rules/no-useless-spread.md) | Disallow unnecessary spread. | βœ… | πŸ”§ | | -| [no-useless-switch-case](docs/rules/no-useless-switch-case.md) | Disallow useless case in switch statements. | βœ… | | πŸ’‘ | -| [no-useless-undefined](docs/rules/no-useless-undefined.md) | Disallow useless `undefined`. | βœ… | πŸ”§ | | -| [no-zero-fractions](docs/rules/no-zero-fractions.md) | Disallow number literals with zero fractions or dangling dots. | βœ… | πŸ”§ | | -| [number-literal-case](docs/rules/number-literal-case.md) | Enforce proper case for numeric literals. | βœ… | πŸ”§ | | -| [numeric-separators-style](docs/rules/numeric-separators-style.md) | Enforce the style of numeric separators by correctly grouping digits. | βœ… | πŸ”§ | | -| [prefer-add-event-listener](docs/rules/prefer-add-event-listener.md) | Prefer `.addEventListener()` and `.removeEventListener()` over `on`-functions. | βœ… | πŸ”§ | | -| [prefer-array-find](docs/rules/prefer-array-find.md) | Prefer `.find(…)` and `.findLast(…)` over the first or last element from `.filter(…)`. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-array-flat](docs/rules/prefer-array-flat.md) | Prefer `Array#flat()` over legacy techniques to flatten arrays. | βœ… | πŸ”§ | | -| [prefer-array-flat-map](docs/rules/prefer-array-flat-map.md) | Prefer `.flatMap(…)` over `.map(…).flat()`. | βœ… | πŸ”§ | | -| [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. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-array-some](docs/rules/prefer-array-some.md) | Prefer `.some(…)` over `.filter(…).length` check and `.{find,findLast}(…)`. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-at](docs/rules/prefer-at.md) | Prefer `.at()` method for index access and `String#charAt()`. | | πŸ”§ | πŸ’‘ | -| [prefer-code-point](docs/rules/prefer-code-point.md) | Prefer `String#codePointAt(…)` over `String#charCodeAt(…)` and `String.fromCodePoint(…)` over `String.fromCharCode(…)`. | βœ… | | πŸ’‘ | -| [prefer-date-now](docs/rules/prefer-date-now.md) | Prefer `Date.now()` to get the number of milliseconds since the Unix Epoch. | βœ… | πŸ”§ | | -| [prefer-default-parameters](docs/rules/prefer-default-parameters.md) | Prefer default parameters over reassignment. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-dom-node-append](docs/rules/prefer-dom-node-append.md) | Prefer `Node#append()` over `Node#appendChild()`. | βœ… | πŸ”§ | | -| [prefer-dom-node-dataset](docs/rules/prefer-dom-node-dataset.md) | Prefer using `.dataset` on DOM elements over calling attribute methods. | βœ… | πŸ”§ | | -| [prefer-dom-node-remove](docs/rules/prefer-dom-node-remove.md) | Prefer `childNode.remove()` over `parentNode.removeChild(childNode)`. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-dom-node-text-content](docs/rules/prefer-dom-node-text-content.md) | Prefer `.textContent` over `.innerText`. | βœ… | | πŸ’‘ | -| [prefer-event-target](docs/rules/prefer-event-target.md) | Prefer `EventTarget` over `EventEmitter`. | | | | -| [prefer-export-from](docs/rules/prefer-export-from.md) | Prefer `export…from` when re-exporting. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-includes](docs/rules/prefer-includes.md) | Prefer `.includes()` over `.indexOf()` and `Array#some()` when checking for existence or non-existence. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-json-parse-buffer](docs/rules/prefer-json-parse-buffer.md) | Prefer reading a JSON file as a buffer. | | πŸ”§ | | -| [prefer-keyboard-event-key](docs/rules/prefer-keyboard-event-key.md) | Prefer `KeyboardEvent#key` over `KeyboardEvent#keyCode`. | βœ… | πŸ”§ | | -| [prefer-logical-operator-over-ternary](docs/rules/prefer-logical-operator-over-ternary.md) | Prefer using a logical operator over a ternary. | βœ… | | πŸ’‘ | -| [prefer-math-trunc](docs/rules/prefer-math-trunc.md) | Enforce the use of `Math.trunc` instead of bitwise operators. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-modern-dom-apis](docs/rules/prefer-modern-dom-apis.md) | Prefer `.before()` over `.insertBefore()`, `.replaceWith()` over `.replaceChild()`, prefer one of `.before()`, `.after()`, `.append()` or `.prepend()` over `insertAdjacentText()` and `insertAdjacentElement()`. | βœ… | πŸ”§ | | -| [prefer-modern-math-apis](docs/rules/prefer-modern-math-apis.md) | Prefer modern `Math` APIs over legacy patterns. | βœ… | πŸ”§ | | -| [prefer-module](docs/rules/prefer-module.md) | Prefer JavaScript modules (ESM) over CommonJS. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-native-coercion-functions](docs/rules/prefer-native-coercion-functions.md) | Prefer using `String`, `Number`, `BigInt`, `Boolean`, and `Symbol` directly. | βœ… | πŸ”§ | | -| [prefer-negative-index](docs/rules/prefer-negative-index.md) | Prefer negative index over `.length - index` for `{String,Array,TypedArray}#{slice,at}()` and `Array#splice()`. | βœ… | πŸ”§ | | -| [prefer-node-protocol](docs/rules/prefer-node-protocol.md) | Prefer using the `node:` protocol when importing Node.js builtin modules. | βœ… | πŸ”§ | | -| [prefer-number-properties](docs/rules/prefer-number-properties.md) | Prefer `Number` static properties over global ones. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-object-from-entries](docs/rules/prefer-object-from-entries.md) | Prefer using `Object.fromEntries(…)` to transform a list of key-value pairs into an object. | βœ… | πŸ”§ | | -| [prefer-optional-catch-binding](docs/rules/prefer-optional-catch-binding.md) | Prefer omitting the `catch` binding parameter. | βœ… | πŸ”§ | | -| [prefer-prototype-methods](docs/rules/prefer-prototype-methods.md) | Prefer borrowing methods from the prototype instead of the instance. | βœ… | πŸ”§ | | -| [prefer-query-selector](docs/rules/prefer-query-selector.md) | Prefer `.querySelector()` over `.getElementById()`, `.querySelectorAll()` over `.getElementsByClassName()` and `.getElementsByTagName()`. | βœ… | πŸ”§ | | -| [prefer-reflect-apply](docs/rules/prefer-reflect-apply.md) | Prefer `Reflect.apply()` over `Function#apply()`. | βœ… | πŸ”§ | | -| [prefer-regexp-test](docs/rules/prefer-regexp-test.md) | Prefer `RegExp#test()` over `String#match()` and `RegExp#exec()`. | βœ… | πŸ”§ | | -| [prefer-set-has](docs/rules/prefer-set-has.md) | Prefer `Set#has()` over `Array#includes()` when checking for existence or non-existence. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-spread](docs/rules/prefer-spread.md) | Prefer the spread operator over `Array.from(…)`, `Array#concat(…)`, `Array#slice()` and `String#split('')`. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-string-replace-all](docs/rules/prefer-string-replace-all.md) | Prefer `String#replaceAll()` over regex searches with the global flag. | | πŸ”§ | | -| [prefer-string-slice](docs/rules/prefer-string-slice.md) | Prefer `String#slice()` over `String#substr()` and `String#substring()`. | βœ… | πŸ”§ | | -| [prefer-string-starts-ends-with](docs/rules/prefer-string-starts-ends-with.md) | Prefer `String#startsWith()` & `String#endsWith()` over `RegExp#test()`. | βœ… | πŸ”§ | πŸ’‘ | -| [prefer-string-trim-start-end](docs/rules/prefer-string-trim-start-end.md) | Prefer `String#trimStart()` / `String#trimEnd()` over `String#trimLeft()` / `String#trimRight()`. | βœ… | πŸ”§ | | -| [prefer-switch](docs/rules/prefer-switch.md) | Prefer `switch` over multiple `else-if`. | βœ… | πŸ”§ | | -| [prefer-ternary](docs/rules/prefer-ternary.md) | Prefer ternary expressions over simple `if-else` statements. | βœ… | πŸ”§ | | -| [prefer-top-level-await](docs/rules/prefer-top-level-await.md) | Prefer top-level await over top-level promises and async function calls. | βœ… | | πŸ’‘ | -| [prefer-type-error](docs/rules/prefer-type-error.md) | Enforce throwing `TypeError` in type checking conditions. | βœ… | πŸ”§ | | -| [prevent-abbreviations](docs/rules/prevent-abbreviations.md) | Prevent abbreviations. | βœ… | πŸ”§ | | -| [relative-url-style](docs/rules/relative-url-style.md) | Enforce consistent relative URL style. | βœ… | πŸ”§ | πŸ’‘ | -| [require-array-join-separator](docs/rules/require-array-join-separator.md) | Enforce using the separator argument with `Array#join()`. | βœ… | πŸ”§ | | -| [require-number-to-fixed-digits-argument](docs/rules/require-number-to-fixed-digits-argument.md) | Enforce using the digits argument with `Number#toFixed()`. | βœ… | πŸ”§ | | -| [require-post-message-target-origin](docs/rules/require-post-message-target-origin.md) | Enforce using the `targetOrigin` argument with `window.postMessage()`. | | | πŸ’‘ | -| [string-content](docs/rules/string-content.md) | Enforce better string content. | | πŸ”§ | πŸ’‘ | -| [switch-case-braces](docs/rules/switch-case-braces.md) | Enforce consistent brace style for `case` clauses. | βœ… | πŸ”§ | | -| [template-indent](docs/rules/template-indent.md) | Fix whitespace-insensitive template indentation. | βœ… | πŸ”§ | | -| [text-encoding-identifier-case](docs/rules/text-encoding-identifier-case.md) | Enforce consistent case for text encoding identifiers. | βœ… | πŸ”§ | πŸ’‘ | -| [throw-new-error](docs/rules/throw-new-error.md) | Require `new` when throwing an error. | βœ… | πŸ”§ | | - + + + +βœ… Enabled in the `recommended` [configuration](https://github.com/sindresorhus/eslint-plugin-unicorn#preset-configs).\ +πŸ”§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\ +πŸ’‘ Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions). + +| Name                                    | Description | βœ… | πŸ”§ | πŸ’‘ | +| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-- | :-- | :-- | +| [better-regex](docs/rules/better-regex.md) | Improve regexes by making them shorter, consistent, and safer. | βœ… | πŸ”§ | | +| [catch-error-name](docs/rules/catch-error-name.md) | Enforce a specific parameter name in catch clauses. | βœ… | πŸ”§ | | +| [consistent-destructuring](docs/rules/consistent-destructuring.md) | Use destructured variables over properties. | βœ… | πŸ”§ | πŸ’‘ | +| [consistent-function-scoping](docs/rules/consistent-function-scoping.md) | Move function definitions to the highest possible scope. | βœ… | | | +| [custom-error-definition](docs/rules/custom-error-definition.md) | Enforce correct `Error` subclassing. | | πŸ”§ | | +| [empty-brace-spaces](docs/rules/empty-brace-spaces.md) | Enforce no spaces between braces. | βœ… | πŸ”§ | | +| [error-message](docs/rules/error-message.md) | Enforce passing a `message` value when creating a built-in error. | βœ… | | | +| [escape-case](docs/rules/escape-case.md) | Require escape sequences to use uppercase values. | βœ… | πŸ”§ | | +| [expiring-todo-comments](docs/rules/expiring-todo-comments.md) | Add expiration conditions to TODO comments. | βœ… | | | +| [explicit-length-check](docs/rules/explicit-length-check.md) | Enforce explicitly comparing the `length` or `size` property of a value. | βœ… | πŸ”§ | πŸ’‘ | +| [filename-case](docs/rules/filename-case.md) | Enforce a case style for filenames. | βœ… | | | +| [import-style](docs/rules/import-style.md) | Enforce specific import styles per module. | βœ… | | | +| [new-for-builtins](docs/rules/new-for-builtins.md) | Enforce the use of `new` for all builtins, except `String`, `Number`, `Boolean`, `Symbol` and `BigInt`. | βœ… | πŸ”§ | | +| [no-abusive-eslint-disable](docs/rules/no-abusive-eslint-disable.md) | Enforce specifying rules to disable in `eslint-disable` comments. | βœ… | | | +| [no-array-callback-reference](docs/rules/no-array-callback-reference.md) | Prevent passing a function reference directly to iterator methods. | βœ… | | πŸ’‘ | +| [no-array-for-each](docs/rules/no-array-for-each.md) | Prefer `for…of` over the `forEach` method. | βœ… | πŸ”§ | πŸ’‘ | +| [no-array-method-this-argument](docs/rules/no-array-method-this-argument.md) | Disallow using the `this` argument in array methods. | βœ… | πŸ”§ | πŸ’‘ | +| [no-array-push-push](docs/rules/no-array-push-push.md) | Enforce combining multiple `Array#push()` into one call. | βœ… | πŸ”§ | πŸ’‘ | +| [no-array-reduce](docs/rules/no-array-reduce.md) | Disallow `Array#reduce()` and `Array#reduceRight()`. | βœ… | | | +| [no-await-expression-member](docs/rules/no-await-expression-member.md) | Disallow member access from await expression. | βœ… | πŸ”§ | | +| [no-console-spaces](docs/rules/no-console-spaces.md) | Do not use leading/trailing space between `console.log` parameters. | βœ… | πŸ”§ | | +| [no-document-cookie](docs/rules/no-document-cookie.md) | Do not use `document.cookie` directly. | βœ… | | | +| [no-empty-file](docs/rules/no-empty-file.md) | Disallow empty files. | βœ… | | | +| [no-for-loop](docs/rules/no-for-loop.md) | Do not use a `for` loop that can be replaced with a `for-of` loop. | βœ… | πŸ”§ | | +| [no-hex-escape](docs/rules/no-hex-escape.md) | Enforce the use of Unicode escapes instead of hexadecimal escapes. | βœ… | πŸ”§ | | +| [no-instanceof-array](docs/rules/no-instanceof-array.md) | Require `Array.isArray()` instead of `instanceof Array`. | βœ… | πŸ”§ | | +| [no-invalid-remove-event-listener](docs/rules/no-invalid-remove-event-listener.md) | Prevent calling `EventTarget#removeEventListener()` with the result of an expression. | βœ… | | | +| [no-keyword-prefix](docs/rules/no-keyword-prefix.md) | Disallow identifiers starting with `new` or `class`. | | | | +| [no-lonely-if](docs/rules/no-lonely-if.md) | Disallow `if` statements as the only statement in `if` blocks without `else`. | βœ… | πŸ”§ | | +| [no-nested-ternary](docs/rules/no-nested-ternary.md) | Disallow nested ternary expressions. | βœ… | πŸ”§ | | +| [no-new-array](docs/rules/no-new-array.md) | Disallow `new Array()`. | βœ… | πŸ”§ | πŸ’‘ | +| [no-new-buffer](docs/rules/no-new-buffer.md) | Enforce the use of `Buffer.from()` and `Buffer.alloc()` instead of the deprecated `new Buffer()`. | βœ… | πŸ”§ | πŸ’‘ | +| [no-null](docs/rules/no-null.md) | Disallow the use of the `null` literal. | βœ… | πŸ”§ | πŸ’‘ | +| [no-object-as-default-parameter](docs/rules/no-object-as-default-parameter.md) | Disallow the use of objects as default parameters. | βœ… | | | +| [no-process-exit](docs/rules/no-process-exit.md) | Disallow `process.exit()`. | βœ… | | | +| [no-static-only-class](docs/rules/no-static-only-class.md) | Disallow classes that only have static members. | βœ… | πŸ”§ | | +| [no-thenable](docs/rules/no-thenable.md) | Disallow `then` property. | βœ… | | | +| [no-this-assignment](docs/rules/no-this-assignment.md) | Disallow assigning `this` to a variable. | βœ… | | | +| [no-unnecessary-await](docs/rules/no-unnecessary-await.md) | Disallow awaiting non-promise values. | βœ… | πŸ”§ | | +| [no-unreadable-array-destructuring](docs/rules/no-unreadable-array-destructuring.md) | Disallow unreadable array destructuring. | βœ… | πŸ”§ | | +| [no-unreadable-iife](docs/rules/no-unreadable-iife.md) | Disallow unreadable IIFEs. | βœ… | | | +| [no-unsafe-regex](docs/rules/no-unsafe-regex.md) | Disallow unsafe regular expressions. | | | | +| [no-unused-properties](docs/rules/no-unused-properties.md) | Disallow unused object properties. | | | | +| [no-useless-fallback-in-spread](docs/rules/no-useless-fallback-in-spread.md) | Disallow useless fallback when spreading in object literals. | βœ… | πŸ”§ | | +| [no-useless-length-check](docs/rules/no-useless-length-check.md) | Disallow useless array length check. | βœ… | πŸ”§ | | +| [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 | βœ… | πŸ”§ | | +| [no-useless-spread](docs/rules/no-useless-spread.md) | Disallow unnecessary spread. | βœ… | πŸ”§ | | +| [no-useless-switch-case](docs/rules/no-useless-switch-case.md) | Disallow useless case in switch statements. | βœ… | | πŸ’‘ | +| [no-useless-undefined](docs/rules/no-useless-undefined.md) | Disallow useless `undefined`. | βœ… | πŸ”§ | | +| [no-zero-fractions](docs/rules/no-zero-fractions.md) | Disallow number literals with zero fractions or dangling dots. | βœ… | πŸ”§ | | +| [number-literal-case](docs/rules/number-literal-case.md) | Enforce proper case for numeric literals. | βœ… | πŸ”§ | | +| [numeric-separators-style](docs/rules/numeric-separators-style.md) | Enforce the style of numeric separators by correctly grouping digits. | βœ… | πŸ”§ | | +| [prefer-add-event-listener](docs/rules/prefer-add-event-listener.md) | Prefer `.addEventListener()` and `.removeEventListener()` over `on`-functions. | βœ… | πŸ”§ | | +| [prefer-array-find](docs/rules/prefer-array-find.md) | Prefer `.find(…)` and `.findLast(…)` over the first or last element from `.filter(…)`. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-array-flat](docs/rules/prefer-array-flat.md) | Prefer `Array#flat()` over legacy techniques to flatten arrays. | βœ… | πŸ”§ | | +| [prefer-array-flat-map](docs/rules/prefer-array-flat-map.md) | Prefer `.flatMap(…)` over `.map(…).flat()`. | βœ… | πŸ”§ | | +| [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. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-array-some](docs/rules/prefer-array-some.md) | Prefer `.some(…)` over `.filter(…).length` check and `.{find,findLast}(…)`. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-at](docs/rules/prefer-at.md) | Prefer `.at()` method for index access and `String#charAt()`. | | πŸ”§ | πŸ’‘ | +| [prefer-code-point](docs/rules/prefer-code-point.md) | Prefer `String#codePointAt(…)` over `String#charCodeAt(…)` and `String.fromCodePoint(…)` over `String.fromCharCode(…)`. | βœ… | | πŸ’‘ | +| [prefer-date-now](docs/rules/prefer-date-now.md) | Prefer `Date.now()` to get the number of milliseconds since the Unix Epoch. | βœ… | πŸ”§ | | +| [prefer-default-parameters](docs/rules/prefer-default-parameters.md) | Prefer default parameters over reassignment. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-dom-node-append](docs/rules/prefer-dom-node-append.md) | Prefer `Node#append()` over `Node#appendChild()`. | βœ… | πŸ”§ | | +| [prefer-dom-node-dataset](docs/rules/prefer-dom-node-dataset.md) | Prefer using `.dataset` on DOM elements over calling attribute methods. | βœ… | πŸ”§ | | +| [prefer-dom-node-remove](docs/rules/prefer-dom-node-remove.md) | Prefer `childNode.remove()` over `parentNode.removeChild(childNode)`. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-dom-node-text-content](docs/rules/prefer-dom-node-text-content.md) | Prefer `.textContent` over `.innerText`. | βœ… | | πŸ’‘ | +| [prefer-event-target](docs/rules/prefer-event-target.md) | Prefer `EventTarget` over `EventEmitter`. | | | | +| [prefer-export-from](docs/rules/prefer-export-from.md) | Prefer `export…from` when re-exporting. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-includes](docs/rules/prefer-includes.md) | Prefer `.includes()` over `.indexOf()` and `Array#some()` when checking for existence or non-existence. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-json-parse-buffer](docs/rules/prefer-json-parse-buffer.md) | Prefer reading a JSON file as a buffer. | | πŸ”§ | | +| [prefer-keyboard-event-key](docs/rules/prefer-keyboard-event-key.md) | Prefer `KeyboardEvent#key` over `KeyboardEvent#keyCode`. | βœ… | πŸ”§ | | +| [prefer-logical-operator-over-ternary](docs/rules/prefer-logical-operator-over-ternary.md) | Prefer using a logical operator over a ternary. | βœ… | | πŸ’‘ | +| [prefer-math-trunc](docs/rules/prefer-math-trunc.md) | Enforce the use of `Math.trunc` instead of bitwise operators. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-modern-dom-apis](docs/rules/prefer-modern-dom-apis.md) | Prefer `.before()` over `.insertBefore()`, `.replaceWith()` over `.replaceChild()`, prefer one of `.before()`, `.after()`, `.append()` or `.prepend()` over `insertAdjacentText()` and `insertAdjacentElement()`. | βœ… | πŸ”§ | | +| [prefer-modern-math-apis](docs/rules/prefer-modern-math-apis.md) | Prefer modern `Math` APIs over legacy patterns. | βœ… | πŸ”§ | | +| [prefer-module](docs/rules/prefer-module.md) | Prefer JavaScript modules (ESM) over CommonJS. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-native-coercion-functions](docs/rules/prefer-native-coercion-functions.md) | Prefer using `String`, `Number`, `BigInt`, `Boolean`, and `Symbol` directly. | βœ… | πŸ”§ | | +| [prefer-negative-index](docs/rules/prefer-negative-index.md) | Prefer negative index over `.length - index` for `{String,Array,TypedArray}#{slice,at}()` and `Array#splice()`. | βœ… | πŸ”§ | | +| [prefer-node-protocol](docs/rules/prefer-node-protocol.md) | Prefer using the `node:` protocol when importing Node.js builtin modules. | βœ… | πŸ”§ | | +| [prefer-number-properties](docs/rules/prefer-number-properties.md) | Prefer `Number` static properties over global ones. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-object-from-entries](docs/rules/prefer-object-from-entries.md) | Prefer using `Object.fromEntries(…)` to transform a list of key-value pairs into an object. | βœ… | πŸ”§ | | +| [prefer-optional-catch-binding](docs/rules/prefer-optional-catch-binding.md) | Prefer omitting the `catch` binding parameter. | βœ… | πŸ”§ | | +| [prefer-prototype-methods](docs/rules/prefer-prototype-methods.md) | Prefer borrowing methods from the prototype instead of the instance. | βœ… | πŸ”§ | | +| [prefer-query-selector](docs/rules/prefer-query-selector.md) | Prefer `.querySelector()` over `.getElementById()`, `.querySelectorAll()` over `.getElementsByClassName()` and `.getElementsByTagName()`. | βœ… | πŸ”§ | | +| [prefer-reflect-apply](docs/rules/prefer-reflect-apply.md) | Prefer `Reflect.apply()` over `Function#apply()`. | βœ… | πŸ”§ | | +| [prefer-regexp-test](docs/rules/prefer-regexp-test.md) | Prefer `RegExp#test()` over `String#match()` and `RegExp#exec()`. | βœ… | πŸ”§ | | +| [prefer-set-has](docs/rules/prefer-set-has.md) | Prefer `Set#has()` over `Array#includes()` when checking for existence or non-existence. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-spread](docs/rules/prefer-spread.md) | Prefer the spread operator over `Array.from(…)`, `Array#concat(…)`, `Array#slice()` and `String#split('')`. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-string-replace-all](docs/rules/prefer-string-replace-all.md) | Prefer `String#replaceAll()` over regex searches with the global flag. | | πŸ”§ | | +| [prefer-string-slice](docs/rules/prefer-string-slice.md) | Prefer `String#slice()` over `String#substr()` and `String#substring()`. | βœ… | πŸ”§ | | +| [prefer-string-starts-ends-with](docs/rules/prefer-string-starts-ends-with.md) | Prefer `String#startsWith()` & `String#endsWith()` over `RegExp#test()`. | βœ… | πŸ”§ | πŸ’‘ | +| [prefer-string-trim-start-end](docs/rules/prefer-string-trim-start-end.md) | Prefer `String#trimStart()` / `String#trimEnd()` over `String#trimLeft()` / `String#trimRight()`. | βœ… | πŸ”§ | | +| [prefer-switch](docs/rules/prefer-switch.md) | Prefer `switch` over multiple `else-if`. | βœ… | πŸ”§ | | +| [prefer-ternary](docs/rules/prefer-ternary.md) | Prefer ternary expressions over simple `if-else` statements. | βœ… | πŸ”§ | | +| [prefer-top-level-await](docs/rules/prefer-top-level-await.md) | Prefer top-level await over top-level promises and async function calls. | βœ… | | πŸ’‘ | +| [prefer-type-error](docs/rules/prefer-type-error.md) | Enforce throwing `TypeError` in type checking conditions. | βœ… | πŸ”§ | | +| [prevent-abbreviations](docs/rules/prevent-abbreviations.md) | Prevent abbreviations. | βœ… | πŸ”§ | | +| [relative-url-style](docs/rules/relative-url-style.md) | Enforce consistent relative URL style. | βœ… | πŸ”§ | πŸ’‘ | +| [require-array-join-separator](docs/rules/require-array-join-separator.md) | Enforce using the separator argument with `Array#join()`. | βœ… | πŸ”§ | | +| [require-number-to-fixed-digits-argument](docs/rules/require-number-to-fixed-digits-argument.md) | Enforce using the digits argument with `Number#toFixed()`. | βœ… | πŸ”§ | | +| [require-post-message-target-origin](docs/rules/require-post-message-target-origin.md) | Enforce using the `targetOrigin` argument with `window.postMessage()`. | | | πŸ’‘ | +| [string-content](docs/rules/string-content.md) | Enforce better string content. | | πŸ”§ | πŸ’‘ | +| [switch-case-braces](docs/rules/switch-case-braces.md) | Enforce consistent brace style for `case` clauses. | βœ… | πŸ”§ | | +| [template-indent](docs/rules/template-indent.md) | Fix whitespace-insensitive template indentation. | βœ… | πŸ”§ | | +| [text-encoding-identifier-case](docs/rules/text-encoding-identifier-case.md) | Enforce consistent case for text encoding identifiers. | βœ… | πŸ”§ | πŸ’‘ | +| [throw-new-error](docs/rules/throw-new-error.md) | Require `new` when throwing an error. | βœ… | πŸ”§ | | + + ### Deprecated Rules diff --git a/scripts/create-rule.mjs b/scripts/create-rule.mjs index dca13025ee..202f091a5e 100644 --- a/scripts/create-rule.mjs +++ b/scripts/create-rule.mjs @@ -5,7 +5,6 @@ import {fileURLToPath} from 'node:url'; import enquirer from 'enquirer'; import {template} from 'lodash-es'; import {execa} from 'execa'; -import ruleDescriptionToDocumentTitle from '../test/utils/rule-description-to-document-title.mjs'; const dirname = path.dirname(fileURLToPath(import.meta.url)); const ROOT = path.join(dirname, '..'); @@ -131,10 +130,7 @@ async function getData() { const data = await enquirer.prompt(questions); - return { - ...data, - docTitle: ruleDescriptionToDocumentTitle(data.description), - }; + return data; } const data = await getData(); diff --git a/scripts/generate-rule-notices.mjs b/scripts/generate-rule-notices.mjs deleted file mode 100644 index 5c77a4a0e2..0000000000 --- a/scripts/generate-rule-notices.mjs +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env node - -// Automatically regenerates the rule notice. - -import {getRules, updateFileContentInsideMark} from './utils.mjs'; -import {RULE_NOTICE_MARK, getRuleNoticesSectionBody} from './rule-notices.mjs'; - -const updateNotices = ruleId => - updateFileContentInsideMark( - new URL(`../docs/rules/${ruleId}.md`, import.meta.url), - getRuleNoticesSectionBody(ruleId), - RULE_NOTICE_MARK, - ); - -await Promise.all( - getRules() - .filter(rule => !rule.isDeprecated) - .map(rule => updateNotices(rule.id)), -); diff --git a/scripts/generate-rules-table.mjs b/scripts/generate-rules-table.mjs deleted file mode 100644 index 19ae869064..0000000000 --- a/scripts/generate-rules-table.mjs +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env node - -// Automatically regenerates the rules table in readme.md. - -import {updateFileContentInsideMark} from './utils.mjs'; -import {RULES_TABLE_MARK, getRulesTable} from './rules-table.mjs'; - -await updateFileContentInsideMark( - new URL('../readme.md', import.meta.url), - getRulesTable(), - RULES_TABLE_MARK, -); diff --git a/scripts/rule-notices.mjs b/scripts/rule-notices.mjs deleted file mode 100644 index 16e2b7b48a..0000000000 --- a/scripts/rule-notices.mjs +++ /dev/null @@ -1,27 +0,0 @@ -import {createMark, getRuleInfo} from './utils.mjs'; - -export const RULE_NOTICE_MARK = createMark('RULE_NOTICE', 'generate-rule-notices'); - -const MESSAGES = { - recommended: 'βœ… *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.*', - fixable: 'πŸ”§ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).*', - fixableAndHasSuggestions: 'πŸ”§πŸ’‘ *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) and provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).*', - hasSuggestions: 'πŸ’‘ *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).*', -}; -export function getRuleNoticesSectionBody(ruleId) { - const rule = getRuleInfo(ruleId); - - const notices = []; - - if (rule.isRecommended) { - notices.push(MESSAGES.recommended); - } - - if (rule.isFixable) { - notices.push(rule.hasSuggestions ? MESSAGES.fixableAndHasSuggestions : MESSAGES.fixable); - } else if (rule.hasSuggestions) { - notices.push(MESSAGES.hasSuggestions); - } - - return notices.join('\n\n'); -} diff --git a/scripts/rules-table.mjs b/scripts/rules-table.mjs deleted file mode 100644 index fbafd527a4..0000000000 --- a/scripts/rules-table.mjs +++ /dev/null @@ -1,33 +0,0 @@ -import outdent from 'outdent'; -import {createMark, getRules} from './utils.mjs'; - -export const RULES_TABLE_MARK = createMark('RULES_TABLE', 'generate-rules-table'); - -// Config/preset/fixable emojis. -const EMOJI_RECOMMENDED = 'βœ…'; -const EMOJI_FIXABLE = 'πŸ”§'; -const EMOJI_HAS_SUGGESTIONS = 'πŸ’‘'; -export function getRulesTable() { - const rules = getRules().filter(rule => !rule.isDeprecated); - - const rulesTableContent = rules.map(rule => { - const url = `docs/rules/${rule.id}.md`; - const link = `[${rule.id}](${url})`; - - const {description} = rule.meta.docs; - - return `| ${[ - link, - description, - rule.isRecommended ? EMOJI_RECOMMENDED : '', - rule.isFixable ? EMOJI_FIXABLE : '', - rule.hasSuggestions ? EMOJI_HAS_SUGGESTIONS : '', - ].join(' | ')} |`; - }).join('\n'); - - return outdent` - | Name${' '.repeat(40)} | Description | ${EMOJI_RECOMMENDED} | ${EMOJI_FIXABLE} | ${EMOJI_HAS_SUGGESTIONS} | - |${' :-- |'.repeat(5)} - ${rulesTableContent} - `; -} diff --git a/scripts/template/documentation.md.jst b/scripts/template/documentation.md.jst index c04c698662..289d98f45a 100644 --- a/scripts/template/documentation.md.jst +++ b/scripts/template/documentation.md.jst @@ -1,8 +1,5 @@ -# <%= docTitle %> - - - - + + diff --git a/scripts/utils.mjs b/scripts/utils.mjs deleted file mode 100644 index 2741a630b0..0000000000 --- a/scripts/utils.mjs +++ /dev/null @@ -1,76 +0,0 @@ -import {promises as fs} from 'node:fs'; -import eslintPluginUnicorn from '../index.js'; - -const {rules, configs} = eslintPluginUnicorn; - -export function getRuleInfo(ruleId) { - const rule = rules[ruleId]; - - return { - id: ruleId, - meta: rule.meta, - get isRecommended() { - return ['error', 'warn'].includes(configs.recommended.rules[`unicorn/${ruleId}`]); - }, - get isDeprecated() { - return Boolean(rule.meta.deprecated); - }, - get isFixable() { - return Boolean(rule.meta.fixable); - }, - get hasSuggestions() { - return Boolean(rule.meta.hasSuggestions); - }, - }; -} - -export function getRules() { - return Object.keys(rules).sort().map(ruleId => getRuleInfo(ruleId)); -} - -const createHtmlComment = comment => ``; -export const createMark = (marker, script) => ({ - comment: createHtmlComment(`Do not manually modify ${marker} part. Run: \`npm run ${script}\``), - start: createHtmlComment(marker), - end: createHtmlComment(`/${marker}`), -}); - -function replaceContentInsideMark(original, text, marker) { - const startMarkIndex = original.indexOf(marker.start); - const endMarkIndex = original.indexOf(marker.end); - - if (startMarkIndex === -1) { - throw new Error(`'${marker.start}' mark lost.`); - } - - if (endMarkIndex === -1) { - throw new Error(`'${marker.end}' mark lost.`); - } - - if (startMarkIndex > endMarkIndex) { - throw new Error(`'${marker.start}' should used before '${marker.end}'.`); - } - - if (text) { - text = `${text}\n`; - } - - text = `\n${text}`; - - const before = original.slice(0, startMarkIndex + marker.start.length); - const after = original.slice(endMarkIndex); - - return before + text + after; -} - -export async function updateFileContentInsideMark(file, text, marker) { - const original = await fs.readFile(file, 'utf8'); - const content = replaceContentInsideMark(original, text, marker); - - if (content === original) { - return; - } - - await fs.writeFile(file, content); -} - diff --git a/test/package.mjs b/test/package.mjs index 3551064fec..ee429d2758 100644 --- a/test/package.mjs +++ b/test/package.mjs @@ -4,9 +4,6 @@ import test from 'ava'; import {ESLint} from 'eslint'; import * as eslintrc from '@eslint/eslintrc'; import eslintPluginUnicorn from '../index.js'; -import {RULE_NOTICE_MARK, getRuleNoticesSectionBody} from '../scripts/rule-notices.mjs'; -import {RULES_TABLE_MARK, getRulesTable} from '../scripts/rules-table.mjs'; -import ruleDescriptionToDocumentTitle from './utils/rule-description-to-document-title.mjs'; let ruleFiles; @@ -34,32 +31,6 @@ const testSorted = (t, actualOrder, sourceName) => { } }; -/** -Get list of named options from a JSON schema (used for rule schemas). - -@param {object | Array} jsonSchema - The JSON schema to check. -@returns {string[]} A list of named options. -*/ -function getNamedOptions(jsonSchema) { - if (!jsonSchema) { - return []; - } - - if (Array.isArray(jsonSchema)) { - return jsonSchema.flatMap(item => getNamedOptions(item)); - } - - if (jsonSchema.items) { - return getNamedOptions(jsonSchema.items); - } - - if (jsonSchema.properties) { - return Object.keys(jsonSchema.properties); - } - - return []; -} - const RULES_WITHOUT_PASS_FAIL_SECTIONS = new Set([ // Doesn't show code samples since it's just focused on filenames. 'filename-case', @@ -189,60 +160,6 @@ test('validate configuration', async t => { } }); -test('Every rule is defined in readme.md usage and list of rules in alphabetical order', async t => { - const readme = await fsAsync.readFile('readme.md', 'utf8'); - - const lines = readme.split('\n'); - const startMarkLine = lines.indexOf(RULES_TABLE_MARK.start); - t.not( - startMarkLine, - -1, - 'missing rules table start mark', - ); - const endMarkLine = lines.indexOf(RULES_TABLE_MARK.end); - t.not( - endMarkLine, - -1, - 'missing rules table end mark', - ); - const table = lines.slice(startMarkLine - 1, endMarkLine + 1).join('\n'); - t.is( - table, - [ - RULES_TABLE_MARK.comment, - RULES_TABLE_MARK.start, - getRulesTable(), - RULES_TABLE_MARK.end, - ].join('\n'), - 'rules table should have correct content', - ); - - const re = /\| \[(?.*?)]\((?.*?)\) \| (?.*) \| (?.*?) \| (?.*?) \| (?.*?)\n/gm; - const rules = []; - let match; - do { - match = re.exec(table); - if (match) { - const {id, link, description} = match.groups; - t.is(link, `docs/rules/${id}.md`, `${id} link to docs should be correct`); - t.true(description.trim().length > 0, `${id} should have description in readme.md ## Rules`); - rules.push(id); - } - } while (match); - - const availableRules = ruleFiles - .map(file => path.basename(file, '.js')) - .filter(name => !deprecatedRules.includes(name)); - - for (const name of availableRules) { - t.truthy(rules.includes(name), `'${name}' is not described in the readme.md ## Rules`); - } - - t.is(Object.keys(rules).length, availableRules.length, 'There are more rules in readme.md ## Rules than rule files.'); - - testSorted(t, rules, 'readme.md ## Rules'); -}); - test('Every rule has valid meta.type', t => { const validTypes = ['problem', 'suggestion', 'layout']; @@ -282,67 +199,13 @@ test('Every rule file has the appropriate contents', t => { test('Every rule has a doc with the appropriate content', t => { for (const ruleFile of ruleFiles) { const ruleName = path.basename(ruleFile, '.js'); - const rule = eslintPluginUnicorn.rules[ruleName]; const documentPath = path.join('docs/rules', `${ruleName}.md`); const documentContents = fs.readFileSync(documentPath, 'utf8'); - const documentLines = documentContents.split('\n'); - - // Check title. - const expectedTitle = `# ${ruleDescriptionToDocumentTitle(rule.meta.docs.description)}`; - t.is(documentLines[0], expectedTitle, `${ruleName} includes the rule description in title`); // Check for examples. if (!RULES_WITHOUT_PASS_FAIL_SECTIONS.has(ruleName)) { t.true(documentContents.includes('## Pass'), `${ruleName} includes '## Pass' examples section`); t.true(documentContents.includes('## Fail'), `${ruleName} includes '## Fail' examples section`); } - - // Check if the rule has configuration options. - if ( - (Array.isArray(rule.meta.schema) && rule.meta.schema.length > 0) - || (typeof rule.meta.schema === 'object' && Object.keys(rule.meta.schema).length > 0) - ) { - // Should have an options section header: - t.true(documentContents.includes('## Options'), `${ruleName} should have an "## Options" section`); - - // Ensure all configuration options are mentioned. - for (const namedOption of getNamedOptions(rule.meta.schema)) { - t.true(documentContents.includes(namedOption), `${ruleName} should mention the \`${namedOption}\` option`); - } - } else { - // Should NOT have any options/config section headers: - t.false(documentContents.includes('# Options'), `${ruleName} should not have an "Options" section`); - t.false(documentContents.includes('# Config'), `${ruleName} should not have a "Config" section`); - } - - // Ensure that expected notices are present in the correct order. - t.is( - documentLines[1], - '', - `${ruleName} should has blank line before notice`, - ); - const startMarkLine = 3; - t.is( - documentLines[startMarkLine], - RULE_NOTICE_MARK.start, - `${ruleName} missing rule notice start mark`, - ); - const endMarkLine = documentLines.indexOf(RULE_NOTICE_MARK.end); - t.not( - endMarkLine, - -1, - `${ruleName} missing rule notice end mark`, - ); - const notices = documentLines.slice(startMarkLine - 1, endMarkLine + 1).join('\n'); - t.is( - notices, - [ - RULE_NOTICE_MARK.comment, - RULE_NOTICE_MARK.start, - getRuleNoticesSectionBody(ruleName), - RULE_NOTICE_MARK.end, - ].filter(Boolean).join('\n'), - `${ruleName} should have expected notice(s)`, - ); } }); diff --git a/test/utils/rule-description-to-document-title.mjs b/test/utils/rule-description-to-document-title.mjs deleted file mode 100644 index 1118afe5a4..0000000000 --- a/test/utils/rule-description-to-document-title.mjs +++ /dev/null @@ -1,14 +0,0 @@ -/** -From a rule's description, generate the intended title for its rule doc. - -@param {string} description - rule description -@returns {string} title for rule doc -*/ -export default function ruleDescriptionToDocumentTitle(description) { - let title = description.charAt(0).toUpperCase() + description.slice(1); // Capitalize first letter. - if (title.endsWith('.')) { - title = title.slice(0, -1); // Remove any ending period. - } - - return title; -}