diff --git a/src/docs/guide/usage/linter/generated-cli.md b/src/docs/guide/usage/linter/generated-cli.md index a2a98306a94..45c917b920f 100644 --- a/src/docs/guide/usage/linter/generated-cli.md +++ b/src/docs/guide/usage/linter/generated-cli.md @@ -104,7 +104,7 @@ Arguments: ## Output - **`-f`**, **`--format`**=_`ARG`_ — - Use a specific output format. Possible values: `checkstyle`, `default`, `github`, `json`, `junit`, `stylish`, `unix` + Use a specific output format. Possible values: `checkstyle`, `default`, `github`, `gitlab`, `json`, `junit`, `stylish`, `unix` ## Miscellaneous diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index a240f09367b..43148e708dc 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: 509 +- Total number of rules: 512 - Rules turned on by default: 123 **Legend for 'Fixable?' column:** @@ -130,7 +130,7 @@ Code that is outright wrong or useless. | [no-duplicate-head](/docs/guide/usage/linter/rules/nextjs/no-duplicate-head.html) | nextjs | ✅ | | | [no-head-element](/docs/guide/usage/linter/rules/nextjs/no-head-element.html) | nextjs | ✅ | | | [no-head-import-in-document](/docs/guide/usage/linter/rules/nextjs/no-head-import-in-document.html) | nextjs | ✅ | | -| [no-img-element](/docs/guide/usage/linter/rules/nextjs/no-img-element.html) | nextjs | ✅ | | +| [no-img-element](/docs/guide/usage/linter/rules/nextjs/no-img-element.html) | nextjs | ✅ | 🚧 | | [no-page-custom-font](/docs/guide/usage/linter/rules/nextjs/no-page-custom-font.html) | nextjs | ✅ | | | [no-script-component-in-head](/docs/guide/usage/linter/rules/nextjs/no-script-component-in-head.html) | nextjs | ✅ | | | [no-styled-jsx-in-document](/docs/guide/usage/linter/rules/nextjs/no-styled-jsx-in-document.html) | nextjs | ✅ | | @@ -211,7 +211,7 @@ Code that can be written to run faster. | [jsx-no-new-object-as-prop](/docs/guide/usage/linter/rules/react_perf/jsx-no-new-object-as-prop.html) | react_perf | | | | [prefer-set-has](/docs/guide/usage/linter/rules/unicorn/prefer-set-has.html) | unicorn | | ⚠️🛠️️ | -## Restriction (65): +## Restriction (66): Lints which prevent the use of language and library features. Must not be enabled as a whole, should be considered on a case-by-case basis before enabling. @@ -256,6 +256,7 @@ Lints which prevent the use of language and library features. Must not be enable | [catch-or-return](/docs/guide/usage/linter/rules/promise/catch-or-return.html) | promise | | | | [spec-only](/docs/guide/usage/linter/rules/promise/spec-only.html) | promise | | | | [button-has-type](/docs/guide/usage/linter/rules/react/button-has-type.html) | react | | | +| [forbid-elements](/docs/guide/usage/linter/rules/react/forbid-elements.html) | react | | | | [jsx-filename-extension](/docs/guide/usage/linter/rules/react/jsx-filename-extension.html) | react | | 🚧 | | [no-danger](/docs/guide/usage/linter/rules/react/no-danger.html) | react | | | | [no-unknown-property](/docs/guide/usage/linter/rules/react/no-unknown-property.html) | react | | 🚧 | @@ -283,7 +284,7 @@ Lints which prevent the use of language and library features. Must not be enable | [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 | | ⚠️🛠️️ | -## Suspicious (31): +## Suspicious (32): code that is most likely wrong or useless. @@ -302,6 +303,7 @@ code that is most likely wrong or useless. | [no-named-as-default](/docs/guide/usage/linter/rules/import/no-named-as-default.html) | import | | | | [no-named-as-default-member](/docs/guide/usage/linter/rules/import/no-named-as-default-member.html) | import | | | | [no-self-import](/docs/guide/usage/linter/rules/import/no-self-import.html) | import | | | +| [no-unassigned-import](/docs/guide/usage/linter/rules/import/no-unassigned-import.html) | import | | | | [no-commented-out-tests](/docs/guide/usage/linter/rules/jest/no-commented-out-tests.html) | jest | | | | [approx-constant](/docs/guide/usage/linter/rules/oxc/approx-constant.html) | oxc | | | | [misrefactored-assign-op](/docs/guide/usage/linter/rules/oxc/misrefactored-assign-op.html) | oxc | | 🚧 | @@ -314,7 +316,7 @@ code that is most likely wrong or useless. | [react-in-jsx-scope](/docs/guide/usage/linter/rules/react/react-in-jsx-scope.html) | react | | | | [style-prop-object](/docs/guide/usage/linter/rules/react/style-prop-object.html) | react | | | | [no-confusing-non-null-assertion](/docs/guide/usage/linter/rules/typescript/no-confusing-non-null-assertion.html) | typescript | | 🚧 | -| [no-extraneous-class](/docs/guide/usage/linter/rules/typescript/no-extraneous-class.html) | typescript | | | +| [no-extraneous-class](/docs/guide/usage/linter/rules/typescript/no-extraneous-class.html) | typescript | | ⚠️💡 | | [no-unnecessary-type-constraint](/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-constraint.html) | typescript | | | | [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 | | | @@ -409,7 +411,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 (138): +## Style (140): Code that should be written in a more idiomatic way. @@ -452,6 +454,7 @@ Code that should be written in a more idiomatic way. | [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 | | 🛠️ | | [exports-last](/docs/guide/usage/linter/rules/import/exports-last.html) | import | | | | [first](/docs/guide/usage/linter/rules/import/first.html) | import | | 🚧 | | [group-exports](/docs/guide/usage/linter/rules/import/group-exports.html) | import | | | @@ -515,6 +518,7 @@ Code that should be written in a more idiomatic way. | [consistent-generic-constructors](/docs/guide/usage/linter/rules/typescript/consistent-generic-constructors.html) | typescript | | 🚧 | | [consistent-indexed-object-style](/docs/guide/usage/linter/rules/typescript/consistent-indexed-object-style.html) | typescript | | 🛠️ | | [consistent-type-definitions](/docs/guide/usage/linter/rules/typescript/consistent-type-definitions.html) | typescript | | 🛠️ | +| [consistent-type-imports](/docs/guide/usage/linter/rules/typescript/consistent-type-imports.html) | typescript | | 🛠️ | | [no-empty-interface](/docs/guide/usage/linter/rules/typescript/no-empty-interface.html) | typescript | | | | [no-inferrable-types](/docs/guide/usage/linter/rules/typescript/no-inferrable-types.html) | typescript | | 🚧 | | [prefer-for-of](/docs/guide/usage/linter/rules/typescript/prefer-for-of.html) | typescript | | 🚧 | @@ -554,19 +558,18 @@ Code that should be written in a more idiomatic way. | [prefer-to-be-object](/docs/guide/usage/linter/rules/vitest/prefer-to-be-object.html) | vitest | | 🛠️ | | [prefer-to-be-truthy](/docs/guide/usage/linter/rules/vitest/prefer-to-be-truthy.html) | vitest | | 🛠️ | -## Nursery (10): +## Nursery (9): New lints that are still under development. -| Rule name | Source | Default | Fixable? | -| ------------------------------------------------------------------------------------------------- | ---------- | ------- | -------- | -| [getter-return](/docs/guide/usage/linter/rules/eslint/getter-return.html) | eslint | | | -| [no-undef](/docs/guide/usage/linter/rules/eslint/no-undef.html) | eslint | | | -| [no-unreachable](/docs/guide/usage/linter/rules/eslint/no-unreachable.html) | eslint | | | -| [export](/docs/guide/usage/linter/rules/import/export.html) | import | | | -| [named](/docs/guide/usage/linter/rules/import/named.html) | import | | | -| [no-map-spread](/docs/guide/usage/linter/rules/oxc/no-map-spread.html) | oxc | | 🛠️💡 | -| [no-return-in-finally](/docs/guide/usage/linter/rules/promise/no-return-in-finally.html) | promise | | | -| [exhaustive-deps](/docs/guide/usage/linter/rules/react/exhaustive-deps.html) | react | | | -| [require-render-return](/docs/guide/usage/linter/rules/react/require-render-return.html) | react | | | -| [consistent-type-imports](/docs/guide/usage/linter/rules/typescript/consistent-type-imports.html) | typescript | | 🛠️ | +| Rule name | Source | Default | Fixable? | +| ---------------------------------------------------------------------------------------- | ------- | ------- | -------- | +| [getter-return](/docs/guide/usage/linter/rules/eslint/getter-return.html) | eslint | | | +| [no-undef](/docs/guide/usage/linter/rules/eslint/no-undef.html) | eslint | | | +| [no-unreachable](/docs/guide/usage/linter/rules/eslint/no-unreachable.html) | eslint | | | +| [export](/docs/guide/usage/linter/rules/import/export.html) | import | | | +| [named](/docs/guide/usage/linter/rules/import/named.html) | import | | | +| [no-map-spread](/docs/guide/usage/linter/rules/oxc/no-map-spread.html) | oxc | | 🛠️💡 | +| [no-return-in-finally](/docs/guide/usage/linter/rules/promise/no-return-in-finally.html) | promise | | | +| [exhaustive-deps](/docs/guide/usage/linter/rules/react/exhaustive-deps.html) | react | | | +| [require-render-return](/docs/guide/usage/linter/rules/react/require-render-return.html) | react | | | diff --git a/src/docs/guide/usage/linter/rules/eslint/array-callback-return.md b/src/docs/guide/usage/linter/rules/eslint/array-callback-return.md index f106f991028..f13f0e45e29 100644 --- a/src/docs/guide/usage/linter/rules/eslint/array-callback-return.md +++ b/src/docs/guide/usage/linter/rules/eslint/array-callback-return.md @@ -23,10 +23,22 @@ consider using .forEach instead. ### Example +Examples of **incorrect** code for this rule: + +```javascript +let foo = [1, 2, 3, 4]; +foo.map((a) => { + console.log(a); +}); +``` + +Examples of **correct** code for this rule: + ```javascript let foo = [1, 2, 3, 4]; foo.map((a) => { console.log(a); + return a; }); ``` diff --git a/src/docs/guide/usage/linter/rules/eslint/default-case-last.md b/src/docs/guide/usage/linter/rules/eslint/default-case-last.md index 9917444ab6b..ba0bde249ba 100644 --- a/src/docs/guide/usage/linter/rules/eslint/default-case-last.md +++ b/src/docs/guide/usage/linter/rules/eslint/default-case-last.md @@ -23,6 +23,8 @@ If a switch statement should have a default clause, it’s considered a best pra ### Example +Examples of **incorrect** code for this rule: + ```javascript switch (foo) { default: @@ -46,6 +48,22 @@ switch (foo) { } ``` +Examples of **correct** code for this rule: + +```javascript +switch (foo) { + case 1: + bar(); + break; + case 2: + qux(); + break; + default: + baz(); + break; +} +``` + ## 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/default-param-last.md b/src/docs/guide/usage/linter/rules/eslint/default-param-last.md index b6eb29051cb..3527dceb9d6 100644 --- a/src/docs/guide/usage/linter/rules/eslint/default-param-last.md +++ b/src/docs/guide/usage/linter/rules/eslint/default-param-last.md @@ -20,16 +20,21 @@ Putting default parameter at last allows function calls to omit optional tail ar ### Example -```javascript -// Correct: optional argument can be omitted -function createUser(id, isAdmin = false) {} -createUser("tabby"); +Examples of **incorrect** code for this rule: +```javascript // Incorrect: optional argument can **not** be omitted function createUser(isAdmin = false, id) {} createUser(undefined, "tabby"); ``` +Examples of **correct** code for this rule: + +```javascript +function createUser(id, isAdmin = false) {} +createUser("tabby"); +``` + ## 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-constant-condition.md b/src/docs/guide/usage/linter/rules/eslint/no-constant-condition.md index 69c45f48a12..2a65bc0bfe8 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-constant-condition.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-constant-condition.md @@ -27,7 +27,7 @@ This rule disallows constant expressions in the test condition of: - `if`, `for`, `while`, or `do...while` statement - `?`: ternary expression -### Example +### Examples Examples of **incorrect** code for this rule: @@ -60,6 +60,16 @@ while (typeof x === "undefined") { } ``` +### Options + +#### checkLoops + +`{ type: "all" | "allExceptWhileTrue" | "none" | boolean, default: "allExceptWhileTrue" }` + +- `"all"` or `true` disallows constant expressions in loops +- `"allExceptWhileTrue"` disallows constant expressions in loops except while loops with expression `true` +- `"none"` or `false` allows constant expressions in loops + ## 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-debugger.md b/src/docs/guide/usage/linter/rules/eslint/no-debugger.md index 902382a92a2..4823cb46003 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-debugger.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-debugger.md @@ -27,6 +27,8 @@ They're most commonly an accidental debugging leftover. ### Example +Examples of **incorrect** code for this rule: + ```javascript async function main() { const data = await getData(); @@ -35,6 +37,15 @@ async function main() { } ``` +Examples of **correct** code for this rule: + +```javascript +async function main() { + const data = await getData(); + const result = complexCalculation(data); +} +``` + ## 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-redeclare.md b/src/docs/guide/usage/linter/rules/eslint/no-redeclare.md index aafa74e07de..2ab1ef37be3 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-redeclare.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-redeclare.md @@ -40,7 +40,7 @@ a = 10; #### builtinGlobals -`{ type: bool, default: false }` +`{ type: bool, default: true }` When set `true`, it flags redeclaring built-in globals (e.g., `let Object = 1;`). diff --git a/src/docs/guide/usage/linter/rules/import/consistent-type-specifier-style.md b/src/docs/guide/usage/linter/rules/import/consistent-type-specifier-style.md new file mode 100644 index 00000000000..a0f6375cb2f --- /dev/null +++ b/src/docs/guide/usage/linter/rules/import/consistent-type-specifier-style.md @@ -0,0 +1,79 @@ + + + + +# import/consistent-type-specifier-style + +
+ +🛠️ An auto-fix is available for this rule for some violations. + +
+ +### What it does + +This rule either enforces or bans the use of inline type-only markers for named imports. + +### Why is this bad? + +Mixing top-level `import type { Foo } from 'foo'` with inline `{ type Bar }` +forces readers to mentally switch contexts when scanning your imports. +Enforcing one style makes it immediately obvious which imports are types and which are value imports. + +### Examples + +Examples of incorrect code for the default `prefer-top-level` option: + +```typescript +import { type Foo } from "Foo"; +import Foo, { type Bar } from "Foo"; +``` + +Examples of correct code for the default option: + +```typescript +import type { Foo } from "Foo"; +import type Foo, { Bar } from "Foo"; +``` + +Examples of incorrect code for the `prefer-inline` option: + +```typescript +import type { Foo } from "Foo"; +import type Foo, { Bar } from "Foo"; +``` + +Examples of correct code for the `prefer-inline` option: + +```typescript +import { type Foo } from "Foo"; +import Foo, { type Bar } from "Foo"; +``` + +## 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/consistent-type-specifier-style --import-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["import"], + "rules": { + "import/consistent-type-specifier-style": "error" + } +} +``` + +::: + +## References + +- Rule Source 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 new file mode 100644 index 00000000000..baa1ccbc2e2 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/import/no-unassigned-import.md @@ -0,0 +1,73 @@ + + + + +# import/no-unassigned-import + +
+
+ +### What it does + +This rule aims to remove modules with side-effects by reporting when a module is imported but not assigned. + +### Why is this bad? + +With both CommonJS' require and the ES6 modules' import syntax, +it is possible to import a module but not to use its result. +This can be done explicitly by not assigning the module to a variable. +Doing so can mean either of the following things: + +- The module is imported but not used +- The module has side-effects. Having side-effects, + makes it hard to know whether the module is actually used or can be removed. + It can also make it harder to test or mock parts of your application. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +import "should"; +require("should"); +``` + +Examples of **correct** code for this rule: + +```js +import _ from "foo"; +import _, { foo } from "foo"; +import _, { foo as bar } from "foo"; +const _ = require("foo"); +const { foo } = require("foo"); +const { foo: bar } = require("foo"); +bar(require("foo")); +``` + +## 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-unassigned-import --import-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["import"], + "rules": { + "import/no-unassigned-import": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/jsx_a11y/anchor-is-valid.md b/src/docs/guide/usage/linter/rules/jsx_a11y/anchor-is-valid.md index 565c7c03348..0c0e5e72f74 100644 --- a/src/docs/guide/usage/linter/rules/jsx_a11y/anchor-is-valid.md +++ b/src/docs/guide/usage/linter/rules/jsx_a11y/anchor-is-valid.md @@ -44,8 +44,6 @@ All these anchor implementations indicate that the element is only used to execu ; ``` -` - ### Why is this bad? There are **many reasons** why an anchor should not have a logic and have a correct `href` attribute: diff --git a/src/docs/guide/usage/linter/rules/nextjs/no-img-element.md b/src/docs/guide/usage/linter/rules/nextjs/no-img-element.md index ee41915158f..8ebb8ea9375 100644 --- a/src/docs/guide/usage/linter/rules/nextjs/no-img-element.md +++ b/src/docs/guide/usage/linter/rules/nextjs/no-img-element.md @@ -11,15 +11,49 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin This rule is turned on by default. + +🚧 An auto-fix is still under development. + ### What it does +Prevent the usage of `` element due to slower +[LCP](https://nextjs.org/learn/seo/lcp) and higher bandwidth. + ### Why is this bad? +`` elements are not optimized for performance and can result in +slower LCP and higher bandwidth. Using [``](https://nextjs.org/docs/pages/api-reference/components/image) +from `next/image` will automatically optimize images and serve them as +static assets. + ### Example +Examples of **incorrect** code for this rule: + +```javascript +export function MyComponent() { + return ( +
+ Test picture +
+ ); +} +``` + +Examples of **correct** code for this rule: + ```javascript +import Image from "next/image"; +import testImage from "./test.png"; +export function MyComponent() { + return ( +
+ Test picture +
+ ); +} ``` ## How to use diff --git a/src/docs/guide/usage/linter/rules/react/forbid-elements.md b/src/docs/guide/usage/linter/rules/react/forbid-elements.md new file mode 100644 index 00000000000..5efcfde89bd --- /dev/null +++ b/src/docs/guide/usage/linter/rules/react/forbid-elements.md @@ -0,0 +1,78 @@ + + + + +# react/forbid-elements + +
+
+ +### What it does + +Allows you to configure a list of forbidden elements and to specify their desired replacements. + +### Why is this bad? + +You may want to forbid usage of certain elements in favor of others, (e.g. forbid all
and use instead) + +### Examples + +Examples of **incorrect** code for this rule: + +```jsx +// [1, { "forbid": ["button"] }] +
; +React.createElement("div", {}, React.createElement("button", {}, React.createElement("input"))); +``` + +Examples of **correct** code for this rule: + +```jsx +// [1, { "forbid": ["button"] }] +