diff --git a/src/docs/guide/usage/linter/generated-config.md b/src/docs/guide/usage/linter/generated-config.md index c6e2c3a0a9b..6bb74ddefcd 100644 --- a/src/docs/guide/usage/linter/generated-config.md +++ b/src/docs/guide/usage/linter/generated-config.md @@ -434,3 +434,22 @@ Example: ``` ##### settings.react.linkComponents[n] + +### settings.vitest + +type: `object` + +Configure Vitest plugin rules. + +See [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest)'s +configuration for a full reference. + +#### settings.vitest.typecheck + +type: `boolean` + +default: `false` + +Whether to enable typecheck mode for Vitest rules. +When enabled, some rules will skip certain checks for describe blocks +to accommodate TypeScript type checking scenarios. diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index 23e9801a02b..3897922d8ca 100644 --- a/src/docs/guide/usage/linter/generated-rules.md +++ b/src/docs/guide/usage/linter/generated-rules.md @@ -2,7 +2,7 @@ The progress of all rule implementations is tracked [here](https://github.com/oxc-project/oxc/issues/481). -- Total number of rules: 610 +- Total number of rules: 611 - Rules turned on by default: 103 **Legend for 'Fixable?' column:** @@ -374,7 +374,7 @@ code that is most likely wrong or useless. | [no-required-prop-with-default](/docs/guide/usage/linter/rules/vue/no-required-prop-with-default.html) | vue | | 🚧 | | [require-default-export](/docs/guide/usage/linter/rules/vue/require-default-export.html) | vue | | | -## Pedantic (102): +## Pedantic (103): Lints which are rather strict or have occasional false positives. @@ -438,6 +438,7 @@ Lints which are rather strict or have occasional false positives. | [require-await](/docs/guide/usage/linter/rules/typescript/require-await.html) | typescript | | 🚧 | | [restrict-plus-operands](/docs/guide/usage/linter/rules/typescript/restrict-plus-operands.html) | typescript | | 🚧 | | [return-await](/docs/guide/usage/linter/rules/typescript/return-await.html) | typescript | | 🚧 | +| [strict-boolean-expressions](/docs/guide/usage/linter/rules/typescript/strict-boolean-expressions.html) | typescript | | 🚧 | | [switch-exhaustiveness-check](/docs/guide/usage/linter/rules/typescript/switch-exhaustiveness-check.html) | typescript | | 🚧 | | [consistent-assert](/docs/guide/usage/linter/rules/unicorn/consistent-assert.html) | unicorn | | 🛠️ | | [consistent-empty-array-spread](/docs/guide/usage/linter/rules/unicorn/consistent-empty-array-spread.html) | unicorn | | 💡 | diff --git a/src/docs/guide/usage/linter/rules/eslint/getter-return.md b/src/docs/guide/usage/linter/rules/eslint/getter-return.md index 4bfcdd4fc57..1dcf2ec6ab7 100644 --- a/src/docs/guide/usage/linter/rules/eslint/getter-return.md +++ b/src/docs/guide/usage/linter/rules/eslint/getter-return.md @@ -49,6 +49,18 @@ class Person { } ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowImplicit + +type: `boolean` + +default: `false` + +When set to `true`, allows getters to implicitly return `undefined` with a `return` statement containing no expression. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/id-length.md b/src/docs/guide/usage/linter/rules/eslint/id-length.md index 235ef4f49bb..9bce9fdeebe 100644 --- a/src/docs/guide/usage/linter/rules/eslint/id-length.md +++ b/src/docs/guide/usage/linter/rules/eslint/id-length.md @@ -115,6 +115,50 @@ const data = { "x": 1 }; // excused because of quotes data["y"] = 3; // excused because of calculated property access ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### exceptionPatterns + +type: `string[]` + +An array of regex patterns for identifiers to exclude from the rule. +For example, `["^x.*"]` would exclude all identifiers starting with "x". + +### exceptions + +type: `string[]` + +default: `[]` + +An array of identifier names that are excluded from the rule. +For example, `["x", "y", "z"]` would allow single-letter identifiers "x", "y", and "z". + +### max + +type: `integer` + +default: `18446744073709551615` + +The maximum number of graphemes allowed in an identifier. +Defaults to no maximum (effectively unlimited). + +### min + +type: `integer` + +default: `2` + +The minimum number of graphemes required in an identifier. + +### properties + +type: `"always" | "never"` + +When set to `"never"`, property names are not checked for length. +When set to `"always"` (default), property names are checked just like other identifiers. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/init-declarations.md b/src/docs/guide/usage/linter/rules/eslint/init-declarations.md index ce9765ab742..1a96b90a7e3 100644 --- a/src/docs/guide/usage/linter/rules/eslint/init-declarations.md +++ b/src/docs/guide/usage/linter/rules/eslint/init-declarations.md @@ -81,6 +81,26 @@ Examples of correct code for the "never", { "ignoreForLoopInit": true } options: for (var i = 0; i < 1; i++) {} ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### ignoreForLoopInit + +type: `boolean` + +default: `false` + +When set to `true`, allows uninitialized variables in the init expression of `for`, `for-in`, and `for-of` loops. +Only applies when mode is set to `"never"`. + +### mode + +type: `"always" | "never"` + +When set to `"always"` (default), requires that variables be initialized on declaration. +When set to `"never"`, disallows initialization during declaration. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/max-classes-per-file.md b/src/docs/guide/usage/linter/rules/eslint/max-classes-per-file.md index 90cd147bdd7..0deb3b2aa79 100644 --- a/src/docs/guide/usage/linter/rules/eslint/max-classes-per-file.md +++ b/src/docs/guide/usage/linter/rules/eslint/max-classes-per-file.md @@ -38,6 +38,26 @@ function foo() { } ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### ignoreExpressions + +type: `boolean` + +default: `false` + +Whether to ignore class expressions when counting classes. + +### max + +type: `integer` + +default: `1` + +The maximum number of classes allowed per file. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/max-nested-callbacks.md b/src/docs/guide/usage/linter/rules/eslint/max-nested-callbacks.md index c705813a6b7..7d6393fb683 100644 --- a/src/docs/guide/usage/linter/rules/eslint/max-nested-callbacks.md +++ b/src/docs/guide/usage/linter/rules/eslint/max-nested-callbacks.md @@ -61,26 +61,17 @@ function handleFoo4() { } ``` -### Options +## Configuration -#### max +This rule accepts a configuration object with the following properties: -`{ type: number, default: 10 }` +### max -The `max` enforces a maximum depth that callbacks can be nested. - -Example: +type: `integer` -```json -"eslint/max-nested-callbacks": ["error", 10] +default: `10` -"eslint/max-nested-callbacks": [ - "error", - { - max: 10 - } -] -``` +The `max` enforces a maximum depth that callbacks can be nested. ## How to use diff --git a/src/docs/guide/usage/linter/rules/eslint/no-empty.md b/src/docs/guide/usage/linter/rules/eslint/no-empty.md index 06a24db1c25..26417878e07 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-empty.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-empty.md @@ -39,6 +39,18 @@ if (condition) { } ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowEmptyCatch + +type: `boolean` + +default: `false` + +If set to `true`, allows an empty `catch` block without triggering the linter. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-eval.md b/src/docs/guide/usage/linter/rules/eslint/no-eval.md index 9d40e13f699..abf45d8c44c 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-eval.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-eval.md @@ -66,11 +66,15 @@ class A { } ``` -### Options +## Configuration -#### allowIndirect +This rule accepts a configuration object with the following properties: -`{ type: boolean, default: true }` +### allowIndirect + +type: `boolean` + +default: `true` This `allowIndirect` option allows indirect `eval()` calls. @@ -79,15 +83,6 @@ than direct calls because they cannot dynamically change the scope. Indirect `eval()` calls also typically have less impact on performance compared to direct calls, as they do not invoke JavaScript's scope chain. -Example: - -```json -"eslint/no-eval": [ - "error", - { "allowIndirect": true } -] -``` - ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-extend-native.md b/src/docs/guide/usage/linter/rules/eslint/no-extend-native.md index 365bc95bc03..2eadbd1d87b 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-extend-native.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-extend-native.md @@ -53,6 +53,18 @@ x.prototype.p = 0; Object.defineProperty(x.prototype, "p", { value: 0 }); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### exceptions + +type: `string[]` + +default: `[]` + +A list of objects which are allowed to be exceptions to the rule. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-extra-boolean-cast.md b/src/docs/guide/usage/linter/rules/eslint/no-extra-boolean-cast.md index baca15c0902..7cf5cca9cff 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-extra-boolean-cast.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-extra-boolean-cast.md @@ -53,6 +53,22 @@ if (foo) {} if (foo || bar) {} ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### enforceForInnerExpressions + +type: `boolean` + +default: `false` + +when set to `true`, in addition to checking default contexts, checks +whether extra boolean casts are present in expressions whose result is +used in a boolean context. See examples below. Default is `false`, +meaning that this rule by default does not warn about extra booleans +cast inside inner expressions. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-labels.md b/src/docs/guide/usage/linter/rules/eslint/no-labels.md index b661c0278e2..39e9f74c98c 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-labels.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-labels.md @@ -83,19 +83,18 @@ while (true) { } ``` -### Options +## Configuration -The options allow labels with loop or switch statements: +This rule accepts a configuration object with the following properties: -- `"allowLoop"` (`boolean`, default is `false`) - If this option was set `true`, this rule ignores labels which are sticking to loop statements. -- `"allowSwitch"` (`boolean`, default is `false`) - If this option was set `true`, this rule ignores labels which are sticking to switch statements. +### allowLoop -Actually labeled statements in JavaScript can be used with other than loop and switch statements. -However, this way is ultra rare, not well-known, so this would be confusing developers. +type: `boolean` -#### allowLoop +default: `false` -Examples of **correct** code for the `{ "allowLoop": true }` option: +If set to `true`, this rule ignores labels which are sticking to loop statements. +Examples of **correct** code with this option set to `true`: ```js label: @@ -104,9 +103,14 @@ while (true) { } ``` -#### allowSwitch +### allowSwitch -Examples of **correct** code for the `{ "allowSwitch": true }` option: +type: `boolean` + +default: `false` + +If set to `true`, this rule ignores labels which are sticking to switch statements. +Examples of **correct** code with this option set to `true`: ```js label: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-misleading-character-class.md b/src/docs/guide/usage/linter/rules/eslint/no-misleading-character-class.md index f78f4e73c0e..6b39d485634 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-misleading-character-class.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-misleading-character-class.md @@ -56,12 +56,18 @@ Examples of **correct** code for this rule: new RegExp("^[\u{1F1EF}\u{1F1F5}]", "u"); ``` -#### Options +## Configuration -This rule has an object option: +This rule accepts a configuration object with the following properties: -- `allowEscape`: When set to `true`, the rule allows any grouping of code points - inside a character class as long as they are written using escape sequences. +### allowEscape + +type: `boolean` + +default: `false` + +When set to `true`, the rule allows any grouping of code points +inside a character class as long as they are written using escape sequences. Examples of **incorrect** code for this rule with `{ "allowEscape": true }`: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-multi-assign.md b/src/docs/guide/usage/linter/rules/eslint/no-multi-assign.md index 5a3356815d9..1c0a480667a 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-multi-assign.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-multi-assign.md @@ -66,15 +66,19 @@ a = "quux"; b = "quux"; ``` -### Options +## Configuration -This rule has an object option: +This rule accepts a configuration object with the following properties: -- `"ignoreNonDeclaration"`: When set to `true`, the rule allows chains that don't include initializing a variable in a declaration or initializing a class field. Default is `false`. +### ignoreNonDeclaration -#### ignoreNonDeclaration +type: `boolean` -Examples of **correct** code for the `{ "ignoreNonDeclaration": true }` option: +default: `false` + +When set to `true`, the rule allows chains that don't include initializing a variable in a declaration or initializing a class field. + +Examples of **correct** code for this option set to `true`: ```js let a; @@ -86,7 +90,7 @@ const y = {}; x.one = y.one = 1; ``` -Examples of **incorrect** code for the `{ "ignoreNonDeclaration": true }` option: +Examples of **incorrect** code for this option set to `true`: ```js let a = b = "baz"; diff --git a/src/docs/guide/usage/linter/rules/eslint/no-undef.md b/src/docs/guide/usage/linter/rules/eslint/no-undef.md index 8a234c95434..48573eb2e79 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-undef.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-undef.md @@ -27,6 +27,18 @@ var foo = someFunction(); var bar = a + 1; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### typeof + +type: `boolean` + +default: `false` + +When set to `true`, warns on undefined variables used in a `typeof` expression. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-unneeded-ternary.md b/src/docs/guide/usage/linter/rules/eslint/no-unneeded-ternary.md index 7fe79cdb482..520ae98075d 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-unneeded-ternary.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-unneeded-ternary.md @@ -45,6 +45,22 @@ const isNo = answer !== 1; foo(bar || 1); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### defaultAssignment + +type: `boolean` + +default: `true` + +Whether to allow the default assignment pattern `x ? x : y`. + +When set to `false`, the rule also flags cases like `x ? x : y` and suggests using +the logical OR form `x || y` instead. When `true` (default), such default assignments +are allowed and not reported. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-unsafe-negation.md b/src/docs/guide/usage/linter/rules/eslint/no-unsafe-negation.md index f06b20fe3bc..8279895c81e 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-unsafe-negation.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-unsafe-negation.md @@ -45,11 +45,15 @@ if (!(key in object)) {} if (!(obj instanceof Ctor)) {} ``` -### Options +## Configuration -#### enforceForOrderingRelations +This rule accepts a configuration object with the following properties: -`{ type: boolean, default: false }` +### enforceForOrderingRelations + +type: `boolean` + +default: `false` The `enforceForOrderingRelations` option determines whether negation is allowed on the left-hand side of ordering relational operators (<, >, <=, >=). diff --git a/src/docs/guide/usage/linter/rules/eslint/no-unsafe-optional-chaining.md b/src/docs/guide/usage/linter/rules/eslint/no-unsafe-optional-chaining.md index e84164b97a6..f2d0ba9e6ba 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-unsafe-optional-chaining.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-unsafe-optional-chaining.md @@ -36,6 +36,19 @@ bar instanceof obj?.foo; // TypeError const { bar } = obj?.foo; // TypeError ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### disallowArithmeticOperators + +type: `boolean` + +default: `false` + +Disallow arithmetic operations on optional chaining expressions. +If this is true, this rule warns arithmetic operations on optional chaining expressions, which possibly result in NaN. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-useless-computed-key.md b/src/docs/guide/usage/linter/rules/eslint/no-useless-computed-key.md index c1106b11ae4..3b8f3d38e1a 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-useless-computed-key.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-useless-computed-key.md @@ -81,11 +81,15 @@ class Foo { } ``` -### Options +## Configuration -#### enforceForClassMembers +This rule accepts a configuration object with the following properties: -`{ type: boolean, default: true }` +### enforceForClassMembers + +type: `boolean` + +default: `true` The `enforceForClassMembers` option controls whether the rule applies to class members (methods and properties). diff --git a/src/docs/guide/usage/linter/rules/eslint/no-useless-rename.md b/src/docs/guide/usage/linter/rules/eslint/no-useless-rename.md index 89b0705efab..96cc9b63bcd 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-useless-rename.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-useless-rename.md @@ -39,6 +39,34 @@ const { bar: renamed } = obj; export { baz }; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### ignoreDestructuring + +type: `boolean` + +default: `false` + +When set to `true`, allows using the same name in destructurings. + +### ignoreExport + +type: `boolean` + +default: `false` + +When set to `true`, allows renaming exports to the same name. + +### ignoreImport + +type: `boolean` + +default: `false` + +When set to `true`, allows renaming imports to the same name. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-void.md b/src/docs/guide/usage/linter/rules/eslint/no-void.md index 44b244ce765..d48f7da73fd 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-void.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-void.md @@ -39,11 +39,15 @@ Examples of **correct** code for this rule: "foo.void = bar"; ``` -### Options +## Configuration -#### allowAsStatement +This rule accepts a configuration object with the following properties: -`{ type: boolean, default: false }` +### allowAsStatement + +type: `boolean` + +default: `false` If set to `true`, using `void` as a standalone statement is allowed. diff --git a/src/docs/guide/usage/linter/rules/eslint/prefer-promise-reject-errors.md b/src/docs/guide/usage/linter/rules/eslint/prefer-promise-reject-errors.md index caefc2cdd93..01d46f81d41 100644 --- a/src/docs/guide/usage/linter/rules/eslint/prefer-promise-reject-errors.md +++ b/src/docs/guide/usage/linter/rules/eslint/prefer-promise-reject-errors.md @@ -12,17 +12,15 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Require using Error objects as Promise rejection reasons +Require using Error objects as Promise rejection reasons. ### Why is this bad? -It is considered good practice to only pass instances of the built-in `Error` object to the `reject()` function for user-defined errors in Promises. `Error` objects automatically store a stack trace, which can be used to debug an error by determining where it came from. If a Promise is rejected with a non-`Error` value, it can be difficult to determine where the rejection occurred. - -### Options - -This rule takes one optional object argument: - -- `allowEmptyReject: true` (`false` by default) allows calls to `Promise.reject()` with no arguments. +It is considered good practice to only pass instances of the built-in `Error` object to the +`reject()` function for user-defined errors in Promises. `Error` objects automatically +store a stack trace, which can be used to debug an error by determining where it came +from. If a Promise is rejected with a non-`Error` value, it can be difficult to +determine where the rejection occurred. ### Examples @@ -59,6 +57,18 @@ var foo = getUnknownValue(); Promise.reject(foo); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowEmptyReject + +type: `boolean` + +default: `false` + +Whether to allow calls to `Promise.reject()` with no arguments. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/sort-imports.md b/src/docs/guide/usage/linter/rules/eslint/sort-imports.md index 1cef3fcaee4..fcab02cd36f 100644 --- a/src/docs/guide/usage/linter/rules/eslint/sort-imports.md +++ b/src/docs/guide/usage/linter/rules/eslint/sort-imports.md @@ -34,6 +34,52 @@ import e from "bar.js"; import d from "foo.js"; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowSeparatedGroups + +type: `boolean` + +default: `false` + +When `true`, the rule allows import groups separated by blank lines to be treated independently. + +### ignoreCase + +type: `boolean` + +default: `false` + +When `true`, the rule ignores case-sensitivity when sorting import names. + +### ignoreDeclarationSort + +type: `boolean` + +default: `false` + +When `true`, the rule ignores the sorting of import declarations (the order of `import` statements). + +### ignoreMemberSort + +type: `boolean` + +default: `false` + +When `true`, the rule ignores the sorting of import members within a single import declaration. + +### memberSyntaxSortOrder + +type: `array` + +Specifies the sort order of different import syntaxes. + +#### memberSyntaxSortOrder[n] + +type: `"none" | "all" | "multiple" | "single"` + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/eslint/sort-keys.md b/src/docs/guide/usage/linter/rules/eslint/sort-keys.md index 10c7372b825..d7db6ec6096 100644 --- a/src/docs/guide/usage/linter/rules/eslint/sort-keys.md +++ b/src/docs/guide/usage/linter/rules/eslint/sort-keys.md @@ -42,6 +42,50 @@ let myObj = { }; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowLineSeparatedGroups + +type: `boolean` + +default: `false` + +When true, groups of properties separated by a blank line are sorted independently. + +### caseSensitive + +type: `boolean` + +default: `true` + +Whether the sort comparison is case-sensitive (A < a when true). + +### minKeys + +type: `integer` + +default: `2` + +Minimum number of properties required in an object before sorting is enforced. + +### natural + +type: `boolean` + +default: `false` + +Use natural sort order so that, for example, "a2" comes before "a10". + +### sortOrder + +type: `"desc" | "asc"` + +default: `"asc"` + +Sorting order for keys. Accepts "asc" for ascending or "desc" for descending. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/import/no-anonymous-default-export.md b/src/docs/guide/usage/linter/rules/import/no-anonymous-default-export.md index 77a8f35feb9..0e383044e3b 100644 --- a/src/docs/guide/usage/linter/rules/import/no-anonymous-default-export.md +++ b/src/docs/guide/usage/linter/rules/import/no-anonymous-default-export.md @@ -67,33 +67,76 @@ export default new Foo(); export default foo(bar); ``` -### Options +By default, all types of anonymous default exports are forbidden, +but any types can be selectively allowed by toggling them on in the options. -This rule takes an object with the following properties: +## Configuration -- `allowArray`: `boolean` (default: `false`) - Allow anonymous array as default export. -- `allowArrowFunction`: `boolean` (default: `false`) - Allow anonymous arrow function as default export. -- `allowAnonymousClass`: `boolean` (default: `false`) - Allow anonymous class as default export. -- `allowAnonymousFunction`: `boolean` (default: `false`) - Allow anonymous function as default export. -- `allowCallExpression`: `boolean` (default: `true`) - Allow anonymous call expression as default export. -- `allowNew`: `boolean` (default: `false`) - Allow anonymous new expression as default export. -- `allowLiteral`: `boolean` (default: `false`) - Allow anonymous literal as default export. -- `allowObject`: `boolean` (default: `false`) - Allow anonymous object as default export. +This rule accepts a configuration object with the following properties: -By default, all types of anonymous default exports are forbidden, -but any types can be selectively allowed by toggling them on in the options. +### allowAnonymousClass -```json -"import/no-anonymous-default-export": ["error", { - "allowArray": false, - "allowArrowFunction": false, - "allowAnonymousClass": false, - "allowAnonymousFunction": false, - "allowCallExpression": true, - "allowNew": false, - "allowLiteral": false, - "allowObject": false -``` +type: `boolean` + +default: `false` + +Allow anonymous class as default export. + +### allowAnonymousFunction + +type: `boolean` + +default: `false` + +Allow anonymous function as default export. + +### allowArray + +type: `boolean` + +default: `false` + +Allow anonymous array as default export. + +### allowArrowFunction + +type: `boolean` + +default: `false` + +Allow anonymous arrow function as default export. + +### allowCallExpression + +type: `boolean` + +default: `true` + +Allow anonymous call expression as default export. + +### allowLiteral + +type: `boolean` + +default: `false` + +Allow anonymous literal as default export. + +### allowNew + +type: `boolean` + +default: `false` + +Allow anonymous new expression as default export. + +### allowObject + +type: `boolean` + +default: `false` + +Allow anonymous object as default export. ## How to use diff --git a/src/docs/guide/usage/linter/rules/import/no-commonjs.md b/src/docs/guide/usage/linter/rules/import/no-commonjs.md index f98c3e0a438..c86901ff3ae 100644 --- a/src/docs/guide/usage/linter/rules/import/no-commonjs.md +++ b/src/docs/guide/usage/linter/rules/import/no-commonjs.md @@ -50,21 +50,24 @@ try { } catch (error) {} ``` -### Allow require +## Configuration -If `allowRequire` option is set to `true`, `require` calls are valid: +This rule accepts a configuration object with the following properties: -```js -var mod = require("./mod"); -``` +### allowConditionalRequire -but `module.exports` is reported as usual. +type: `boolean` -### Allow conditional require +default: `true` -By default, conditional requires are allowed, If the `allowConditionalRequire` option is set to `false`, they will be reported. +When set to `true`, allows conditional `require()` calls (e.g., inside `if` statements or try-catch blocks). +This is useful for places where you need to conditionally load via commonjs requires if ESM imports are not supported. -### Allow primitive modules +### allowPrimitiveModules + +type: `boolean` + +default: `false` If `allowPrimitiveModules` option is set to true, the following is valid: @@ -82,6 +85,20 @@ module.exports = { x: "y" }; exports.z = function bark() {/* ... */}; ``` +### allowRequire + +type: `boolean` + +default: `false` + +If set to `true`, `require` calls are valid: + +```js +var mod = require("./mod"); +``` + +but `module.exports` is reported as usual. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/import/no-unassigned-import.md b/src/docs/guide/usage/linter/rules/import/no-unassigned-import.md index baa1ccbc2e2..9fdacaf0c4f 100644 --- a/src/docs/guide/usage/linter/rules/import/no-unassigned-import.md +++ b/src/docs/guide/usage/linter/rules/import/no-unassigned-import.md @@ -47,6 +47,20 @@ const { foo: bar } = require("foo"); bar(require("foo")); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allow + +type: `string[]` + +default: `[]` + +A list of glob patterns to allow unassigned imports for specific modules. +For example: +`{ "allow": ["*.css"] }` will allow unassigned imports for any module ending with `.css`. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/jest/max-expects.md b/src/docs/guide/usage/linter/rules/jest/max-expects.md index e13adf09e5d..9a315f6ca1e 100644 --- a/src/docs/guide/usage/linter/rules/jest/max-expects.md +++ b/src/docs/guide/usage/linter/rules/jest/max-expects.md @@ -19,7 +19,7 @@ the maximum number of assertions is exceeded. ### Why is this bad? This rule enforces a maximum number of `expect()` calls. -The following patterns are considered warnings (with the default option of `{ "max": 5 }`): +The following patterns are considered warnings (with the default max of 5): ### Examples @@ -45,6 +45,18 @@ it("should not pass", () => { }); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### max + +type: `integer` + +default: `5` + +Maximum number of `expect()` assertion calls allowed within a single test. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/jest/no-deprecated-functions.md b/src/docs/guide/usage/linter/rules/jest/no-deprecated-functions.md index e346c0ea448..0fa9adfe593 100644 --- a/src/docs/guide/usage/linter/rules/jest/no-deprecated-functions.md +++ b/src/docs/guide/usage/linter/rules/jest/no-deprecated-functions.md @@ -32,8 +32,8 @@ This function was replaced with `expect.extend` in Jest 17 and removed in Jest 2 These functions were replaced in Jest 21 and removed in Jest 26. -Originally, the `requireActual` & `requireMock` the `requireActual`& -`requireMock` functions were placed onto the `require` function. +Originally, the `requireActual` and `requireMock` functions were placed +onto the `require` function. These functions were later moved onto the `jest` object in order to be easier for type checkers to handle, and their use via `require` deprecated. Finally, @@ -61,6 +61,24 @@ jest.resetModuleRegistry; // since Jest 15 jest.addMatchers; // since Jest 17 ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### jest + +type: `object` + +Jest configuration options. + +#### jest.version + +type: `string` + +default: `"29"` + +The version of Jest being used. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/jest/no-hooks.md b/src/docs/guide/usage/linter/rules/jest/no-hooks.md index 69539aed79c..c3df41da6ba 100644 --- a/src/docs/guide/usage/linter/rules/jest/no-hooks.md +++ b/src/docs/guide/usage/linter/rules/jest/no-hooks.md @@ -61,6 +61,18 @@ describe("foo", () => { }); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allow + +type: `string[]` + +default: `[]` + +An array of hook function names that are permitted for use. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/jest/no-large-snapshots.md b/src/docs/guide/usage/linter/rules/jest/no-large-snapshots.md index c925c348c49..c139f3047a5 100644 --- a/src/docs/guide/usage/linter/rules/jest/no-large-snapshots.md +++ b/src/docs/guide/usage/linter/rules/jest/no-large-snapshots.md @@ -93,6 +93,35 @@ line 4 `; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowedSnapshots + +type: `Record` + +default: `{}` + +A map of snapshot file paths to arrays of snapshot names that are allowed to exceed the size limit. +Snapshot names can be specified as regular expressions. + +### inlineMaxSize + +type: `integer` + +default: `50` + +Maximum number of lines allowed for inline snapshots. + +### maxSize + +type: `integer` + +default: `50` + +Maximum number of lines allowed for external snapshot files. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/jest/require-hook.md b/src/docs/guide/usage/linter/rules/jest/require-hook.md index aeaf21fc59b..c5a446e4db3 100644 --- a/src/docs/guide/usage/linter/rules/jest/require-hook.md +++ b/src/docs/guide/usage/linter/rules/jest/require-hook.md @@ -128,6 +128,18 @@ afterEach(() => { }); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowedFunctionCalls + +type: `string[]` + +default: `[]` + +An array of function names that are allowed to be called outside of hooks. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/jest/require-top-level-describe.md b/src/docs/guide/usage/linter/rules/jest/require-top-level-describe.md index 72fb20bd6e2..e1d551ddf5d 100644 --- a/src/docs/guide/usage/linter/rules/jest/require-top-level-describe.md +++ b/src/docs/guide/usage/linter/rules/jest/require-top-level-describe.md @@ -63,21 +63,17 @@ describe("test suite", () => { }); ``` -### Options +## Configuration -You can also enforce a limit on the number of describes allowed at the top-level -using the `maxNumberOfTopLevelDescribes` option: +This rule accepts a configuration object with the following properties: -```json -{ - "jest/require-top-level-describe": [ - "error", - { - "maxNumberOfTopLevelDescribes": 2 - } - ] -} -``` +### maxNumberOfTopLevelDescribes + +type: `integer` + +default: `18446744073709551615` + +The maximum number of top-level `describe` blocks allowed in a test file. ## How to use diff --git a/src/docs/guide/usage/linter/rules/jest/valid-title.md b/src/docs/guide/usage/linter/rules/jest/valid-title.md index a44f705fcb4..52b0acdaee2 100644 --- a/src/docs/guide/usage/linter/rules/jest/valid-title.md +++ b/src/docs/guide/usage/linter/rules/jest/valid-title.md @@ -15,7 +15,7 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Checks that the titles of Jest blocks are valid. +Checks that the titles of Jest and Vitest blocks are valid. Titles must be: @@ -59,6 +59,7 @@ interface Options { ignoreSpaces?: boolean; ignoreTypeOfTestName?: boolean; ignoreTypeOfDescribeName?: boolean; + allowArguments?: boolean; disallowedWords?: string[]; mustNotMatch?: Partial> | string; mustMatch?: Partial> | string; diff --git a/src/docs/guide/usage/linter/rules/jsdoc/check-tag-names.md b/src/docs/guide/usage/linter/rules/jsdoc/check-tag-names.md index acc12bcaedb..079462d99f6 100644 --- a/src/docs/guide/usage/linter/rules/jsdoc/check-tag-names.md +++ b/src/docs/guide/usage/linter/rules/jsdoc/check-tag-names.md @@ -39,7 +39,7 @@ Examples of **correct** code for this rule: /** @param */ ``` -### Options +### Settings Configuration for allowed tags is done via [`settings.jsdoc.tagNamePreference`](/docs/guide/usage/linter/config-file-reference.html#settings-jsdoc-tagnamepreference). There is no CLI-only parameter for this rule. @@ -74,6 +74,39 @@ Examples of correct code for this rule with the above configuration, adding the */ ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### definedTags + +type: `string[]` + +default: `[]` + +Additional tag names to allow. + +### jsxTags + +type: `boolean` + +default: `false` + +Whether to allow JSX-related tags: + +- `jsx` +- `jsxFrag` +- `jsxImportSource` +- `jsxRuntime` + +### typed + +type: `boolean` + +default: `false` + +If typed is `true`, disallow tags that are unnecessary/duplicative of TypeScript functionality. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/jsdoc/empty-tags.md b/src/docs/guide/usage/linter/rules/jsdoc/empty-tags.md index 4507ba5f7ad..3d99f6d3794 100644 --- a/src/docs/guide/usage/linter/rules/jsdoc/empty-tags.md +++ b/src/docs/guide/usage/linter/rules/jsdoc/empty-tags.md @@ -55,6 +55,18 @@ Examples of **correct** code for this rule: /** @private */ ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### tags + +type: `string[]` + +default: `[]` + +Additional tags to check for their descriptions. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/jsdoc/no-defaults.md b/src/docs/guide/usage/linter/rules/jsdoc/no-defaults.md index 93b380e0553..89d92d4ac68 100644 --- a/src/docs/guide/usage/linter/rules/jsdoc/no-defaults.md +++ b/src/docs/guide/usage/linter/rules/jsdoc/no-defaults.md @@ -39,6 +39,18 @@ function quux(foo) {} function quux(foo) {} ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### noOptionalParamNames + +type: `boolean` + +default: `false` + +If true, report the presence of optional param names (square brackets) on `@param` tags. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/jsdoc/require-yields.md b/src/docs/guide/usage/linter/rules/jsdoc/require-yields.md index e378c53d74b..b869cb8f42d 100644 --- a/src/docs/guide/usage/linter/rules/jsdoc/require-yields.md +++ b/src/docs/guide/usage/linter/rules/jsdoc/require-yields.md @@ -44,6 +44,34 @@ function* quux(foo) { } ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### exemptedBy + +type: `string[]` + +default: `["inheritdoc"]` + +Functions with these tags will be exempted from the lint rule. + +### forceRequireYields + +type: `boolean` + +default: `false` + +When `true`, all generator functions must have a `@yields` tag, even if they don't yield a value or have an empty body. + +### withGeneratorTag + +type: `boolean` + +default: `false` + +When `true`, require `@yields` when a `@generator` tag is present. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/oxc/no-async-endpoint-handlers.md b/src/docs/guide/usage/linter/rules/oxc/no-async-endpoint-handlers.md index 509d8c5664c..0f6305a8c58 100644 --- a/src/docs/guide/usage/linter/rules/oxc/no-async-endpoint-handlers.md +++ b/src/docs/guide/usage/linter/rules/oxc/no-async-endpoint-handlers.md @@ -105,16 +105,15 @@ app.get("/user", (req, res, next) => asyncHandler(req, res).catch(next)); ## Configuration -This rule takes the following configuration: - -```ts -type NoAsyncEndpointHandlersConfig = { - /** - * An array of names that are allowed to be async. - */ - allowedNames?: string[]; -}; -``` +This rule accepts a configuration object with the following properties: + +### allowedNames + +type: `string[]` + +default: `[]` + +An array of names that are allowed to be async. ## How to use diff --git a/src/docs/guide/usage/linter/rules/oxc/no-barrel-file.md b/src/docs/guide/usage/linter/rules/oxc/no-barrel-file.md index 258d84e279b..04dbcdff130 100644 --- a/src/docs/guide/usage/linter/rules/oxc/no-barrel-file.md +++ b/src/docs/guide/usage/linter/rules/oxc/no-barrel-file.md @@ -15,7 +15,7 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin Disallow the use of barrel files where the file contains `export *` statements, and the total number of modules exceed a threshold. -The default threshold is 100; +The default threshold is 100. ### Why is this bad? @@ -45,6 +45,19 @@ Valid: export { foo } from "foo"; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### threshold + +type: `integer` + +default: `100` + +The maximum number of modules that can be re-exported via `export *` +before the rule is triggered. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/oxc/no-map-spread.md b/src/docs/guide/usage/linter/rules/oxc/no-map-spread.md index 192d5e2b74c..aae0e05a5ae 100644 --- a/src/docs/guide/usage/linter/rules/oxc/no-map-spread.md +++ b/src/docs/guide/usage/linter/rules/oxc/no-map-spread.md @@ -203,6 +203,54 @@ function UsersTable({ users }) { - [ECMA262 - Object spread evaluation semantics](https://262.ecma-international.org/15.0/index.html#sec-runtime-semantics-propertydefinitionevaluation) - [JSPerf - `concat` vs array spread performance](https://jsperf.app/pihevu) +## Configuration + +This rule accepts a configuration object with the following properties: + +### ignoreArgs + +type: `boolean` + +default: `true` + +Ignore maps on arrays passed as parameters to a function. + +This option is enabled by default to better avoid false positives. It +comes at the cost of potentially missing spreads that are inefficient. +We recommend turning this off in your `.oxlintrc.json` files. + +#### Examples + +Examples of **incorrect** code for this rule when `ignoreArgs` is `true`: + +```ts +/* "oxc/no-map-spread": ["error", { "ignoreArgs": true }] */ +function foo(arr) { + let arr2 = arr.filter(x => x.a > 0); + return arr2.map(x => ({ ...x })); +} +``` + +Examples of **correct** code for this rule when `ignoreArgs` is `true`: + +```ts +/* "oxc/no-map-spread": ["error", { "ignoreArgs": true }] */ +function foo(arr) { + return arr.map(x => ({ ...x })); +} +``` + +### ignoreRereads + +type: `boolean` + +default: `true` + +Ignore mapped arrays that are re-read after the `map` call. + +Re-used arrays may rely on shallow copying behavior to avoid mutations. +In these cases, `Object.assign` is not really more performant than spreads. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/oxc/no-optional-chaining.md b/src/docs/guide/usage/linter/rules/oxc/no-optional-chaining.md index 3706e86f308..060dd869644 100644 --- a/src/docs/guide/usage/linter/rules/oxc/no-optional-chaining.md +++ b/src/docs/guide/usage/linter/rules/oxc/no-optional-chaining.md @@ -32,23 +32,19 @@ const foo = obj?.foo; obj.fn?.(); ``` -### Options +## Configuration -```json -{ - "rules": { - "no-optional-chaining": [ - "error", - { - "message": "Our output target is ES2016, and optional chaining results in verbose - helpers and should be avoided." - } - ] - } -} -``` +This rule accepts a configuration object with the following properties: + +### message + +type: `string` + +default: `""` -- `message`: A custom help message to display when optional chaining is found. +A custom help message to display when optional chaining is found. +For example, "Our output target is ES2016, and optional chaining results in verbose +helpers and should be avoided." ## How to use diff --git a/src/docs/guide/usage/linter/rules/oxc/no-rest-spread-properties.md b/src/docs/guide/usage/linter/rules/oxc/no-rest-spread-properties.md index 8eb6b8c1396..ea08a713088 100644 --- a/src/docs/guide/usage/linter/rules/oxc/no-rest-spread-properties.md +++ b/src/docs/guide/usage/linter/rules/oxc/no-rest-spread-properties.md @@ -31,24 +31,25 @@ let { x, ...y } = z; let z = { x, ...y }; ``` -### Options +## Configuration -```json -{ - "rules": { - "no-rest-spread-properties": [ - "error", - { - "objectSpreadMessage": "Object spread properties are not allowed.", - "objectRestMessage": "Object rest properties are not allowed." - } - ] - } -} -``` +This rule accepts a configuration object with the following properties: + +### objectRestMessage + +type: `string` + +default: `""` + +A message to display when object rest properties are found. + +### objectSpreadMessage + +type: `string` + +default: `""` -- `objectSpreadMessage`: A message to display when object spread properties are found. -- `objectRestMessage`: A message to display when object rest properties are found. +A message to display when object spread properties are found. ## How to use diff --git a/src/docs/guide/usage/linter/rules/promise/catch-or-return.md b/src/docs/guide/usage/linter/rules/promise/catch-or-return.md index c571d3e4b96..ffab556493b 100644 --- a/src/docs/guide/usage/linter/rules/promise/catch-or-return.md +++ b/src/docs/guide/usage/linter/rules/promise/catch-or-return.md @@ -40,6 +40,34 @@ function doSomethingElse() { } ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowFinally + +type: `boolean` + +default: `false` + +Whether to allow `finally()` as a termination method. + +### allowThen + +type: `boolean` + +default: `false` + +Whether to allow `then()` with two arguments as a termination method. + +### terminationMethod + +type: `string[]` + +default: `["catch"]` + +List of allowed termination methods (e.g., `catch`, `done`). + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/promise/no-return-wrap.md b/src/docs/guide/usage/linter/rules/promise/no-return-wrap.md index 73d4d37f058..2c2f60f7ced 100644 --- a/src/docs/guide/usage/linter/rules/promise/no-return-wrap.md +++ b/src/docs/guide/usage/linter/rules/promise/no-return-wrap.md @@ -95,14 +95,17 @@ myPromise().catch( myPromise().finally(() => 4); ``` -### Options +## Configuration -#### allowReject +This rule accepts a configuration object with the following properties: -`{ type: boolean, default: false }` +### allowReject -The `allowReject` turns off the checking of returning a call `Promise.reject` inside a -promise handler. +type: `boolean` + +default: `false` + +`allowReject` allows returning `Promise.reject` inside a promise handler. With `allowReject` set to `true` the following are examples of correct code: diff --git a/src/docs/guide/usage/linter/rules/promise/prefer-await-to-then.md b/src/docs/guide/usage/linter/rules/promise/prefer-await-to-then.md index 78ce1f2386c..b90d12d3120 100644 --- a/src/docs/guide/usage/linter/rules/promise/prefer-await-to-then.md +++ b/src/docs/guide/usage/linter/rules/promise/prefer-await-to-then.md @@ -46,6 +46,18 @@ async function hi() { } ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### strict + +type: `boolean` + +default: `false` + +If true, enforces the rule even after an `await` or `yield` expression. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/react/self-closing-comp.md b/src/docs/guide/usage/linter/rules/react/self-closing-comp.md index 7bf17e55657..2a67454fc28 100644 --- a/src/docs/guide/usage/linter/rules/react/self-closing-comp.md +++ b/src/docs/guide/usage/linter/rules/react/self-closing-comp.md @@ -48,6 +48,26 @@ const welem = ; const dom_elem =
; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### component + +type: `boolean` + +default: `true` + +Whether to enforce self-closing for custom components. + +### html + +type: `boolean` + +default: `true` + +Whether to enforce self-closing for native HTML elements. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/typescript/await-thenable.md b/src/docs/guide/usage/linter/rules/typescript/await-thenable.md index 2e5cc079374..4f2997efa80 100644 --- a/src/docs/guide/usage/linter/rules/typescript/await-thenable.md +++ b/src/docs/guide/usage/linter/rules/typescript/await-thenable.md @@ -69,7 +69,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/await-thenable +oxlint --type-aware --deny typescript/await-thenable ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/explicit-module-boundary-types.md b/src/docs/guide/usage/linter/rules/typescript/explicit-module-boundary-types.md index 03d12187bd9..485cd7c8988 100644 --- a/src/docs/guide/usage/linter/rules/typescript/explicit-module-boundary-types.md +++ b/src/docs/guide/usage/linter/rules/typescript/explicit-module-boundary-types.md @@ -75,6 +75,65 @@ function test() { } ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowArgumentsExplicitlyTypedAsAny + +type: `boolean` + +default: `false` + +Whether to ignore arguments that are explicitly typed as `any`. + +### allowDirectConstAssertionInArrowFunctions + +type: `boolean` + +default: `true` + +Whether to ignore return type annotations on body-less arrow functions +that return an `as const` type assertion. You must still type the +parameters of the function. + +### allowHigherOrderFunctions + +type: `boolean` + +default: `true` + +Whether to ignore return type annotations on functions immediately +returning another function expression. You must still type the +parameters of the function. + +### allowOverloadFunctions + +type: `boolean` + +default: `false` + +Whether to ignore return type annotations on functions with overload +signatures. + +### allowTypedFunctionExpressions + +type: `boolean` + +default: `true` + +Whether to ignore type annotations on the variable of a function +expression. + +### allowedNames + +type: `string[]` + +default: `[]` + +An array of function/method names that will not have their arguments or +return values checked. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/typescript/no-array-delete.md b/src/docs/guide/usage/linter/rules/typescript/no-array-delete.md index 7032c5a9a6b..94599f34f9f 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-array-delete.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-array-delete.md @@ -57,7 +57,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-array-delete +oxlint --type-aware --deny typescript/no-array-delete ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-base-to-string.md b/src/docs/guide/usage/linter/rules/typescript/no-base-to-string.md index fb6c64cb010..104e99a1c28 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-base-to-string.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-base-to-string.md @@ -68,7 +68,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-base-to-string +oxlint --type-aware --deny typescript/no-base-to-string ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-confusing-void-expression.md b/src/docs/guide/usage/linter/rules/typescript/no-confusing-void-expression.md index 12a5fd0d36b..67893d0c809 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-confusing-void-expression.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-confusing-void-expression.md @@ -69,7 +69,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-confusing-void-expression +oxlint --type-aware --deny typescript/no-confusing-void-expression ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-duplicate-type-constituents.md b/src/docs/guide/usage/linter/rules/typescript/no-duplicate-type-constituents.md index ef7ca3b3296..20f52c7b90b 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-duplicate-type-constituents.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-duplicate-type-constituents.md @@ -70,7 +70,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-duplicate-type-constituents +oxlint --type-aware --deny typescript/no-duplicate-type-constituents ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-empty-interface.md b/src/docs/guide/usage/linter/rules/typescript/no-empty-interface.md index ab76e863c7a..914300104f5 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-empty-interface.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-empty-interface.md @@ -40,6 +40,18 @@ interface Bar extends Foo { } ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowSingleExtends + +type: `boolean` + +default: `false` + +When set to `true`, allows empty interfaces that extend a single interface. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/typescript/no-empty-object-type.md b/src/docs/guide/usage/linter/rules/typescript/no-empty-object-type.md index 709f87e6a83..8ebeb5c09c3 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-empty-object-type.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-empty-object-type.md @@ -57,6 +57,42 @@ interface InterfaceWith { type TypeWith = { property: boolean }; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowInterfaces + +type: `"never" | "always" | "with-single-extends"` + +Whether to allow empty interfaces. + +Allowed values are: + +- `'always'`: to always allow interfaces with no fields +- `'never'` _(default)_: to never allow interfaces with no fields +- `'with-single-extends'`: to allow empty interfaces that `extend` from a single base interface + +Examples of **correct** code for this rule with `{ allowInterfaces: 'with-single-extends' }`: + +```ts +interface Base { + value: boolean; +} +interface Derived extends Base {} +``` + +### allowObjectTypes + +type: `"never" | "always"` + +Whether to allow empty object type literals. + +Allowed values are: + +- `'always'`: to always allow object type literals with no fields +- `'never'` _(default)_: to never allow object type literals with no fields + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/typescript/no-explicit-any.md b/src/docs/guide/usage/linter/rules/typescript/no-explicit-any.md index 921dfef3fc6..e1c605d3c5c 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-explicit-any.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-explicit-any.md @@ -57,17 +57,25 @@ function greet(param: Array): string {} function greet(param: Array): Array {} ``` -### Options +## Configuration -#### `ignoreRestArgs` +This rule accepts a configuration object with the following properties: -A boolean to specify if arrays from the rest operator are considered ok. `false` by -default. +### fixToUnknown -#### `fixToUnknown` +type: `boolean` + +default: `false` Whether to enable auto-fixing in which the `any` type is converted to the `unknown` type. -`false` by default. + +### ignoreRestArgs + +type: `boolean` + +default: `false` + +Whether to ignore rest parameter arrays. ## How to use diff --git a/src/docs/guide/usage/linter/rules/typescript/no-floating-promises.md b/src/docs/guide/usage/linter/rules/typescript/no-floating-promises.md index b93d601fdac..f7d23ba2136 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-floating-promises.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-floating-promises.md @@ -93,7 +93,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-floating-promises +oxlint --type-aware --deny typescript/no-floating-promises ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-for-in-array.md b/src/docs/guide/usage/linter/rules/typescript/no-for-in-array.md index 64f97806f0d..3c1ac0af9a8 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-for-in-array.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-for-in-array.md @@ -77,7 +77,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-for-in-array +oxlint --type-aware --deny typescript/no-for-in-array ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-implied-eval.md b/src/docs/guide/usage/linter/rules/typescript/no-implied-eval.md index 7582a48fa62..11c114ee467 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-implied-eval.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-implied-eval.md @@ -70,7 +70,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-implied-eval +oxlint --type-aware --deny typescript/no-implied-eval ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-meaningless-void-operator.md b/src/docs/guide/usage/linter/rules/typescript/no-meaningless-void-operator.md index d0d8154dc14..227bde6a787 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-meaningless-void-operator.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-meaningless-void-operator.md @@ -70,7 +70,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-meaningless-void-operator +oxlint --type-aware --deny typescript/no-meaningless-void-operator ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-misused-promises.md b/src/docs/guide/usage/linter/rules/typescript/no-misused-promises.md index 4ff43be020d..d7bf9319199 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-misused-promises.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-misused-promises.md @@ -71,7 +71,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-misused-promises +oxlint --type-aware --deny typescript/no-misused-promises ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-misused-spread.md b/src/docs/guide/usage/linter/rules/typescript/no-misused-spread.md index 5559ba26dac..c2485141583 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-misused-spread.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-misused-spread.md @@ -72,7 +72,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-misused-spread +oxlint --type-aware --deny typescript/no-misused-spread ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-mixed-enums.md b/src/docs/guide/usage/linter/rules/typescript/no-mixed-enums.md index b2e337e96ff..895427023a4 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-mixed-enums.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-mixed-enums.md @@ -74,7 +74,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-mixed-enums +oxlint --type-aware --deny typescript/no-mixed-enums ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-redundant-type-constituents.md b/src/docs/guide/usage/linter/rules/typescript/no-redundant-type-constituents.md index ecab8108aaa..46dd9f4e0a2 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-redundant-type-constituents.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-redundant-type-constituents.md @@ -71,7 +71,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-redundant-type-constituents +oxlint --type-aware --deny typescript/no-redundant-type-constituents ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-boolean-literal-compare.md b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-boolean-literal-compare.md index 547464ec0b2..ef0ac230cf2 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-boolean-literal-compare.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-boolean-literal-compare.md @@ -77,7 +77,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unnecessary-boolean-literal-compare +oxlint --type-aware --deny typescript/no-unnecessary-boolean-literal-compare ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-template-expression.md b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-template-expression.md index c2428cbe397..d256017e900 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-template-expression.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-template-expression.md @@ -69,7 +69,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unnecessary-template-expression +oxlint --type-aware --deny typescript/no-unnecessary-template-expression ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-arguments.md b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-arguments.md index c24c89d7662..dd29dabb020 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-arguments.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-arguments.md @@ -82,7 +82,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unnecessary-type-arguments +oxlint --type-aware --deny typescript/no-unnecessary-type-arguments ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-assertion.md b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-assertion.md index 51d7ff0484c..5bff3ec3f79 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-assertion.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-assertion.md @@ -67,7 +67,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unnecessary-type-assertion +oxlint --type-aware --deny typescript/no-unnecessary-type-assertion ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-argument.md b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-argument.md index 155bc315c45..49157a4ff5d 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-argument.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-argument.md @@ -70,7 +70,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unsafe-argument +oxlint --type-aware --deny typescript/no-unsafe-argument ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-assignment.md b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-assignment.md index a94695c992d..14e7fcaa212 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-assignment.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-assignment.md @@ -76,7 +76,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unsafe-assignment +oxlint --type-aware --deny typescript/no-unsafe-assignment ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-call.md b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-call.md index 81acbe6af13..08bed5dcade 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-call.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-call.md @@ -68,7 +68,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unsafe-call +oxlint --type-aware --deny typescript/no-unsafe-call ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-enum-comparison.md b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-enum-comparison.md index ba99919e557..6d406751ad6 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-enum-comparison.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-enum-comparison.md @@ -80,7 +80,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unsafe-enum-comparison +oxlint --type-aware --deny typescript/no-unsafe-enum-comparison ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-member-access.md b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-member-access.md index 53517ae6ef3..a0546910041 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-member-access.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-member-access.md @@ -68,7 +68,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unsafe-member-access +oxlint --type-aware --deny typescript/no-unsafe-member-access ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-return.md b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-return.md index 5d7c20ebb19..b9f1af4c94c 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-return.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-return.md @@ -75,7 +75,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unsafe-return +oxlint --type-aware --deny typescript/no-unsafe-return ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-type-assertion.md b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-type-assertion.md index 75f5f0831fb..a4fd793cd29 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-type-assertion.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-type-assertion.md @@ -73,7 +73,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unsafe-type-assertion +oxlint --type-aware --deny typescript/no-unsafe-type-assertion ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-unary-minus.md b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-unary-minus.md index 0d5ef454e1d..7a0f789e68d 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-unary-minus.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-unary-minus.md @@ -76,7 +76,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/no-unsafe-unary-minus +oxlint --type-aware --deny typescript/no-unsafe-unary-minus ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/non-nullable-type-assertion-style.md b/src/docs/guide/usage/linter/rules/typescript/non-nullable-type-assertion-style.md index 076da954753..00e3e69756b 100644 --- a/src/docs/guide/usage/linter/rules/typescript/non-nullable-type-assertion-style.md +++ b/src/docs/guide/usage/linter/rules/typescript/non-nullable-type-assertion-style.md @@ -75,7 +75,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/non-nullable-type-assertion-style +oxlint --type-aware --deny typescript/non-nullable-type-assertion-style ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/only-throw-error.md b/src/docs/guide/usage/linter/rules/typescript/only-throw-error.md index 1d7a92e594e..54d49c243c5 100644 --- a/src/docs/guide/usage/linter/rules/typescript/only-throw-error.md +++ b/src/docs/guide/usage/linter/rules/typescript/only-throw-error.md @@ -75,7 +75,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/only-throw-error +oxlint --type-aware --deny typescript/only-throw-error ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/prefer-promise-reject-errors.md b/src/docs/guide/usage/linter/rules/typescript/prefer-promise-reject-errors.md index 6d6f9797a4b..7af160a8f24 100644 --- a/src/docs/guide/usage/linter/rules/typescript/prefer-promise-reject-errors.md +++ b/src/docs/guide/usage/linter/rules/typescript/prefer-promise-reject-errors.md @@ -75,7 +75,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/prefer-promise-reject-errors +oxlint --type-aware --deny typescript/prefer-promise-reject-errors ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/prefer-reduce-type-parameter.md b/src/docs/guide/usage/linter/rules/typescript/prefer-reduce-type-parameter.md index c3a727995df..1cdf346ffb5 100644 --- a/src/docs/guide/usage/linter/rules/typescript/prefer-reduce-type-parameter.md +++ b/src/docs/guide/usage/linter/rules/typescript/prefer-reduce-type-parameter.md @@ -76,7 +76,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/prefer-reduce-type-parameter +oxlint --type-aware --deny typescript/prefer-reduce-type-parameter ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/prefer-return-this-type.md b/src/docs/guide/usage/linter/rules/typescript/prefer-return-this-type.md index 0e951ebc322..a40f09efeb6 100644 --- a/src/docs/guide/usage/linter/rules/typescript/prefer-return-this-type.md +++ b/src/docs/guide/usage/linter/rules/typescript/prefer-return-this-type.md @@ -95,7 +95,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/prefer-return-this-type +oxlint --type-aware --deny typescript/prefer-return-this-type ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/promise-function-async.md b/src/docs/guide/usage/linter/rules/typescript/promise-function-async.md index 750fcedf68e..7aaedd52ca3 100644 --- a/src/docs/guide/usage/linter/rules/typescript/promise-function-async.md +++ b/src/docs/guide/usage/linter/rules/typescript/promise-function-async.md @@ -87,7 +87,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/promise-function-async +oxlint --type-aware --deny typescript/promise-function-async ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/related-getter-setter-pairs.md b/src/docs/guide/usage/linter/rules/typescript/related-getter-setter-pairs.md index 654b768e9c7..4db4672b0c9 100644 --- a/src/docs/guide/usage/linter/rules/typescript/related-getter-setter-pairs.md +++ b/src/docs/guide/usage/linter/rules/typescript/related-getter-setter-pairs.md @@ -89,7 +89,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/related-getter-setter-pairs +oxlint --type-aware --deny typescript/related-getter-setter-pairs ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/require-array-sort-compare.md b/src/docs/guide/usage/linter/rules/typescript/require-array-sort-compare.md index fc8d7dc92bb..4d7e8b9a2b4 100644 --- a/src/docs/guide/usage/linter/rules/typescript/require-array-sort-compare.md +++ b/src/docs/guide/usage/linter/rules/typescript/require-array-sort-compare.md @@ -78,7 +78,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/require-array-sort-compare +oxlint --type-aware --deny typescript/require-array-sort-compare ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/require-await.md b/src/docs/guide/usage/linter/rules/typescript/require-await.md index e386ecca635..d1add672e4e 100644 --- a/src/docs/guide/usage/linter/rules/typescript/require-await.md +++ b/src/docs/guide/usage/linter/rules/typescript/require-await.md @@ -91,7 +91,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/require-await +oxlint --type-aware --deny typescript/require-await ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/restrict-plus-operands.md b/src/docs/guide/usage/linter/rules/typescript/restrict-plus-operands.md index 0219fed191b..14aff7965b9 100644 --- a/src/docs/guide/usage/linter/rules/typescript/restrict-plus-operands.md +++ b/src/docs/guide/usage/linter/rules/typescript/restrict-plus-operands.md @@ -77,7 +77,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/restrict-plus-operands +oxlint --type-aware --deny typescript/restrict-plus-operands ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/restrict-template-expressions.md b/src/docs/guide/usage/linter/rules/typescript/restrict-template-expressions.md index 8b891ae7a10..148a7fca9d0 100644 --- a/src/docs/guide/usage/linter/rules/typescript/restrict-template-expressions.md +++ b/src/docs/guide/usage/linter/rules/typescript/restrict-template-expressions.md @@ -88,7 +88,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/restrict-template-expressions +oxlint --type-aware --deny typescript/restrict-template-expressions ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/return-await.md b/src/docs/guide/usage/linter/rules/typescript/return-await.md index 208ee4c3617..8cfd526148c 100644 --- a/src/docs/guide/usage/linter/rules/typescript/return-await.md +++ b/src/docs/guide/usage/linter/rules/typescript/return-await.md @@ -87,7 +87,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/return-await +oxlint --type-aware --deny typescript/return-await ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/strict-boolean-expressions.md b/src/docs/guide/usage/linter/rules/typescript/strict-boolean-expressions.md new file mode 100644 index 00000000000..4ba776ec872 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/strict-boolean-expressions.md @@ -0,0 +1,115 @@ + + + + +# typescript/strict-boolean-expressions + +
+ +💭 This rule requires type information. + + +🚧 An auto-fix is still under development. + +
+ +### What it does + +Disallow certain types in boolean expressions. + +### Why is this bad? + +Forbids usage of non-boolean types in expressions where a boolean is expected. +`boolean` and `never` types are always allowed. Additional types which are +considered safe in a boolean context can be configured via options. + +The following nodes are checked: + +- Arguments to the `!`, `&&`, and `||` operators +- The condition in a conditional expression (`cond ? x : y`) +- Conditions for `if`, `for`, `while`, and `do-while` statements. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +const str = "hello"; +if (str) { + console.log("string"); +} + +const num = 42; +if (num) { + console.log("number"); +} + +const obj = { foo: "bar" }; +if (obj) { + console.log("object"); +} + +declare const maybeString: string | undefined; +if (maybeString) { + console.log(maybeString); +} + +const result = str && num; +const ternary = str ? "yes" : "no"; +``` + +Examples of **correct** code for this rule: + +```ts +const str = "hello"; +if (str !== "") { + console.log("string"); +} + +const num = 42; +if (num !== 0) { + console.log("number"); +} + +const obj = { foo: "bar" }; +if (obj !== null) { + console.log("object"); +} + +declare const maybeString: string | undefined; +if (maybeString !== undefined) { + console.log(maybeString); +} + +const bool = true; +if (bool) { + console.log("boolean"); +} +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --type-aware --deny typescript/strict-boolean-expressions +``` + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/strict-boolean-expressions": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/typescript/switch-exhaustiveness-check.md b/src/docs/guide/usage/linter/rules/typescript/switch-exhaustiveness-check.md index fe302bdfe1c..aa2eebc7f7e 100644 --- a/src/docs/guide/usage/linter/rules/typescript/switch-exhaustiveness-check.md +++ b/src/docs/guide/usage/linter/rules/typescript/switch-exhaustiveness-check.md @@ -117,7 +117,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/switch-exhaustiveness-check +oxlint --type-aware --deny typescript/switch-exhaustiveness-check ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/triple-slash-reference.md b/src/docs/guide/usage/linter/rules/typescript/triple-slash-reference.md index 09cf14e7732..ff661ec1b02 100644 --- a/src/docs/guide/usage/linter/rules/typescript/triple-slash-reference.md +++ b/src/docs/guide/usage/linter/rules/typescript/triple-slash-reference.md @@ -30,6 +30,34 @@ Examples of **incorrect** code for this rule: globalThis.value; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### lib + +type: `"always" | "never"` + +default: `"always"` + +What to enforce for `/// ` references. + +### path + +type: `"always" | "never"` + +default: `"never"` + +What to enforce for `/// ` references. + +### types + +type: `"always" | "never" | "prefer-import"` + +default: `"prefer-import"` + +What to enforce for `/// ` references. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/typescript/unbound-method.md b/src/docs/guide/usage/linter/rules/typescript/unbound-method.md index 060cf4810e0..efa583dd2ec 100644 --- a/src/docs/guide/usage/linter/rules/typescript/unbound-method.md +++ b/src/docs/guide/usage/linter/rules/typescript/unbound-method.md @@ -106,7 +106,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/unbound-method +oxlint --type-aware --deny typescript/unbound-method ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/typescript/use-unknown-in-catch-callback-variable.md b/src/docs/guide/usage/linter/rules/typescript/use-unknown-in-catch-callback-variable.md index d624700c375..df22c14942e 100644 --- a/src/docs/guide/usage/linter/rules/typescript/use-unknown-in-catch-callback-variable.md +++ b/src/docs/guide/usage/linter/rules/typescript/use-unknown-in-catch-callback-variable.md @@ -96,7 +96,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ::: code-group ```bash [CLI] -oxlint --deny typescript/use-unknown-in-catch-callback-variable +oxlint --type-aware --deny typescript/use-unknown-in-catch-callback-variable ``` ```json [Config (.oxlintrc.json)] diff --git a/src/docs/guide/usage/linter/rules/unicorn/consistent-function-scoping.md b/src/docs/guide/usage/linter/rules/unicorn/consistent-function-scoping.md index 0dfced06b2a..7a9ec0c0c09 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/consistent-function-scoping.md +++ b/src/docs/guide/usage/linter/rules/unicorn/consistent-function-scoping.md @@ -63,23 +63,6 @@ export function doFoo(foo) { } ``` -### Options - -#### checkArrowFunctions - -`{ type: boolean, default: true }` - -Pass `"checkArrowFunctions": false` to disable linting of arrow functions. - -Example: - -```json -"unicorn/consistent-function-scoping": [ - "error", - { "checkArrowFunctions": false } -] -``` - ### Limitations This rule does not detect or remove extraneous code blocks inside of functions: @@ -118,6 +101,18 @@ function doFoo(FooComponent) { })(); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### checkArrowFunctions + +type: `boolean` + +default: `true` + +Whether to check scoping with arrow functions. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-array-sort.md b/src/docs/guide/usage/linter/rules/unicorn/no-array-sort.md index f6ec5eb19dd..493b1dd4b29 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-array-sort.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-array-sort.md @@ -36,16 +36,20 @@ Examples of **correct** code for this rule: const sorted = [...array].toSorted(); ``` -### Options +## Configuration -#### allowExpressionStatement +This rule accepts a configuration object with the following properties: -`{ type: boolean, default: true }` +### allowExpressionStatement -This rule allows `array.sort()` as an expression statement by default, -Pass allowExpressionStatement: false to forbid `Array#sort()` even if it's an expression statement. +type: `boolean` -Examples of **incorrect** code for this rule with the `{ "allowExpressionStatement": false }` option: +default: `true` + +When set to `true` (default), allows `array.sort()` as an expression statement. +Set to `false` to forbid `Array#sort()` even if it's an expression statement. + +Example of **incorrect** code for this rule with `allowExpressionStatement` set to `false`: ```js array.sort(); diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-instanceof-builtins.md b/src/docs/guide/usage/linter/rules/unicorn/no-instanceof-builtins.md index 6f3573e95fa..5f555ebac78 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-instanceof-builtins.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-instanceof-builtins.md @@ -42,6 +42,46 @@ if (Array.isArray(arr)) { … } if (el?.nodeType === 1) { … } ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### exclude + +type: `string[]` + +default: `[]` + +Constructor names to exclude from checking. + +### include + +type: `string[]` + +default: `[]` + +Additional constructor names to check beyond the default set. +Use this to extend the rule with additional constructors. + +### strategy + +type: `"strict" | "loose"` + +Controls which built-in constructors are checked. + +- `"loose"` (default): Only checks Array, Function, Error (if `useErrorIsError` is true), and primitive wrappers +- `"strict"`: Additionally checks Error types, collections, typed arrays, and other built-in constructors + +### useErrorIsError + +type: `boolean` + +default: `false` + +When `true`, checks `instanceof Error` and suggests using `Error.isError()` instead. +Requires [the `Error.isError()` function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/isError) +to be available. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-typeof-undefined.md b/src/docs/guide/usage/linter/rules/unicorn/no-typeof-undefined.md index c928b08392d..b4448f753e0 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-typeof-undefined.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-typeof-undefined.md @@ -35,6 +35,19 @@ Examples of **correct** code for this rule: foo === undefined; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### checkGlobalVariables + +type: `boolean` + +default: `false` + +If set to `true`, also report `typeof x === "undefined"` when `x` may be a global +variable that is not declared (commonly checked via `typeof foo === "undefined"`). + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-useless-undefined.md b/src/docs/guide/usage/linter/rules/unicorn/no-useless-undefined.md index a01f59eaf13..f4c36da2ece 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-useless-undefined.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-useless-undefined.md @@ -35,6 +35,26 @@ Examples of **correct** code for this rule: let foo; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### checkArguments + +type: `boolean` + +default: `true` + +Whether to check for useless `undefined` in function call arguments. + +### checkArrowFunctionBody + +type: `boolean` + +default: `true` + +Whether to check for useless `undefined` in arrow function bodies. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/unicorn/numeric-separators-style.md b/src/docs/guide/usage/linter/rules/unicorn/numeric-separators-style.md index 0ad594038d7..ad06369271d 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/numeric-separators-style.md +++ b/src/docs/guide/usage/linter/rules/unicorn/numeric-separators-style.md @@ -52,6 +52,105 @@ const valid = [ ]; ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### binary + +type: `object` + +Configuration for binary literals (e.g. `0b1010_0001` and bigint variants). +Controls how digits are grouped and when separators are applied. + +#### binary.groupLength + +type: `integer` + +The number of digits per group when inserting numeric separators. +For example, a `groupLength` of 3 formats `1234567` as `1_234_567`. + +#### binary.minimumDigits + +type: `integer` + +The minimum number of digits required before grouping is applied. +Values with fewer digits than this threshold will not be grouped. + +### hexadecimal + +type: `object` + +Configuration for hexadecimal literals (e.g. `0xAB_CD`, `0Xab_cd`, and bigint variants). +Controls how digits are grouped and when separators are applied. + +#### hexadecimal.groupLength + +type: `integer` + +The number of digits per group when inserting numeric separators. +For example, a `groupLength` of 3 formats `1234567` as `1_234_567`. + +#### hexadecimal.minimumDigits + +type: `integer` + +The minimum number of digits required before grouping is applied. +Values with fewer digits than this threshold will not be grouped. + +### number + +type: `object` + +Configuration for decimal numbers (integers, fraction parts, and exponents). +Controls how digits are grouped and when separators are applied. + +#### number.groupLength + +type: `integer` + +The number of digits per group when inserting numeric separators. +For example, a `groupLength` of 3 formats `1234567` as `1_234_567`. + +#### number.minimumDigits + +type: `integer` + +The minimum number of digits required before grouping is applied. +Values with fewer digits than this threshold will not be grouped. + +### octal + +type: `object` + +Configuration for octal literals (e.g. `0o1234_5670` and bigint variants). +Controls how digits are grouped and when separators are applied. + +#### octal.groupLength + +type: `integer` + +The number of digits per group when inserting numeric separators. +For example, a `groupLength` of 3 formats `1234567` as `1_234_567`. + +#### octal.minimumDigits + +type: `integer` + +The minimum number of digits required before grouping is applied. +Values with fewer digits than this threshold will not be grouped. + +### onlyIfContainsSeparator + +type: `boolean` + +default: `false` + +Only enforce the rule when the numeric literal already contains a separator (`_`). + +When `true`, numbers without separators are left as-is; when `false` (default), +grouping will be enforced for eligible numbers even if they don't include separators yet. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-at.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-at.md index 63004be0df9..e81dea4bcff 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-at.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-at.md @@ -40,6 +40,28 @@ const foo = array.at(-5); const foo = string.at(-1); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### checkAllIndexAccess + +type: `boolean` + +default: `false` + +Check all index access, not just special patterns like `array.length - 1`. +When enabled, `array[0]`, `array[1]`, etc. will also be flagged. + +### getLastElementFunctions + +type: `string[]` + +default: `[]` + +List of function names to treat as "get last element" functions. +These functions will be checked for `.at(-1)` usage. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-object-from-entries.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-object-from-entries.md index cbb8d5bfbd5..f22855ccca6 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-object-from-entries.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-object-from-entries.md @@ -46,6 +46,18 @@ Examples of **correct** code for this rule: const result = Object.fromEntries(pairs); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### functions + +type: `string[]` + +default: `["_.fromPairs", "lodash.fromPairs"]` + +Additional functions to treat as equivalents to `Object.fromEntries`. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/version.data.js b/src/docs/guide/usage/linter/rules/version.data.js index 75527747475..303d5e2449e 100644 --- a/src/docs/guide/usage/linter/rules/version.data.js +++ b/src/docs/guide/usage/linter/rules/version.data.js @@ -1,5 +1,5 @@ export default { load() { - return "dd1fdd44304b82e5df2aecef0787a7c6f2c6de84"; + return "ecc81ef1cc714e3ab21adaa15bfdf82737301642"; }, }; diff --git a/src/docs/guide/usage/linter/rules/vue/max-props.md b/src/docs/guide/usage/linter/rules/vue/max-props.md index 35ab0efe71f..a2a5edf4ff6 100644 --- a/src/docs/guide/usage/linter/rules/vue/max-props.md +++ b/src/docs/guide/usage/linter/rules/vue/max-props.md @@ -42,20 +42,17 @@ defineProps({ ``` -### Options +## Configuration -This rule takes an object, where you can specify the maximum number of props allowed in a Vue SFC. +This rule accepts a configuration object with the following properties: -```json -{ - "vue/max-props": [ - "error", - { - "maxProps": 1 - } - ] -} -``` +### maxProps + +type: `integer` + +default: `1` + +The maximum number of props allowed in a Vue Single File Component (SFC). ## How to use