From 8ccbd9b526b09ca97c5901022577176319a62246 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Thu, 19 Feb 2026 19:31:00 +0000 Subject: [PATCH] Release 1.49.0 --- .vitepress/data/rules.json | 152 +++++++++++++++++- .../guide/usage/formatter/generated-config.md | 26 +-- .../rules/eslint/array-callback-return.md | 9 ++ .../no-use-before-define.md | 8 +- .../guide/usage/linter/rules/eslint/radix.md | 12 -- .../jest/prefer-mock-return-shorthand.md | 93 +++++++++++ .../usage/linter/rules/node/no-path-concat.md | 80 +++++++++ .../linter/rules/react/no-unknown-property.md | 2 +- .../rules/typescript/consistent-return.md | 87 ++++++++++ .../typescript/consistent-type-exports.md | 84 ++++++++++ .../linter/rules/typescript/dot-notation.md | 114 +++++++++++++ .../typescript/no-unnecessary-qualifier.md | 70 ++++++++ .../no-unnecessary-type-parameters.md | 73 +++++++++ .../no-useless-default-assignment.md | 65 ++++++++ .../linter/rules/typescript/prefer-find.md | 65 ++++++++ .../prefer-readonly-parameter-types.md | 149 +++++++++++++++++ .../rules/typescript/prefer-readonly.md | 89 ++++++++++ .../rules/typescript/prefer-regexp-exec.md | 67 ++++++++ .../prefer-string-starts-ends-with.md | 79 +++++++++ .../rules/typescript/strict-void-return.md | 86 ++++++++++ .../no-unnecessary-array-flat-depth.md | 2 +- .../guide/usage/linter/rules/version.data.js | 2 +- .../vitest/no-importing-vitest-globals.md | 78 +++++++++ .../rules/vitest/prefer-import-in-mock.md | 71 ++++++++ src/docs/guide/usage/rule-count.data.js | 2 +- 25 files changed, 1523 insertions(+), 42 deletions(-) rename src/docs/guide/usage/linter/rules/{typescript => eslint}/no-use-before-define.md (89%) create mode 100644 src/docs/guide/usage/linter/rules/jest/prefer-mock-return-shorthand.md create mode 100644 src/docs/guide/usage/linter/rules/node/no-path-concat.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/consistent-return.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/consistent-type-exports.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/dot-notation.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/no-unnecessary-qualifier.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-parameters.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/no-useless-default-assignment.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/prefer-find.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/prefer-readonly-parameter-types.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/prefer-readonly.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/prefer-regexp-exec.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/prefer-string-starts-ends-with.md create mode 100644 src/docs/guide/usage/linter/rules/typescript/strict-void-return.md create mode 100644 src/docs/guide/usage/linter/rules/vitest/no-importing-vitest-globals.md create mode 100644 src/docs/guide/usage/linter/rules/vitest/prefer-import-in-mock.md diff --git a/.vitepress/data/rules.json b/.vitepress/data/rules.json index 0c4b89946c5..ba192120557 100644 --- a/.vitepress/data/rules.json +++ b/.vitepress/data/rules.json @@ -1187,6 +1187,15 @@ "default": true, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html" }, + { + "scope": "eslint", + "value": "no-use-before-define", + "category": "restriction", + "type_aware": false, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-use-before-define.html" + }, { "scope": "eslint", "value": "no-useless-backreference", @@ -2159,6 +2168,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-mock-promise-shorthand.html" }, + { + "scope": "jest", + "value": "prefer-mock-return-shorthand", + "category": "style", + "type_aware": false, + "fix": "fixable_fix", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/jest/prefer-mock-return-shorthand.html" + }, { "scope": "jest", "value": "prefer-spy-on", @@ -2942,6 +2960,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/node/no-new-require.html" }, + { + "scope": "node", + "value": "no-path-concat", + "category": "restriction", + "type_aware": false, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/node/no-path-concat.html" + }, { "scope": "node", "value": "no-process-env", @@ -3923,6 +3950,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/consistent-indexed-object-style.html" }, + { + "scope": "typescript", + "value": "consistent-return", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/consistent-return.html" + }, { "scope": "typescript", "value": "consistent-type-assertions", @@ -3941,6 +3977,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/consistent-type-definitions.html" }, + { + "scope": "typescript", + "value": "consistent-type-exports", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/consistent-type-exports.html" + }, { "scope": "typescript", "value": "consistent-type-imports", @@ -3950,6 +3995,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/consistent-type-imports.html" }, + { + "scope": "typescript", + "value": "dot-notation", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/dot-notation.html" + }, { "scope": "typescript", "value": "explicit-function-return-type", @@ -4283,6 +4337,15 @@ "default": true, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-unnecessary-parameter-property-assignment.html" }, + { + "scope": "typescript", + "value": "no-unnecessary-qualifier", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-unnecessary-qualifier.html" + }, { "scope": "typescript", "value": "no-unnecessary-template-expression", @@ -4319,6 +4382,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-constraint.html" }, + { + "scope": "typescript", + "value": "no-unnecessary-type-parameters", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-parameters.html" + }, { "scope": "typescript", "value": "no-unsafe-argument", @@ -4411,12 +4483,12 @@ }, { "scope": "typescript", - "value": "no-use-before-define", - "category": "restriction", - "type_aware": false, + "value": "no-useless-default-assignment", + "category": "nursery", + "type_aware": true, "fix": "none", "default": false, - "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-use-before-define.html" + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-useless-default-assignment.html" }, { "scope": "typescript", @@ -4490,6 +4562,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-enum-initializers.html" }, + { + "scope": "typescript", + "value": "prefer-find", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-find.html" + }, { "scope": "typescript", "value": "prefer-for-of", @@ -4562,6 +4643,24 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-promise-reject-errors.html" }, + { + "scope": "typescript", + "value": "prefer-readonly", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-readonly.html" + }, + { + "scope": "typescript", + "value": "prefer-readonly-parameter-types", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-readonly-parameter-types.html" + }, { "scope": "typescript", "value": "prefer-reduce-type-parameter", @@ -4571,6 +4670,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-reduce-type-parameter.html" }, + { + "scope": "typescript", + "value": "prefer-regexp-exec", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-regexp-exec.html" + }, { "scope": "typescript", "value": "prefer-return-this-type", @@ -4580,6 +4688,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-return-this-type.html" }, + { + "scope": "typescript", + "value": "prefer-string-starts-ends-with", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": true, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/prefer-string-starts-ends-with.html" + }, { "scope": "typescript", "value": "prefer-ts-expect-error", @@ -4661,6 +4778,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/strict-boolean-expressions.html" }, + { + "scope": "typescript", + "value": "strict-void-return", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/strict-void-return.html" + }, { "scope": "typescript", "value": "switch-exhaustiveness-check", @@ -5858,6 +5984,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/vitest/no-import-node-test.html" }, + { + "scope": "vitest", + "value": "no-importing-vitest-globals", + "category": "style", + "type_aware": false, + "fix": "fixable_fix", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/vitest/no-importing-vitest-globals.html" + }, { "scope": "vitest", "value": "prefer-called-once", @@ -5894,6 +6029,15 @@ "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-expect-type-of.html" }, + { + "scope": "vitest", + "value": "prefer-import-in-mock", + "category": "style", + "type_aware": false, + "fix": "fixable_fix", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/vitest/prefer-import-in-mock.html" + }, { "scope": "vitest", "value": "prefer-to-be-falsy", diff --git a/src/docs/guide/usage/formatter/generated-config.md b/src/docs/guide/usage/formatter/generated-config.md index a3994c2bfd5..652fa65d84d 100644 --- a/src/docs/guide/usage/formatter/generated-config.md +++ b/src/docs/guide/usage/formatter/generated-config.md @@ -164,17 +164,12 @@ The list of modifiers is sorted from most to least important: - Default: See below ```json -[ - "type-import", - ["value-builtin", "value-external"], - "type-internal", - "value-internal", - ["type-parent", "type-sibling", "type-index"], - ["value-parent", "value-sibling", "value-index"], - "unknown" -] +["builtin", "external", ["internal", "subpath"], ["parent", "sibling", "index"], "style", "unknown"] ``` +Also, you can override the global `newlinesBetween` setting for specific group boundaries +by including a `{ "newlinesBetween": boolean }` marker object in the `groups` list at the desired position. + #### experimentalSortImports.groups[n] type: `array | string` @@ -582,17 +577,12 @@ The list of modifiers is sorted from most to least important: - Default: See below ```json -[ - "type-import", - ["value-builtin", "value-external"], - "type-internal", - "value-internal", - ["type-parent", "type-sibling", "type-index"], - ["value-parent", "value-sibling", "value-index"], - "unknown" -] +["builtin", "external", ["internal", "subpath"], ["parent", "sibling", "index"], "style", "unknown"] ``` +Also, you can override the global `newlinesBetween` setting for specific group boundaries +by including a `{ "newlinesBetween": boolean }` marker object in the `groups` list at the desired position. + ####### overrides[n].options.experimentalSortImports.groups[n] type: `array | string` 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 ad9e679af02..f71f6f8c227 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 @@ -60,6 +60,15 @@ default: `false` When set to true, allows callbacks of methods that require a return value to implicitly return undefined with a return statement containing no expression. +### allowVoid + +type: `boolean` + +default: `false` + +When set to true, rule will not report the return value with a void operator. +Works only if `checkForEach` option is set to true. + ### checkForEach type: `boolean` diff --git a/src/docs/guide/usage/linter/rules/typescript/no-use-before-define.md b/src/docs/guide/usage/linter/rules/eslint/no-use-before-define.md similarity index 89% rename from src/docs/guide/usage/linter/rules/typescript/no-use-before-define.md rename to src/docs/guide/usage/linter/rules/eslint/no-use-before-define.md index 9f7561f94e1..7036a5e7be9 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-use-before-define.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-use-before-define.md @@ -1,5 +1,5 @@ --- -title: "typescript/no-use-before-define" +title: "eslint/no-use-before-define" category: "Restriction" default: false type_aware: false @@ -10,7 +10,7 @@ fix: "none" @@ -109,13 +109,13 @@ To **enable** this rule using the config file or in the CLI, you can use: ```json [Config (.oxlintrc.json)] { "rules": { - "typescript/no-use-before-define": "error" + "no-use-before-define": "error" } } ``` ```bash [CLI] -oxlint --deny typescript/no-use-before-define +oxlint --deny no-use-before-define ``` ::: diff --git a/src/docs/guide/usage/linter/rules/eslint/radix.md b/src/docs/guide/usage/linter/rules/eslint/radix.md index 77b9ce9bc70..f2ee1c974f9 100644 --- a/src/docs/guide/usage/linter/rules/eslint/radix.md +++ b/src/docs/guide/usage/linter/rules/eslint/radix.md @@ -42,18 +42,6 @@ Examples of **correct** code for this rule: var num = parseInt("071", 10); // 71 ``` -## Configuration - -This rule accepts one of the following string values: - -### `"always"` - -Always require the radix parameter when using `parseInt()`. - -### `"as-needed"` - -Only require the radix parameter when necessary. - ## How to use To **enable** this rule using the config file or in the CLI, you can use: diff --git a/src/docs/guide/usage/linter/rules/jest/prefer-mock-return-shorthand.md b/src/docs/guide/usage/linter/rules/jest/prefer-mock-return-shorthand.md new file mode 100644 index 00000000000..f44ce247dc8 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/jest/prefer-mock-return-shorthand.md @@ -0,0 +1,93 @@ +--- +title: "jest/prefer-mock-return-shorthand" +category: "Style" +default: false +type_aware: false +fix: "fixable_fix" +--- + + + + + + + +### What it does + +When working with mocks of functions that return simple values, Jest provides some API sugar functions to reduce the amount of boilerplate you have to write. + +### Why is this bad? + +Not using Jest’s API sugar functions adds unnecessary boilerplate and makes tests harder to read. These helpers clearly express intent +and reduce errors, keeping tests simple and maintainable. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +jest.fn().mockImplementation(() => "hello world"); + +jest + .spyOn(fs.promises, "readFile") + .mockImplementationOnce(() => Promise.reject(new Error("oh noes!"))); + +myFunction + .mockImplementationOnce(() => 42) + .mockImplementationOnce(() => Promise.resolve(42)) + .mockReturnValue(0); +``` + +Examples of **correct** code for this rule: + +```js +jest.fn().mockResolvedValue(123); + +jest.spyOn(fs.promises, "readFile").mockReturnValue(Promise.reject(new Error("oh noes!"))); +jest.spyOn(fs.promises, "readFile").mockRejectedValue(new Error("oh noes!")); + +jest.spyOn(fs, "readFileSync").mockImplementationOnce(() => { + throw new Error("oh noes!"); +}); + +myFunction.mockResolvedValueOnce(42).mockResolvedValueOnce(42).mockReturnValue(0); +``` + +This rule is compatible with [eslint-plugin-vitest](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-mock-return-shorthand.md), +to use it, add the following configuration to your `.oxlintrc.json`: + +```json +{ + "rules": { + "vitest/prefer-mock-return-shorthand": "error" + } +} +``` + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["jest"], + "rules": { + "jest/prefer-mock-return-shorthand": "error" + } +} +``` + +```bash [CLI] +oxlint --deny jest/prefer-mock-return-shorthand --jest-plugin +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/node/no-path-concat.md b/src/docs/guide/usage/linter/rules/node/no-path-concat.md new file mode 100644 index 00000000000..7ba77ae5af9 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/node/no-path-concat.md @@ -0,0 +1,80 @@ +--- +title: "node/no-path-concat" +category: "Restriction" +default: false +type_aware: false +fix: "none" +--- + + + + + + + +### What it does + +Disallows string concatenation with `__dirname` and `__filename`. + +### Why is this bad? + +In Node.js, the `__dirname` and `__filename` global variables contain the directory path and the file path of the currently executing script file, respectively. +Sometimes, developers try to use these variables to create paths to other files, such as: + +```js +var fullPath = __dirname + "/foo.js"; +``` + +However, this is error-prone because it doesn't account for different +operating systems, which use different path separators. Using `path.join()` +or `path.resolve()` is the proper way to create cross-platform file paths. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +const fullPath1 = __dirname + "/foo.js"; +const fullPath2 = __filename + "/foo.js"; +const fullPath3 = `${__dirname}/foo.js`; +const fullPath4 = `${__filename}/foo.js`; +``` + +Examples of **correct** code for this rule: + +```js +const fullPath1 = path.join(__dirname, "foo.js"); +const fullPath2 = path.join(__filename, "foo.js"); +const fullPath3 = __dirname + ".js"; +const fullPath4 = __filename + ".map"; +const fullPath5 = `${__dirname}_foo.js`; +const fullPath6 = `${__filename}.test.js`; +``` + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["node"], + "rules": { + "node/no-path-concat": "error" + } +} +``` + +```bash [CLI] +oxlint --deny node/no-path-concat --node-plugin +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/react/no-unknown-property.md b/src/docs/guide/usage/linter/rules/react/no-unknown-property.md index e59302ce6e6..f17eb82bffc 100644 --- a/src/docs/guide/usage/linter/rules/react/no-unknown-property.md +++ b/src/docs/guide/usage/linter/rules/react/no-unknown-property.md @@ -21,7 +21,7 @@ Disallow usage of unknown DOM properties. ### Why is this bad? -You can use unknown property name that has no effect. +DOM properties should only be used if they are valid for a given HTML element. ### Examples diff --git a/src/docs/guide/usage/linter/rules/typescript/consistent-return.md b/src/docs/guide/usage/linter/rules/typescript/consistent-return.md new file mode 100644 index 00000000000..ad86451a82a --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/consistent-return.md @@ -0,0 +1,87 @@ +--- +title: "typescript/consistent-return" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Enforce consistent return behavior in functions. + +### Why is this bad? + +Mixing value-returning and non-value-returning code paths makes control flow harder to +reason about and frequently indicates a bug. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +function maybe(flag: boolean): number { + if (flag) { + return 1; + } + return; +} +``` + +Examples of **correct** code for this rule: + +```ts +function maybe(flag: boolean): number { + if (flag) { + return 1; + } + return 0; +} +``` + +## Configuration + +This rule accepts a configuration object with the following properties: + +### treatUndefinedAsUnspecified + +type: `boolean` + +default: `false` + +Treat explicit `return undefined` as equivalent to an unspecified return. + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/consistent-return": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/consistent-return +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/consistent-type-exports.md b/src/docs/guide/usage/linter/rules/typescript/consistent-type-exports.md new file mode 100644 index 00000000000..ab59220987d --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/consistent-type-exports.md @@ -0,0 +1,84 @@ +--- +title: "typescript/consistent-type-exports" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Enforce using `export type` for exports that are only used as types. + +### Why is this bad? + +Mixing type-only exports with value exports without `export type` makes module intent +harder to read and can cause unnecessary runtime export surface. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +type Foo = { bar: string }; +export { Foo }; + +export { TypeOnly, value } from "./mod"; +``` + +Examples of **correct** code for this rule: + +```ts +type Foo = { bar: string }; +export type { Foo }; + +export type { TypeOnly } from "./mod"; +export { value } from "./mod"; +``` + +## Configuration + +This rule accepts a configuration object with the following properties: + +### fixMixedExportsWithInlineTypeSpecifier + +type: `boolean` + +default: `false` + +Enables an autofix strategy that rewrites mixed exports using inline `type` specifiers. + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/consistent-type-exports": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/consistent-type-exports +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/dot-notation.md b/src/docs/guide/usage/linter/rules/typescript/dot-notation.md new file mode 100644 index 00000000000..331daf98831 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/dot-notation.md @@ -0,0 +1,114 @@ +--- +title: "typescript/dot-notation" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Enforce dot notation whenever property access can be written safely as `obj.prop`. + +### Why is this bad? + +Dot notation is generally more readable and concise than bracket notation for static +property names. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +obj["name"]; +foo["bar"]; +``` + +Examples of **correct** code for this rule: + +```ts +obj.name; +foo.bar; + +obj[key]; +obj["not-an-identifier"]; +``` + +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowIndexSignaturePropertyAccess + +type: `boolean` + +default: `false` + +Allow bracket notation for properties covered by an index signature. + +### allowKeywords + +type: `boolean` + +default: `true` + +Allow bracket notation for ES3 keyword property names (for example `obj["class"]`). + +### allowPattern + +type: `string` + +default: `""` + +Regex pattern for property names that are allowed to use bracket notation. + +### allowPrivateClassPropertyAccess + +type: `boolean` + +default: `false` + +Allow bracket notation for private class members. + +### allowProtectedClassPropertyAccess + +type: `boolean` + +default: `false` + +Allow bracket notation for protected class members. + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/dot-notation": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/dot-notation +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-qualifier.md b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-qualifier.md new file mode 100644 index 00000000000..68dd889a000 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-qualifier.md @@ -0,0 +1,70 @@ +--- +title: "typescript/no-unnecessary-qualifier" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Disallow namespace qualifiers when the referenced name is already in scope. + +### Why is this bad? + +Redundant qualifiers add noise and make type references harder to read. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +namespace A { + export type B = number; + const value: A.B = 1; +} +``` + +Examples of **correct** code for this rule: + +```ts +namespace A { + export type B = number; + const value: B = 1; +} +``` + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/no-unnecessary-qualifier": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/no-unnecessary-qualifier +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-parameters.md b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-parameters.md new file mode 100644 index 00000000000..c5e9da1fe86 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-parameters.md @@ -0,0 +1,73 @@ +--- +title: "typescript/no-unnecessary-type-parameters" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Disallow type parameters that are declared but not meaningfully used. + +### Why is this bad? + +Unnecessary type parameters make signatures noisier and harder to understand, and they +often hide opportunities to simplify APIs. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +function parseYAML(input: string): T { + return input as any as T; +} +``` + +Examples of **correct** code for this rule: + +```ts +function parseYAML(input: string): unknown { + return input; +} + +function identity(value: T): T { + return value; +} +``` + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/no-unnecessary-type-parameters": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/no-unnecessary-type-parameters +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/no-useless-default-assignment.md b/src/docs/guide/usage/linter/rules/typescript/no-useless-default-assignment.md new file mode 100644 index 00000000000..eca6b7359de --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/no-useless-default-assignment.md @@ -0,0 +1,65 @@ +--- +title: "typescript/no-useless-default-assignment" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Disallow default assignments that can never be used. + +### Why is this bad? + +A default assignment is redundant when the value can never be `undefined`. +This adds runtime logic and noise without changing behavior. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +[1, 2, 3].map((a = 0) => a + 1); +``` + +Examples of **correct** code for this rule: + +```ts +[1, 2, 3].map((a) => a + 1); +``` + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/no-useless-default-assignment": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/no-useless-default-assignment +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/prefer-find.md b/src/docs/guide/usage/linter/rules/typescript/prefer-find.md new file mode 100644 index 00000000000..1968c170c20 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/prefer-find.md @@ -0,0 +1,65 @@ +--- +title: "typescript/prefer-find" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Prefer `.find(...)` over `.filter(...)[0]` for retrieving a single element. + +### Why is this bad? + +`.filter(...)[0]` builds an intermediate array and is less clear about intent. +`.find(...)` directly expresses that only the first matching element is needed. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +const first = list.filter((item) => item.active)[0]; +``` + +Examples of **correct** code for this rule: + +```ts +const first = list.find((item) => item.active); +``` + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/prefer-find": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/prefer-find +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/prefer-readonly-parameter-types.md b/src/docs/guide/usage/linter/rules/typescript/prefer-readonly-parameter-types.md new file mode 100644 index 00000000000..940b98b2ad9 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/prefer-readonly-parameter-types.md @@ -0,0 +1,149 @@ +--- +title: "typescript/prefer-readonly-parameter-types" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Require function and method parameters to use readonly-compatible types. + +### Why is this bad? + +Mutable parameter types make accidental mutation easier and weaken function contracts. +Readonly parameter types communicate intent and improve API safety. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +function update(items: string[]) { + items.push("x"); +} + +function consume(obj: { value: string }) { + obj.value = obj.value.trim(); +} +``` + +Examples of **correct** code for this rule: + +```ts +function update(items: readonly string[]) { + return items.length; +} + +function consume(obj: Readonly<{ value: string }>) { + return obj.value; +} +``` + +## Configuration + +This rule accepts a configuration object with the following properties: + +### allow + +type: `array` + +default: `[]` + +Type/value specifiers that should be exempt from this rule. + +#### allow[n] + +type: `string` + +Type or value specifier for matching specific declarations + +Supports four types of specifiers: + +1. **String specifier** (deprecated): Universal match by name + +```json +"Promise" +``` + +2. **File specifier**: Match types/values declared in local files + +```json +{ "from": "file", "name": "MyType" } +{ "from": "file", "name": ["Type1", "Type2"] } +{ "from": "file", "name": "MyType", "path": "./types.ts" } +``` + +3. **Lib specifier**: Match TypeScript built-in lib types + +```json +{ "from": "lib", "name": "Promise" } +{ "from": "lib", "name": ["Promise", "PromiseLike"] } +``` + +4. **Package specifier**: Match types/values from npm packages + +```json +{ "from": "package", "name": "Observable", "package": "rxjs" } +{ "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" } +``` + +### checkParameterProperties + +type: `boolean` + +default: `true` + +Whether to check constructor parameter properties. + +### ignoreInferredTypes + +type: `boolean` + +default: `false` + +Whether to ignore parameters without explicit type annotations. + +### treatMethodsAsReadonly + +type: `boolean` + +default: `false` + +Whether mutable methods should be treated as readonly members. + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/prefer-readonly-parameter-types": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/prefer-readonly-parameter-types +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/prefer-readonly.md b/src/docs/guide/usage/linter/rules/typescript/prefer-readonly.md new file mode 100644 index 00000000000..81670c84598 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/prefer-readonly.md @@ -0,0 +1,89 @@ +--- +title: "typescript/prefer-readonly" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Require class members that are never reassigned to be marked `readonly`. + +### Why is this bad? + +Members that never change should be declared `readonly` to make class invariants explicit +and prevent accidental mutation. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +class Counter { + private value = 0; + + getValue() { + return this.value; + } +} +``` + +Examples of **correct** code for this rule: + +```ts +class Counter { + private readonly value = 0; + + getValue() { + return this.value; + } +} +``` + +## Configuration + +This rule accepts a configuration object with the following properties: + +### onlyInlineLambdas + +type: `boolean` + +default: `false` + +Restrict checks to members immediately initialized with inline lambda values. + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/prefer-readonly": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/prefer-readonly +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/prefer-regexp-exec.md b/src/docs/guide/usage/linter/rules/typescript/prefer-regexp-exec.md new file mode 100644 index 00000000000..0c5ce3153f6 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/prefer-regexp-exec.md @@ -0,0 +1,67 @@ +--- +title: "typescript/prefer-regexp-exec" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Prefer `RegExp#exec()` over `String#match()` when extracting a regex match. + +### Why is this bad? + +`exec()` is more explicit about matching with a regular expression and avoids the +overloaded behavior of `String#match()`. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +const text = "value"; +text.match(/v/); +``` + +Examples of **correct** code for this rule: + +```ts +const text = "value"; +/v/.exec(text); +``` + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/prefer-regexp-exec": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/prefer-regexp-exec +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/prefer-string-starts-ends-with.md b/src/docs/guide/usage/linter/rules/typescript/prefer-string-starts-ends-with.md new file mode 100644 index 00000000000..39ac27c8578 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/prefer-string-starts-ends-with.md @@ -0,0 +1,79 @@ +--- +title: "typescript/prefer-string-starts-ends-with" +category: "Nursery" +default: true +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Prefer `startsWith` and `endsWith` over manual string boundary checks. + +### Why is this bad? + +Boundary checks written with `slice`, `indexOf`, regex anchors, or manual indexing are +harder to read and maintain than `startsWith`/`endsWith`. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +value.slice(0, 3) === "foo"; +value.slice(-3) === "bar"; +``` + +Examples of **correct** code for this rule: + +```ts +value.startsWith("foo"); +value.endsWith("bar"); +``` + +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowSingleElementEquality + +type: `"always" | "never"` + +default: `null` + +Whether equality checks against the first/last character are allowed. + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/prefer-string-starts-ends-with": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/prefer-string-starts-ends-with +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/strict-void-return.md b/src/docs/guide/usage/linter/rules/typescript/strict-void-return.md new file mode 100644 index 00000000000..db4ca3f506f --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/strict-void-return.md @@ -0,0 +1,86 @@ +--- +title: "typescript/strict-void-return" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Disallow returning non-void values where a `void` return is expected. + +### Why is this bad? + +Returning values from `void` contexts can hide logic errors and make callback APIs +behave unexpectedly. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +declare function run(cb: () => void): void; + +run(() => "value"); +run(async () => 123); +``` + +Examples of **correct** code for this rule: + +```ts +declare function run(cb: () => void): void; + +run(() => { + doWork(); +}); + +run(() => undefined); +``` + +## Configuration + +This rule accepts a configuration object with the following properties: + +### allowReturnAny + +type: `boolean` + +default: `false` + +Allow callbacks that return `any` in places that expect a `void` callback. + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "typescript/strict-void-return": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/strict-void-return +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-unnecessary-array-flat-depth.md b/src/docs/guide/usage/linter/rules/unicorn/no-unnecessary-array-flat-depth.md index 0eb144ffbcf..5842e46fb47 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-unnecessary-array-flat-depth.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-unnecessary-array-flat-depth.md @@ -17,7 +17,7 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallows passing `1` to `Array.prototype.flat` +Disallows passing `1` to `Array.prototype.flat`. ### Why is this bad? diff --git a/src/docs/guide/usage/linter/rules/version.data.js b/src/docs/guide/usage/linter/rules/version.data.js index 97256790f0e..34d374d978a 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 "7673818e81e030dce4f5f70f023b8756a38049ba"; + return "82ca5c3dfa0e389a099666107a669e95b54587ce"; }, }; diff --git a/src/docs/guide/usage/linter/rules/vitest/no-importing-vitest-globals.md b/src/docs/guide/usage/linter/rules/vitest/no-importing-vitest-globals.md new file mode 100644 index 00000000000..922c1d2059d --- /dev/null +++ b/src/docs/guide/usage/linter/rules/vitest/no-importing-vitest-globals.md @@ -0,0 +1,78 @@ +--- +title: "vitest/no-importing-vitest-globals" +category: "Style" +default: false +type_aware: false +fix: "fixable_fix" +--- + + + + + + + +### What it does + +The rule disallows import any vitest global function. + +### Why is this bad? + +If the project is configured to use globals from vitest, the rule ensure +that never imports the globals from `import` or `require`. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +import { test, expect } from "vitest"; + +test("foo", () => { + expect(1).toBe(1); +}); +``` + +```js +const { test, expect } = require("vitest"); + +test("foo", () => { + expect(1).toBe(1); +}); +``` + +Examples of **correct** code for this rule: + +```js +test("foo", () => { + expect(1).toBe(1); +}); +``` + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["vitest"], + "rules": { + "vitest/no-importing-vitest-globals": "error" + } +} +``` + +```bash [CLI] +oxlint --deny vitest/no-importing-vitest-globals --vitest-plugin +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/vitest/prefer-import-in-mock.md b/src/docs/guide/usage/linter/rules/vitest/prefer-import-in-mock.md new file mode 100644 index 00000000000..ad79bc84ab4 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/vitest/prefer-import-in-mock.md @@ -0,0 +1,71 @@ +--- +title: "vitest/prefer-import-in-mock" +category: "Style" +default: false +type_aware: false +fix: "fixable_fix" +--- + + + + + + + +### What it does + +This rule enforces using a dynamic import() in `vi.mock()`, which improves type information and IntelliSense for the mocked module. + +### Why is this bad? + +A lack of type information and IntelliSense increase the risk of mismatches between the real module and it's mock. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +vi.mock("./path/to/module"); +``` + +Examples of **correct** code for this rule: + +```js +vi.mock(import("./path/to/module")); +``` + +## Configuration + +This rule accepts a configuration object with the following properties: + +### fixable + +type: `boolean` + +## How to use + +To **enable** this rule using the config file or in the CLI, you can use: + +::: code-group + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["vitest"], + "rules": { + "vitest/prefer-import-in-mock": "error" + } +} +``` + +```bash [CLI] +oxlint --deny vitest/prefer-import-in-mock --vitest-plugin +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/rule-count.data.js b/src/docs/guide/usage/rule-count.data.js index b37df5fe472..432ae19e40f 100644 --- a/src/docs/guide/usage/rule-count.data.js +++ b/src/docs/guide/usage/rule-count.data.js @@ -1,5 +1,5 @@ export default { load() { - return 677; + return 693; }, };