From 2b93543f5c68af058d894ebcbe34b457169821f9 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Mon, 29 Sep 2025 09:38:00 +0000 Subject: [PATCH] Release 1.19.0 --- .../guide/usage/linter/generated-config.md | 14 ++ .../guide/usage/linter/generated-rules.md | 24 +- .../guide/usage/linter/rules/eslint/curly.md | 218 +++++++++++++++++- .../guide/usage/linter/rules/eslint/eqeqeq.md | 141 ++++++++--- .../rules/eslint/no-unused-expressions.md | 41 +++- .../rules/eslint/preserve-caught-error.md | 6 +- .../usage/linter/rules/eslint/sort-keys.md | 2 +- .../linter/rules/import/no-named-export.md | 65 ++++++ .../rules/promise/no-multiple-resolved.md | 79 +++++++ .../linter/rules/react/jsx-pascal-case.md | 120 ++++++++++ .../unicorn/no-array-callback-reference.md | 72 ++++++ .../linter/rules/unicorn/no-array-sort.md | 76 ++++++ .../guide/usage/linter/rules/version.data.js | 2 +- .../guide/usage/linter/rules/vue/max-props.md | 83 +++++++ 14 files changed, 891 insertions(+), 52 deletions(-) create mode 100644 src/docs/guide/usage/linter/rules/import/no-named-export.md create mode 100644 src/docs/guide/usage/linter/rules/promise/no-multiple-resolved.md create mode 100644 src/docs/guide/usage/linter/rules/react/jsx-pascal-case.md create mode 100644 src/docs/guide/usage/linter/rules/unicorn/no-array-callback-reference.md create mode 100644 src/docs/guide/usage/linter/rules/unicorn/no-array-sort.md create mode 100644 src/docs/guide/usage/linter/rules/vue/max-props.md diff --git a/src/docs/guide/usage/linter/generated-config.md b/src/docs/guide/usage/linter/generated-config.md index bb7dacd3a6d..b129ddcd1de 100644 --- a/src/docs/guide/usage/linter/generated-config.md +++ b/src/docs/guide/usage/linter/generated-config.md @@ -143,6 +143,14 @@ default: `[]` Globs to ignore during linting. These are resolved from the configuration file path. +## jsPlugins + +type: `string[]` + +default: `null` + +JS plugins. + ## overrides type: `array` @@ -157,6 +165,12 @@ type: `string[]` A set of glob patterns. +#### overrides[n].jsPlugins + +type: `string[]` + +JS plugins for this override. + #### overrides[n].rules type: `object` diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index 6fcc728f1cb..1ff06592b00 100644 --- a/src/docs/guide/usage/linter/generated-rules.md +++ b/src/docs/guide/usage/linter/generated-rules.md @@ -2,8 +2,8 @@ The progress of all rule implementations is tracked [here](https://github.com/oxc-project/oxc/issues/481). -- Total number of rules: 585 -- Rules turned on by default: 102 +- Total number of rules: 591 +- Rules turned on by default: 103 **Legend for 'Fixable?' column:** @@ -13,7 +13,7 @@ The progress of all rule implementations is tracked [here](https://github.com/ox - βš οΈπŸ’‘: a dangerous suggestion is available for this rule - 🚧: an auto-fix or suggestion is possible, but currently not implemented -## Correctness (194): +## Correctness (195): Code that is outright wrong or useless. @@ -59,6 +59,7 @@ Code that is outright wrong or useless. | [no-unsafe-finally](/docs/guide/usage/linter/rules/eslint/no-unsafe-finally.html) | eslint | βœ… | | | [no-unsafe-negation](/docs/guide/usage/linter/rules/eslint/no-unsafe-negation.html) | eslint | βœ… | πŸ› οΈ | | [no-unsafe-optional-chaining](/docs/guide/usage/linter/rules/eslint/no-unsafe-optional-chaining.html) | eslint | βœ… | | +| [no-unused-expressions](/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html) | eslint | βœ… | | | [no-unused-labels](/docs/guide/usage/linter/rules/eslint/no-unused-labels.html) | eslint | βœ… | πŸ› οΈ | | [no-unused-private-class-members](/docs/guide/usage/linter/rules/eslint/no-unused-private-class-members.html) | eslint | βœ… | | | [no-unused-vars](/docs/guide/usage/linter/rules/eslint/no-unused-vars.html) | eslint | βœ… | βš οΈπŸ’‘ | @@ -254,7 +255,6 @@ Lints which prevent the use of language and library features. Must not be enable | [no-restricted-globals](/docs/guide/usage/linter/rules/eslint/no-restricted-globals.html) | eslint | | | | [no-restricted-imports](/docs/guide/usage/linter/rules/eslint/no-restricted-imports.html) | eslint | | | | [no-undefined](/docs/guide/usage/linter/rules/eslint/no-undefined.html) | eslint | | | -| [no-unused-expressions](/docs/guide/usage/linter/rules/eslint/no-unused-expressions.html) | eslint | | | | [no-var](/docs/guide/usage/linter/rules/eslint/no-var.html) | eslint | | πŸ› οΈ | | [no-void](/docs/guide/usage/linter/rules/eslint/no-void.html) | eslint | | πŸ’‘ | | [unicode-bom](/docs/guide/usage/linter/rules/eslint/unicode-bom.html) | eslint | | πŸ› οΈ | @@ -309,9 +309,10 @@ Lints which prevent the use of language and library features. Must not be enable | [prefer-modern-math-apis](/docs/guide/usage/linter/rules/unicorn/prefer-modern-math-apis.html) | unicorn | | 🚧 | | [prefer-node-protocol](/docs/guide/usage/linter/rules/unicorn/prefer-node-protocol.html) | unicorn | | πŸ› οΈ | | [prefer-number-properties](/docs/guide/usage/linter/rules/unicorn/prefer-number-properties.html) | unicorn | | βš οΈπŸ› οΈοΈ | +| [max-props](/docs/guide/usage/linter/rules/vue/max-props.html) | vue | | | | [no-multiple-slot-args](/docs/guide/usage/linter/rules/vue/no-multiple-slot-args.html) | vue | | 🚧 | -## Suspicious (43): +## Suspicious (45): code that is most likely wrong or useless. @@ -325,7 +326,7 @@ code that is most likely wrong or useless. | [no-unneeded-ternary](/docs/guide/usage/linter/rules/eslint/no-unneeded-ternary.html) | eslint | | βš οΈπŸ› οΈοΈ | | [no-useless-concat](/docs/guide/usage/linter/rules/eslint/no-useless-concat.html) | eslint | | | | [no-useless-constructor](/docs/guide/usage/linter/rules/eslint/no-useless-constructor.html) | eslint | | πŸ› οΈ | -| [preserve-caught-error](/docs/guide/usage/linter/rules/eslint/preserve-caught-error.html) | eslint | | 🚧 | +| [preserve-caught-error](/docs/guide/usage/linter/rules/eslint/preserve-caught-error.html) | eslint | | πŸ› οΈ | | [no-absolute-path](/docs/guide/usage/linter/rules/import/no-absolute-path.html) | import | | 🚧 | | [no-empty-named-blocks](/docs/guide/usage/linter/rules/import/no-empty-named-blocks.html) | import | | πŸ› οΈ | | [no-named-as-default](/docs/guide/usage/linter/rules/import/no-named-as-default.html) | import | | | @@ -337,6 +338,7 @@ code that is most likely wrong or useless. | [misrefactored-assign-op](/docs/guide/usage/linter/rules/oxc/misrefactored-assign-op.html) | oxc | | 🚧 | | [no-async-endpoint-handlers](/docs/guide/usage/linter/rules/oxc/no-async-endpoint-handlers.html) | oxc | | | | [always-return](/docs/guide/usage/linter/rules/promise/always-return.html) | promise | | | +| [no-multiple-resolved](/docs/guide/usage/linter/rules/promise/no-multiple-resolved.html) | promise | | | | [no-promise-in-callback](/docs/guide/usage/linter/rules/promise/no-promise-in-callback.html) | promise | | | | [iframe-missing-sandbox](/docs/guide/usage/linter/rules/react/iframe-missing-sandbox.html) | react | | 🚧 | | [jsx-no-comment-textnodes](/docs/guide/usage/linter/rules/react/jsx-no-comment-textnodes.html) | react | | | @@ -356,12 +358,13 @@ code that is most likely wrong or useless. | [consistent-function-scoping](/docs/guide/usage/linter/rules/unicorn/consistent-function-scoping.html) | unicorn | | 🚧 | | [no-accessor-recursion](/docs/guide/usage/linter/rules/unicorn/no-accessor-recursion.html) | unicorn | | | | [no-array-reverse](/docs/guide/usage/linter/rules/unicorn/no-array-reverse.html) | unicorn | | πŸ› οΈ | +| [no-array-sort](/docs/guide/usage/linter/rules/unicorn/no-array-sort.html) | unicorn | | πŸ› οΈ | | [no-instanceof-builtins](/docs/guide/usage/linter/rules/unicorn/no-instanceof-builtins.html) | unicorn | | 🚧 | | [prefer-add-event-listener](/docs/guide/usage/linter/rules/unicorn/prefer-add-event-listener.html) | unicorn | | 🚧 | | [require-post-message-target-origin](/docs/guide/usage/linter/rules/unicorn/require-post-message-target-origin.html) | unicorn | | πŸ’‘ | | [no-required-prop-with-default](/docs/guide/usage/linter/rules/vue/no-required-prop-with-default.html) | vue | | 🚧 | -## Pedantic (97): +## Pedantic (98): Lints which are rather strict or have occasional false positives. @@ -430,6 +433,7 @@ Lints which are rather strict or have occasional false positives. | [escape-case](/docs/guide/usage/linter/rules/unicorn/escape-case.html) | unicorn | | πŸ› οΈ | | [explicit-length-check](/docs/guide/usage/linter/rules/unicorn/explicit-length-check.html) | unicorn | | πŸ› οΈ | | [new-for-builtins](/docs/guide/usage/linter/rules/unicorn/new-for-builtins.html) | unicorn | | | +| [no-array-callback-reference](/docs/guide/usage/linter/rules/unicorn/no-array-callback-reference.html) | unicorn | | 🚧 | | [no-hex-escape](/docs/guide/usage/linter/rules/unicorn/no-hex-escape.html) | unicorn | | πŸ› οΈ | | [no-instanceof-array](/docs/guide/usage/linter/rules/unicorn/no-instanceof-array.html) | unicorn | | πŸ› οΈ | | [no-lonely-if](/docs/guide/usage/linter/rules/unicorn/no-lonely-if.html) | unicorn | | | @@ -465,7 +469,7 @@ Lints which are rather strict or have occasional false positives. | [prefer-type-error](/docs/guide/usage/linter/rules/unicorn/prefer-type-error.html) | unicorn | | πŸ› οΈ | | [require-number-to-fixed-digits-argument](/docs/guide/usage/linter/rules/unicorn/require-number-to-fixed-digits-argument.html) | unicorn | | πŸ› οΈ | -## Style (159): +## Style (161): Code that should be written in a more idiomatic way. @@ -510,7 +514,7 @@ Code that should be written in a more idiomatic way. | [prefer-spread](/docs/guide/usage/linter/rules/eslint/prefer-spread.html) | eslint | | | | [prefer-template](/docs/guide/usage/linter/rules/eslint/prefer-template.html) | eslint | | 🚧 | | [sort-imports](/docs/guide/usage/linter/rules/eslint/sort-imports.html) | eslint | | πŸ› οΈ | -| [sort-keys](/docs/guide/usage/linter/rules/eslint/sort-keys.html) | eslint | | 🚧 | +| [sort-keys](/docs/guide/usage/linter/rules/eslint/sort-keys.html) | eslint | | πŸ› οΈ | | [vars-on-top](/docs/guide/usage/linter/rules/eslint/vars-on-top.html) | eslint | | | | [yoda](/docs/guide/usage/linter/rules/eslint/yoda.html) | eslint | | πŸ› οΈ | | [consistent-type-specifier-style](/docs/guide/usage/linter/rules/import/consistent-type-specifier-style.html) | import | | πŸ› οΈ | @@ -521,6 +525,7 @@ Code that should be written in a more idiomatic way. | [no-duplicates](/docs/guide/usage/linter/rules/import/no-duplicates.html) | import | | | | [no-mutable-exports](/docs/guide/usage/linter/rules/import/no-mutable-exports.html) | import | | | | [no-named-default](/docs/guide/usage/linter/rules/import/no-named-default.html) | import | | | +| [no-named-export](/docs/guide/usage/linter/rules/import/no-named-export.html) | import | | | | [no-namespace](/docs/guide/usage/linter/rules/import/no-namespace.html) | import | | 🚧 | | [prefer-default-export](/docs/guide/usage/linter/rules/import/prefer-default-export.html) | import | | | | [consistent-test-it](/docs/guide/usage/linter/rules/jest/consistent-test-it.html) | jest | | πŸ› οΈ | @@ -573,6 +578,7 @@ Code that should be written in a more idiomatic way. | [jsx-curly-brace-presence](/docs/guide/usage/linter/rules/react/jsx-curly-brace-presence.html) | react | | πŸ› οΈ | | [jsx-fragments](/docs/guide/usage/linter/rules/react/jsx-fragments.html) | react | | πŸ› οΈ | | [jsx-handler-names](/docs/guide/usage/linter/rules/react/jsx-handler-names.html) | react | | | +| [jsx-pascal-case](/docs/guide/usage/linter/rules/react/jsx-pascal-case.html) | react | | | | [no-set-state](/docs/guide/usage/linter/rules/react/no-set-state.html) | react | | | | [prefer-es6-class](/docs/guide/usage/linter/rules/react/prefer-es6-class.html) | react | | | | [self-closing-comp](/docs/guide/usage/linter/rules/react/self-closing-comp.html) | react | | πŸ› οΈ | diff --git a/src/docs/guide/usage/linter/rules/eslint/curly.md b/src/docs/guide/usage/linter/rules/eslint/curly.md index b8c8dd1272c..1e4626892f6 100644 --- a/src/docs/guide/usage/linter/rules/eslint/curly.md +++ b/src/docs/guide/usage/linter/rules/eslint/curly.md @@ -15,7 +15,8 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -This rule enforces the use of curly braces `{}` for all control statements (`if`, `else`, `for`, `while`, `do`, etc.). +This rule enforces the use of curly braces `{}` for all control statements +(`if`, `else`, `for`, `while`, `do`, `with`). It ensures that all blocks are enclosed in curly braces to improve code clarity and maintainability. ### Why is this bad? @@ -24,31 +25,232 @@ Omitting curly braces can reduce code readability and increase the likelihood of It can also lead to bugs if additional statements are added later without properly enclosing them in braces. Using curly braces consistently makes the code safer and easier to modify. +### Options + +First option: + +- Type: `string` +- Default: `"all"` +- Possible values: + - `"all"`: require braces in all cases + - `"multi"`: require braces only for multi-statement blocks + - `"multi-line"`: require braces only for multi-line blocks + - `"multi-or-nest"`: require braces for multi-line blocks or when nested + +Second option: + +- Type: `string` +- Default: `undefined` +- Possible values: +- `"consistent"`: require braces if any other branch in the `if-else` chain has braces + +Note : The second option can only be used in conjunction with the first option. + +Example configuration: + +```json +{ + "curly": ["error", "multi-or-nest", "consistent"] +} +``` + ### Examples +#### `"all"` (default) + Examples of **incorrect** code for this rule: ```js +/* curly: ["error", "all"] */ + if (foo) foo++; +while (bar) bar--; +do foo(); while (bar); +``` + +Examples of **correct** code for this rule: -for (let i = 0; i < 10; i++) doSomething(i); +```js +/* curly: ["error", "all"] */ +if (foo) foo++; while (bar) bar--; +do { + foo(); +} while (bar); ``` -Examples of **correct** code for this rule: +#### `"multi"` + +Examples of **incorrect** code for this rule with the `"multi"` option: + +```js +/* curly: ["error", "multi"] */ + +if (foo) foo(); +else { + bar(); + baz(); +} +``` + +Examples of **correct** code for this rule with the `"multi"` option: ```js +/* curly: ["error", "multi"] */ + +if (foo) foo(); +else bar(); +``` + +#### `"multi-line"` + +Examples of **incorrect** code for this rule with the `"multi-line"` option: + +```js +/* curly: ["error", "multi-line"] */ + +if (foo) foo(); +else { + bar(); +} + +while (foo) { + foo(); +} +``` + +Examples of **correct** code for this rule with the `"multi-line"` option: + +```js +/* curly: ["error", "multi-line"] */ + +if (foo) foo(); +else bar(); + +while (foo) foo(); + +while (true) { + doSomething(); + doSomethingElse(); +} +``` + +#### `"multi-or-nest"` + +Examples of **incorrect** code for this rule with the `"multi-or-nest"` option: + +```js +/* curly: ["error", "multi-or-nest"] */ + if (foo) { - foo++; + if (bar) bar(); } -for (let i = 0; i < 10; i++) { - doSomething(i); +while (foo) { + while (bar) bar(); } +``` + +Examples of **correct** code for this rule with the `"multi-or-nest"` option: -while (bar) { - bar--; +```js +/* curly: ["error", "multi-or-nest"] */ + +if (foo) { + if (bar) bar(); +} + +while (foo) { + while (bar) bar(); +} +``` + +#### `{ "consistent": true }` + +When enabled, `consistent: true` enforces consistent use of braces within an `if-else` chain. +If one branch of the chain uses braces, then all branches must use braces, even if not strictly required by the first option. + +Examples of **incorrect** code with `"multi"` and `consistent: true`: + +```js +/* curly: ["error", "multi", "consistent"] */ + +if (foo) { + bar(); + baz(); +} else qux(); + +if (foo) bar(); +else { + baz(); + qux(); +} +``` + +Examples of **correct** code with `"multi"` and `consistent: true`: + +```js +/* curly: ["error", "multi", "consistent"] */ + +if (foo) { + bar(); + baz(); +} else { + qux(); +} + +if (foo) { + bar(); +} else { + baz(); + qux(); +} +``` + +Examples of **incorrect** code with `"multi-line"` and `consistent: true`: + +```js +/* curly: ["error", "multi-line", "consistent"] */ + +if (foo) { + bar(); +} else { + baz(); +} +``` + +Examples of **correct** code with `"multi-line"` and `consistent: true`: + +```js +/* curly: ["error", "multi-line", "consistent"] */ + +if (foo) { + bar(); +} else { + baz(); +} +``` + +Examples of **incorrect** code with `"multi-or-nest"` and `consistent: true`: + +```js +/* curly: ["error", "multi-or-nest", "consistent"] */ + +if (foo) { + if (bar) baz(); +} else qux(); +``` + +Examples of **correct** code with `"multi-or-nest"` and `consistent: true`: + +```js +/* curly: ["error", "multi-or-nest", "consistent"] */ + +if (foo) { + if (bar) baz(); +} else { + qux(); } ``` diff --git a/src/docs/guide/usage/linter/rules/eslint/eqeqeq.md b/src/docs/guide/usage/linter/rules/eslint/eqeqeq.md index caad5664a44..88540d6d6a3 100644 --- a/src/docs/guide/usage/linter/rules/eslint/eqeqeq.md +++ b/src/docs/guide/usage/linter/rules/eslint/eqeqeq.md @@ -15,70 +15,149 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Requires the use of the `===` and `!==` operators. +Requires the use of the `===` and `!==` operators, disallowing the use of `==` and `!=`. ### Why is this bad? -Using non-strict equality operators leads to hard to track bugs due to type coercion. +Using non-strict equality operators leads to unexpected behavior due to type coercion, which can cause hard-to-find bugs. + +### Options + +First option: + +- Type: `string` +- Default: `"always"` + +Possible values: + +- `"always"` - always require `===`/`!==` +- `"smart"` - allow safe comparisons (`typeof`, literals, nullish) + +Second option (only used with `"always"`): + +- Type: `object` +- Properties: + - `null`: `string` (default: `"always"`) - `"ignore"` allows `== null` and `!= null`. + +Possible values for `null`: + +- `"always"` - always require `=== null`/`!== null` +- `"never"` - always require `== null`/`!= null` +- `"ignore"` - allow both `== null`/`!= null` and `=== null`/`!== null` + +Example JSON configuration: + +```json +{ + "eqeqeq": ["error", "always", { "null": "ignore" }] +} +``` ### Examples +#### `"always"` (default) + Examples of **incorrect** code for this rule: ```js -const a = []; -const b = true; -a == b; -``` +/* eslint eqeqeq: "error" */ -The above will evaluate to `true`, but that is almost surely not what you want. +if (x == 42) {} +if ("" == text) {} +if (obj.getStuff() != undefined) {} +``` Examples of **correct** code for this rule: ```js -const a = []; -const b = true; -a === b; +/* eslint eqeqeq: "error" */ + +if (x === 42) {} +if ("" === text) {} +if (obj.getStuff() !== undefined) {} ``` -The above will evaluate to `false` (an array is not boolean true). +#### `"smart"` -### Options +Examples of **incorrect** code for this rule with the `"smart"` option: -#### null +```js +/* eslint eqeqeq: ["error", "smart"] */ -```json -"eslint/eqeqeq": ["error", "always", {"null": "ignore"}] +if (x == 42) {} +if ("" == text) {} ``` -Allow nullish comparison (`foo == null`). The alternative (`foo === null || foo === undefined`) is verbose and has no other benefit. +Examples of **correct** code for this rule with the `"smart"` option: -#### smart +```js +/* eslint eqeqeq: ["error", "smart"] */ -```json -"eslint/eqeqeq": ["error", "smart"] +if (typeof foo == "undefined") {} +if (foo == null) {} +if (foo != null) {} +``` + +#### `{"null": "ignore"}` (with `"always"` first option) + +Examples of **incorrect** code for this rule with the `{ "null": "ignore" }` option: + +```js +/* eslint eqeqeq: ["error", "always", { "null": "ignore" }] */ +if (x == 42) {} +if ("" == text) {} ``` -Allow `==` when comparing: +Examples of **correct** code for this rule with the `{ "null": "ignore" }` option: + +```js +/* eslint eqeqeq: ["error", "always", { "null": "ignore" }] */ +if (foo == null) {} +if (foo != null) {} +``` -- the result from `typeof` -- literal values -- nullish +#### `{"null": "always"}` (default - with `"always"` first option) -Examples of **incorrect** code for this option: +Examples of **incorrect** code for this rule with the `{ "null": "always" }` option: ```js -a == b -[] == true +/* eslint eqeqeq: ["error", "always", { "null": "always" }] */ + +if (foo == null) {} +if (foo != null) {} ``` -Examples of **correct** code for this option: +Examples of **correct** code for this rule with the `{ "null": "always" }` option: ```js -typeof foo == "undefined"; -"foo" == "bar"; -42 == 42; -foo == null; +/* eslint eqeqeq: ["error", "always", { "null": "always" }] */ + +if (foo === null) {} +if (foo !== null) {} +``` + +#### `{"null": "never"}` (with `"always"` first option) + +Examples of **incorrect** code for this rule with the `{ "null": "never" }` option: + +```js +/* eslint eqeqeq: ["error", "always", { "null": "never" }] */ + +if (x == 42) {} +if ("" == text) {} +if (foo === null) {} +if (foo !== null) {} +``` + +Examples of **correct** code for this rule with the `{ "null": "never" }` option: + +```js +/* eslint eqeqeq: ["error", "always", { "null": "never" }] */ + +if (x === 42) {} +if ("" === text) {} +if (foo == null) {} +if (foo != null) {} ``` ## Configuration diff --git a/src/docs/guide/usage/linter/rules/eslint/no-unused-expressions.md b/src/docs/guide/usage/linter/rules/eslint/no-unused-expressions.md index 2b855bf57c0..2dd7b1c0d8f 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-unused-expressions.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-unused-expressions.md @@ -5,9 +5,12 @@ import { data } from '../version.data.js'; const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_linter/src/rules/eslint/no_unused_expressions.rs`; -# eslint/no-unused-expressions +# eslint/no-unused-expressions
+ +βœ… This rule is turned on by default. +
### What it does @@ -34,6 +37,42 @@ Examples of **correct** code for this rule: const foo = new Set(); ``` +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowShortCircuit + +type: `boolean` + +default: `false` + +When set to `true`, allows short circuit evaluations in expressions. + +### allowTaggedTemplates + +type: `boolean` + +default: `false` + +When set to `true`, allows tagged template literals in expressions. + +### allowTernary + +type: `boolean` + +default: `false` + +When set to `true`, allows ternary operators in expressions. + +### enforceForJsx + +type: `boolean` + +default: `false` + +When set to `true`, enforces the rule for unused JSX expressions also. + ## 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/preserve-caught-error.md b/src/docs/guide/usage/linter/rules/eslint/preserve-caught-error.md index ca4885bae4e..05cb3943d4a 100644 --- a/src/docs/guide/usage/linter/rules/eslint/preserve-caught-error.md +++ b/src/docs/guide/usage/linter/rules/eslint/preserve-caught-error.md @@ -9,7 +9,7 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin
-🚧 An auto-fix is still under development. +πŸ› οΈ An auto-fix is available for this rule for some violations.
@@ -53,6 +53,10 @@ This rule accepts a configuration object with the following properties: type: `boolean` +default: `false` + +When set to `true`, requires that catch clauses always have a parameter. + ## 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 8bcb9c083e1..10c7372b825 100644 --- a/src/docs/guide/usage/linter/rules/eslint/sort-keys.md +++ b/src/docs/guide/usage/linter/rules/eslint/sort-keys.md @@ -9,7 +9,7 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin
-🚧 An auto-fix is still under development. +πŸ› οΈ An auto-fix is available for this rule for some violations.
diff --git a/src/docs/guide/usage/linter/rules/import/no-named-export.md b/src/docs/guide/usage/linter/rules/import/no-named-export.md new file mode 100644 index 00000000000..020e41aed97 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/import/no-named-export.md @@ -0,0 +1,65 @@ + + + + +# import/no-named-export + +
+
+ +### What it does + +Prohibit named exports. + +### Why is this bad? + +Named exports require strict identifier matching and can lead to fragile imports, +while default exports enforce a single, consistent module entry point. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +export const foo = "foo"; + +const bar = "bar"; +export { bar }; +``` + +Examples of **correct** code for this rule: + +```js +export default "bar"; + +const foo = "foo"; +export { foo as default }; +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny import/no-named-export --import-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["import"], + "rules": { + "import/no-named-export": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/promise/no-multiple-resolved.md b/src/docs/guide/usage/linter/rules/promise/no-multiple-resolved.md new file mode 100644 index 00000000000..dbd7143c2ac --- /dev/null +++ b/src/docs/guide/usage/linter/rules/promise/no-multiple-resolved.md @@ -0,0 +1,79 @@ + + + + +# promise/no-multiple-resolved + +
+
+ +### What it does + +This rule warns of paths that resolve multiple times in executor functions that Promise constructors. + +### Why is this bad? + +Multiple resolve/reject calls: + +- Violate the Promise/A+ specification +- Have no effect on the Promise's behavior +- Make the code's intent unclear +- May indicate logical errors in the implementation + +### Examples + +Examples of **incorrect** code for this rule: + +```javascript +new Promise((resolve, reject) => { + fn((error, value) => { + if (error) { + reject(error); + } + + resolve(value); // Both `reject` and `resolve` may be called. + }); +}); +``` + +Examples of **correct** code for this rule: + +```javascript +new Promise((resolve, reject) => { + fn((error, value) => { + if (error) { + reject(error); + } else { + resolve(value); + } + }); +}); +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny promise/no-multiple-resolved --promise-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["promise"], + "rules": { + "promise/no-multiple-resolved": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/react/jsx-pascal-case.md b/src/docs/guide/usage/linter/rules/react/jsx-pascal-case.md new file mode 100644 index 00000000000..469fe60713a --- /dev/null +++ b/src/docs/guide/usage/linter/rules/react/jsx-pascal-case.md @@ -0,0 +1,120 @@ + + + + +# react/jsx-pascal-case + +
+
+ +### What it does + +Enforce PascalCase for user-defined JSX components + +### Why is this bad? + +It enforces coding style that user-defined JSX components are defined and referenced in PascalCase. Note that since React's JSX uses the upper vs. lower case convention +to distinguish between local component classes and HTML tags this rule will not warn on components that start with a lower case letter. + +### Examples + +Examples of **incorrect** code for this rule: + +```jsx + + +``` + +Examples of **correct** code for this rule: + +```jsx +
+ + + + +
+ + + +``` + +Examples of **correct** code for the "allowAllCaps" option: + +```jsx + + + +``` + +Examples of **correct** code for the "allowNamespace" option: + +```jsx + + + +``` + +Examples of **correct** code for the "allowLeadingUnderscore" option: + +```jsx +<_AllowedComponent /> + +<_AllowedComponent> +
+ +``` + +### Options + +#### allowAllCaps + +`{ type: boolean, default: false }` + +Optional boolean set to true to allow components name in all caps + +#### allowLeadingUnderscore + +`{ type: boolean, default: false }` + +Optional boolean set to true to allow components name with that starts with an underscore + +#### allowNamespace + +`{ type: boolean, default: false }` + +Optional boolean set to true to ignore namespaced components + +#### ignore + +`{ type: Array, default: [] }` + +Optional string-array of component names to ignore during validation + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny react/jsx-pascal-case --react-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["react"], + "rules": { + "react/jsx-pascal-case": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-array-callback-reference.md b/src/docs/guide/usage/linter/rules/unicorn/no-array-callback-reference.md new file mode 100644 index 00000000000..0ea615600b9 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/unicorn/no-array-callback-reference.md @@ -0,0 +1,72 @@ + + + + +# unicorn/no-array-callback-reference + +
+ +🚧 An auto-fix is still under development. + +
+ +### What it does + +Prevents passing a function reference directly to iterator methods + +### Why is this bad? + +Passing functions to iterator methods can cause issues when the function is changed +without realizing that the iterator passes 2 more parameters to it (index and array). +This can lead to unexpected behavior when the function signature changes. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +const foo = array.map(callback); +array.forEach(callback); +const result = array.filter(lib.method); +``` + +Examples of **correct** code for this rule: + +```js +const foo = array.map(element => callback(element)); +array.forEach(element => { + callback(element); +}); +const result = array.filter(element => lib.method(element)); + +// Built-in functions are allowed +const foo = array.map(String); +const bar = array.filter(Boolean); +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny unicorn/no-array-callback-reference +``` + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "unicorn/no-array-callback-reference": "error" + } +} +``` + +::: + +## References + +- Rule Source 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 new file mode 100644 index 00000000000..f6ec5eb19dd --- /dev/null +++ b/src/docs/guide/usage/linter/rules/unicorn/no-array-sort.md @@ -0,0 +1,76 @@ + + + + +# unicorn/no-array-sort + +
+ +πŸ› οΈ An auto-fix is available for this rule. + +
+ +### What it does + +Prefer using `Array#toSorted()` over `Array#sort()`. + +### Why is this bad? + +`Array#sort()` modifies the original array in place, which can lead to unintended side effectsβ€”especially +when the original array is used elsewhere in the code. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +const sorted = [...array].sort(); +``` + +Examples of **correct** code for this rule: + +```js +const sorted = [...array].toSorted(); +``` + +### Options + +#### allowExpressionStatement + +`{ type: boolean, default: true }` + +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. + +Examples of **incorrect** code for this rule with the `{ "allowExpressionStatement": false }` option: + +```js +array.sort(); +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny unicorn/no-array-sort +``` + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "unicorn/no-array-sort": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/version.data.js b/src/docs/guide/usage/linter/rules/version.data.js index bf83991903a..bba66674ec3 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 "3a706a7fbb9dcb673e7f39a5f137c3d10524f6e3"; + return "eb6345f0c2927517ad5eff19c54a5d636f17b106"; }, }; diff --git a/src/docs/guide/usage/linter/rules/vue/max-props.md b/src/docs/guide/usage/linter/rules/vue/max-props.md new file mode 100644 index 00000000000..35ab0efe71f --- /dev/null +++ b/src/docs/guide/usage/linter/rules/vue/max-props.md @@ -0,0 +1,83 @@ + + + + +# vue/max-props + +
+
+ +### What it does + +Enforce maximum number of props in Vue component. + +### Why is this bad? + +This rule enforces a maximum number of props in a Vue SFC, +in order to aid in maintainability and reduce complexity. + +### Examples + +Examples of **incorrect** code for this rule with the default `{ maxProps: 1 }` option: + +```js + +``` + +Examples of **correct** code for this rule with the default `{ maxProps: 1 }` option: + +```js + +``` + +### Options + +This rule takes an object, where you can specify the maximum number of props allowed in a Vue SFC. + +```json +{ + "vue/max-props": [ + "error", + { + "maxProps": 1 + } + ] +} +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny vue/max-props --vue-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["vue"], + "rules": { + "vue/max-props": "error" + } +} +``` + +::: + +## References + +- Rule Source