diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index 37c35c72aa..68dd4f7733 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: 520 +- Total number of rules: 521 - Rules turned on by default: 123 **Legend for 'Fixable?' column:** @@ -213,7 +213,7 @@ Code that can be written to run faster. | [prefer-array-find](/docs/guide/usage/linter/rules/unicorn/prefer-array-find.html) | unicorn | | 🚧 | | [prefer-set-has](/docs/guide/usage/linter/rules/unicorn/prefer-set-has.html) | unicorn | | ⚠️🛠️️ | -## Restriction (66): +## Restriction (67): 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. @@ -238,6 +238,7 @@ Lints which prevent the use of language and library features. Must not be enable | [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 | | 🛠️ | +| [extensions](/docs/guide/usage/linter/rules/import/extensions.html) | import | | | | [no-amd](/docs/guide/usage/linter/rules/import/no-amd.html) | import | | | | [no-commonjs](/docs/guide/usage/linter/rules/import/no-commonjs.html) | import | | | | [no-cycle](/docs/guide/usage/linter/rules/import/no-cycle.html) | import | | | diff --git a/src/docs/guide/usage/linter/rules/eslint/no-console.md b/src/docs/guide/usage/linter/rules/eslint/no-console.md index 119ab1e371..90ff28ed48 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-console.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-console.md @@ -9,7 +9,7 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin
-💡 A suggestion is available for this rule. +💡 A suggestion is available for this rule for some violations.
diff --git a/src/docs/guide/usage/linter/rules/eslint/no-var.md b/src/docs/guide/usage/linter/rules/eslint/no-var.md index b9f783a6a2..7bd67abb76 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-var.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-var.md @@ -9,7 +9,7 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin
-🛠️ An auto-fix is available for this rule. +🛠️ An auto-fix is available for this rule for some violations.
diff --git a/src/docs/guide/usage/linter/rules/import/extensions.md b/src/docs/guide/usage/linter/rules/import/extensions.md new file mode 100644 index 0000000000..a0524e4a63 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/import/extensions.md @@ -0,0 +1,91 @@ + + + + +# import/extensions + +
+
+ +### What it does + +Some file resolve algorithms allow you to omit the file extension within the import source path. +For example the node resolver (which does not yet support ESM/import) can resolve ./foo/bar to the absolute path /User/someone/foo/bar.js because the .js extension is resolved automatically by default in CJS. +Depending on the resolver you can configure more extensions to get resolved automatically. +In order to provide a consistent use of file extensions across your code base, this rule can enforce or disallow the use of certain file extensions. + +### Why is this bad? + +ESM-based file resolve algorithms (e.g., the one that Vite provides) recommend specifying the file extension to improve performance. + +### Examples + +Examples of **incorrect** code for this rule: + +The following patterns are considered problems when configuration set to "always": + +```js +import foo from "@/foo"; +import bar from "./bar"; +import Component from "./Component"; +import foo from "./foo"; +``` + +The following patterns are considered problems when configuration set to "never": + +```js +import express from "express/index.js"; +import bar from "./bar.json"; +import Component from "./Component.jsx"; +import foo from "./foo.js"; +``` + +Examples of **correct** code for this rule: + +The following patterns are not considered problems when configuration set to "always": + +```js +import foo from "@/foo.js"; +import * as path from "path"; +import bar from "./bar.json"; +import Component from "./Component.jsx"; +import foo from "./foo.js"; +``` + +The following patterns are not considered problems when configuration set to "never": + +```js +import express from "express/index"; +import * as path from "path"; +import bar from "./bar"; +import Component from "./Component"; +import foo 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/extensions --import-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["import"], + "rules": { + "import/extensions": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/import/no-namespace.md b/src/docs/guide/usage/linter/rules/import/no-namespace.md index d54f3718c3..50c9683ec8 100644 --- a/src/docs/guide/usage/linter/rules/import/no-namespace.md +++ b/src/docs/guide/usage/linter/rules/import/no-namespace.md @@ -42,7 +42,7 @@ Namespaced imports, while sometimes used, are generally considered less ideal in ```json { - "ignores": ["*.json"] + "ignore": ["*.json"] } ``` diff --git a/src/docs/guide/usage/linter/rules/jest/valid-expect.md b/src/docs/guide/usage/linter/rules/jest/valid-expect.md index 5df4436aad..67613d1e7f 100644 --- a/src/docs/guide/usage/linter/rules/jest/valid-expect.md +++ b/src/docs/guide/usage/linter/rules/jest/valid-expect.md @@ -19,7 +19,9 @@ Checks that `expect()` is called correctly. ### Why is this bad? -`expect()` is a function that is used to assert values in tests. It should be called with a single argument, which is the value to be tested. If you call `expect()` with no arguments, or with more than one argument, it will not work as expected. +`expect()` is a function that is used to assert values in tests. +It should be called with a single argument, which is the value to be tested. +If you call `expect()` with no arguments, or with more than one argument, it will not work as expected. ### Examples diff --git a/src/docs/guide/usage/linter/rules/typescript/array-type.md b/src/docs/guide/usage/linter/rules/typescript/array-type.md index 38aad92a80..699ea7f49c 100644 --- a/src/docs/guide/usage/linter/rules/typescript/array-type.md +++ b/src/docs/guide/usage/linter/rules/typescript/array-type.md @@ -35,6 +35,14 @@ const arr: Array = new Array(); const arr: number[] = new Array(); ``` +```typescript +/*oxlint array-type: ["error", { "default": "array-simple" }] */ +const a: (string | number)[] = ["a", "b"]; +const b: { prop: string }[] = [{ prop: "a" }]; +const c: Array = ["a", "b"]; +const d: Array = ["a", "b"]; +``` + Examples of **correct** code for this rule: ```typescript @@ -47,6 +55,33 @@ const arr: number[] = new Array(); const arr: Array = new Array(); ``` +```typescript +/*oxlint array-type: ["error", { "default": "array-simple" }] */ +const a: Array = ["a", "b"]; +const b: Array<{ prop: string }> = [{ prop: "a" }]; +const c: string[] = ["a", "b"]; +const d: MyType[] = ["a", "b"]; +``` + +### Options + +```json +{ + "typescript/array-type": ["error", { "default": "array", "readonly": "array" }] +} +``` + +- `default`: The array type expected for mutable cases. +- `readonly`: The array type expected for readonly cases. If omitted, the value for `default` will be used. + +Both `default` and `readonly` can be one of: + +- `"array"` +- `"generic"` +- `"array-simple"` + +The default config will enforce that all mutable and readonly arrays use the 'array' syntax. + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/version.data.js b/src/docs/guide/usage/linter/rules/version.data.js index 92ae4b99f7..22946f8c6e 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 "40ca1ef8d4b2e923caf723ebd190a9d52efeaef5"; + return "08e666fc2da750dc6e8659f1e71b0766058516d6"; }, };