diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index 24a79e794ee..742ea5b82d6 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: 445 +- Total number of rules: 448 - Rules turned on by default: 97 ## Correctness (172): @@ -195,7 +195,7 @@ Code that can be written to run faster. | [jsx-no-new-function-as-prop](/docs/guide/usage/linter/rules/react_perf/jsx-no-new-function-as-prop.html) | react_perf | | | | [jsx-no-new-object-as-prop](/docs/guide/usage/linter/rules/react_perf/jsx-no-new-object-as-prop.html) | react_perf | | | -## Restriction (58): +## Restriction (59): 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. | Rule name | Source | Default | Fixable? | @@ -224,6 +224,7 @@ Lints which prevent the use of language and library features. Must not be enable | [no-default-export](/docs/guide/usage/linter/rules/import/no-default-export.html) | import | | | | [no-dynamic-require](/docs/guide/usage/linter/rules/import/no-dynamic-require.html) | import | | | | [no-webpack-loader-syntax](/docs/guide/usage/linter/rules/import/no-webpack-loader-syntax.html) | import | | | +| [unambiguous](/docs/guide/usage/linter/rules/import/unambiguous.html) | import | | | | [check-access](/docs/guide/usage/linter/rules/jsdoc/check-access.html) | jsdoc | | | | [empty-tags](/docs/guide/usage/linter/rules/jsdoc/empty-tags.html) | jsdoc | | | | [no-new-require](/docs/guide/usage/linter/rules/node/no-new-require.html) | node | | | @@ -287,7 +288,7 @@ code that is most likely wrong or useless. | [consistent-function-scoping](/docs/guide/usage/linter/rules/unicorn/consistent-function-scoping.html) | unicorn | | 🚧 | | [prefer-add-event-listener](/docs/guide/usage/linter/rules/unicorn/prefer-add-event-listener.html) | unicorn | | 🚧 | -## Pedantic (72): +## Pedantic (73): Lints which are rather strict or have occasional false positives. | Rule name | Source | Default | Fixable? | @@ -325,6 +326,7 @@ Lints which are rather strict or have occasional false positives. | [no-unescaped-entities](/docs/guide/usage/linter/rules/react/no-unescaped-entities.html) | react | | | | [ban-ts-comment](/docs/guide/usage/linter/rules/typescript/ban-ts-comment.html) | typescript | | 🛠️ | | [ban-types](/docs/guide/usage/linter/rules/typescript/ban-types.html) | typescript | | 🚧 | +| [no-unsafe-function-type](/docs/guide/usage/linter/rules/typescript/no-unsafe-function-type.html) | typescript | | | | [prefer-enum-initializers](/docs/guide/usage/linter/rules/typescript/prefer-enum-initializers.html) | typescript | | 🚧 | | [prefer-ts-expect-error](/docs/guide/usage/linter/rules/typescript/prefer-ts-expect-error.html) | typescript | | 🛠️ | | [consistent-empty-array-spread](/docs/guide/usage/linter/rules/unicorn/consistent-empty-array-spread.html) | unicorn | | 💡 | @@ -365,7 +367,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 (104): +## Style (105): Code that should be written in a more idiomatic way. | Rule name | Source | Default | Fixable? | @@ -389,6 +391,7 @@ Code that should be written in a more idiomatic way. | [prefer-object-has-own](/docs/guide/usage/linter/rules/eslint/prefer-object-has-own.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 | | 🚧 | +| [first](/docs/guide/usage/linter/rules/import/first.html) | import | | 🚧 | | [consistent-test-it](/docs/guide/usage/linter/rules/jest/consistent-test-it.html) | jest | | 🛠️ | | [max-expects](/docs/guide/usage/linter/rules/jest/max-expects.html) | jest | | | | [max-nested-describe](/docs/guide/usage/linter/rules/jest/max-nested-describe.html) | jest | | | diff --git a/src/docs/guide/usage/linter/rules/import/first.md b/src/docs/guide/usage/linter/rules/import/first.md new file mode 100644 index 00000000000..a0464b4c879 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/import/first.md @@ -0,0 +1,60 @@ + + +# import/first + +
+ +🚧 An auto-fix is still under development. + +
+ +### What it does + +Forbids any non-import statements before imports except directives. + +### Why is this bad? + +Notably, imports are hoisted, which means the imported modules will be evaluated +before any of the statements interspersed between them. +Keeping all imports together at the top of the file may prevent surprises +resulting from this part of the spec + +### Examples + +Examples of **incorrect** code for this rule: + +```js +import { x } from "./foo"; +export { x }; +import { y } from "./bar"; +``` + +Examples of **correct** code for this rule: + +```js +import { x } from "./foo"; +import { y } from "./bar"; +export { x, y }; +``` + +### Options + +with `"absolute-import"`: + +Examples of **incorrect** code for this rule: + +```js +import { x } from "./foo"; +import { y } from "bar"; +``` + +Examples of **correct** code for this rule: + +```js +import { y } from "bar"; +import { x } from "./foo"; +``` + +## References + +- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/import/first.rs) diff --git a/src/docs/guide/usage/linter/rules/import/unambiguous.md b/src/docs/guide/usage/linter/rules/import/unambiguous.md new file mode 100644 index 00000000000..79cd1b3d8a0 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/import/unambiguous.md @@ -0,0 +1,48 @@ + + +# import/unambiguous + +
+
+ +### What it does + +Warn if a `module` could be mistakenly parsed as a `script` and not pure ESM module + +### Why is this bad? + +For ESM-only environments helps to determine files that not pure ESM modules + +### Examples + +Examples of **incorrect** code for this rule: + +```js +function x() {} + +(function x() { + return 42; +})(); +``` + +Examples of **correct** code for this rule: + +```js +import "foo"; +function x() { + return 42; +} + +export function x() { + return 42; +} + +(function x() { + return 42; +})(); +export {}; // simple way to mark side-effects-only file as 'module' without any imports/exports +``` + +## References + +- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/import/unambiguous.rs) diff --git a/src/docs/guide/usage/linter/rules/typescript/no-unsafe-function-type.md b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-function-type.md new file mode 100644 index 00000000000..4fd1d827430 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/no-unsafe-function-type.md @@ -0,0 +1,46 @@ + + +# typescript/no-unsafe-function-type + +
+
+ +### What it does + +Disallow using the unsafe built-in Function type. + +### Why is this bad? + +TypeScript's built-in Function type allows being called with any number of arguments and returns type any. Function also allows classes or plain objects that happen to possess all properties of the Function class. It's generally better to specify function parameters and return types with the function type syntax. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +let noParametersOrReturn: Function; +noParametersOrReturn = () => {}; + +let stringToNumber: Function; +stringToNumber = (text: string) => text.length; + +let identity: Function; +identity = (value) => value; +``` + +Examples of **correct** code for this rule: + +```ts +let noParametersOrReturn: () => void; +noParametersOrReturn = () => {}; + +let stringToNumber: (text: string) => number; +stringToNumber = (text) => text.length; + +let identity: (value: T) => T; +identity = (value) => value; +``` + +## References + +- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/typescript/no_unsafe_function_type.rs)