diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index 68dd4f7733..b39ae5bc06 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: 521 +- Total number of rules: 524 - 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 (67): +## 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. @@ -281,13 +281,12 @@ Lints which prevent the use of language and library features. Must not be enable | [no-document-cookie](/docs/guide/usage/linter/rules/unicorn/no-document-cookie.html) | unicorn | | | | [no-length-as-slice-end](/docs/guide/usage/linter/rules/unicorn/no-length-as-slice-end.html) | unicorn | | πŸ› οΈ | | [no-magic-array-flat-depth](/docs/guide/usage/linter/rules/unicorn/no-magic-array-flat-depth.html) | unicorn | | | -| [no-nested-ternary](/docs/guide/usage/linter/rules/unicorn/no-nested-ternary.html) | unicorn | | πŸ› οΈ | | [no-process-exit](/docs/guide/usage/linter/rules/unicorn/no-process-exit.html) | unicorn | | 🚧 | | [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 | | βš οΈπŸ› οΈοΈ | -## Suspicious (34): +## Suspicious (33): code that is most likely wrong or useless. @@ -302,7 +301,6 @@ code that is most likely wrong or useless. | [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 | | πŸ› οΈ | | [no-absolute-path](/docs/guide/usage/linter/rules/import/no-absolute-path.html) | import | | 🚧 | -| [no-duplicates](/docs/guide/usage/linter/rules/import/no-duplicates.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 | | | | [no-named-as-default-member](/docs/guide/usage/linter/rules/import/no-named-as-default-member.html) | import | | | @@ -417,12 +415,13 @@ 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 (144): +## Style (149): Code that should be written in a more idiomatic way. | Rule name | Source | Default | Fixable? | | ------------------------------------------------------------------------------------------------------------------------ | ---------- | ------- | -------- | +| [arrow-body-style](/docs/guide/usage/linter/rules/eslint/arrow-body-style.html) | eslint | | 🚧 | | [curly](/docs/guide/usage/linter/rules/eslint/curly.html) | eslint | | πŸ› οΈ | | [default-case-last](/docs/guide/usage/linter/rules/eslint/default-case-last.html) | eslint | | | | [default-param-last](/docs/guide/usage/linter/rules/eslint/default-param-last.html) | eslint | | | @@ -430,6 +429,7 @@ Code that should be written in a more idiomatic way. | [func-style](/docs/guide/usage/linter/rules/eslint/func-style.html) | eslint | | 🚧 | | [grouped-accessor-pairs](/docs/guide/usage/linter/rules/eslint/grouped-accessor-pairs.html) | eslint | | 🚧 | | [guard-for-in](/docs/guide/usage/linter/rules/eslint/guard-for-in.html) | eslint | | | +| [id-length](/docs/guide/usage/linter/rules/eslint/id-length.html) | eslint | | | | [init-declarations](/docs/guide/usage/linter/rules/eslint/init-declarations.html) | eslint | | | | [max-params](/docs/guide/usage/linter/rules/eslint/max-params.html) | eslint | | | | [new-cap](/docs/guide/usage/linter/rules/eslint/new-cap.html) | eslint | | 🚧 | @@ -465,9 +465,11 @@ Code that should be written in a more idiomatic way. | [first](/docs/guide/usage/linter/rules/import/first.html) | import | | 🚧 | | [group-exports](/docs/guide/usage/linter/rules/import/group-exports.html) | import | | | | [no-anonymous-default-export](/docs/guide/usage/linter/rules/import/no-anonymous-default-export.html) | import | | | +| [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-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 | | πŸ› οΈ | | [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 | | | @@ -539,6 +541,7 @@ Code that should be written in a more idiomatic way. | [no-array-method-this-argument](/docs/guide/usage/linter/rules/unicorn/no-array-method-this-argument.html) | unicorn | | 🚧 | | [no-await-expression-member](/docs/guide/usage/linter/rules/unicorn/no-await-expression-member.html) | unicorn | | βš οΈπŸ› οΈοΈ | | [no-console-spaces](/docs/guide/usage/linter/rules/unicorn/no-console-spaces.html) | unicorn | | πŸ› οΈ | +| [no-nested-ternary](/docs/guide/usage/linter/rules/unicorn/no-nested-ternary.html) | unicorn | | πŸ› οΈ | | [no-null](/docs/guide/usage/linter/rules/unicorn/no-null.html) | unicorn | | πŸ› οΈ | | [no-unreadable-array-destructuring](/docs/guide/usage/linter/rules/unicorn/no-unreadable-array-destructuring.html) | unicorn | | | | [no-zero-fractions](/docs/guide/usage/linter/rules/unicorn/no-zero-fractions.html) | unicorn | | πŸ› οΈ | diff --git a/src/docs/guide/usage/linter/rules/eslint/arrow-body-style.md b/src/docs/guide/usage/linter/rules/eslint/arrow-body-style.md new file mode 100644 index 0000000000..f5c6c7e8b6 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/eslint/arrow-body-style.md @@ -0,0 +1,135 @@ + + + + +# eslint/arrow-body-style + +
+ +🚧 An auto-fix is still under development. + +
+ +### What it does + +This rule can enforce or disallow the use of braces around arrow function body. + +### Why is this bad? + +Arrow functions have two syntactic forms for their function bodies. +They may be defined with a block body (denoted by curly braces) () => { ... } +or with a single expression () => ..., whose value is implicitly returned. + +### Examples + +Examples of **incorrect** code for this rule with the `always` option: + +```js +const foo = () => 0; +``` + +Examples of **correct** code for this rule with the `always` option: + +```js +const foo = () => { + return 0; +}; +``` + +Examples of **incorrect** code for this rule with the `as-needed` option: + +```js +const foo = () => { + return 0; +}; +``` + +Examples of **correct** code for this rule with the `as-needed` option: + +```js +const foo1 = () => 0; + +const foo2 = (retv, name) => { + retv[name] = true; + return retv; +}; +``` + +Examples of **incorrect** code for this rule with the { "requireReturnForObjectLiteral": true } option: + +```js +/* arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/ +const foo = () => ({}); +const bar = () => ({ bar: 0 }); +``` + +Examples of **correct** code for this rule with the { "requireReturnForObjectLiteral": true } option: + +```js +/* arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/ +const foo = () => {}; +const bar = () => { + return { bar: 0 }; +}; +``` + +Examples of **incorrect** code for this rule with the `never` option: + +```js +const foo = () => { + return 0; +}; +``` + +Examples of **correct** code for this rule with the `never` option: + +```js +const foo = () => 0; +const bar = () => ({ foo: 0 }); +``` + +### Options + +The rule takes one or two options. The first is a string, which can be: + +- `always` enforces braces around the function body +- `never` enforces no braces where they can be omitted (default) +- `as-needed` enforces no braces around the function body (constrains arrow functions to the role of returning an expression) + +The second one is an object for more fine-grained configuration +when the first option is "as-needed". Currently, +the only available option is requireReturnForObjectLiteral, a boolean property. +It’s false by default. If set to true, it requires braces and an explicit return for object literals. + +```json +{ + "arrow-body-style": ["error", "as-needed", { "requireReturnForObjectLiteral": true }] +} +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny arrow-body-style +``` + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "arrow-body-style": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/eslint/id-length.md b/src/docs/guide/usage/linter/rules/eslint/id-length.md new file mode 100644 index 0000000000..235ef4f49b --- /dev/null +++ b/src/docs/guide/usage/linter/rules/eslint/id-length.md @@ -0,0 +1,140 @@ + + + + +# eslint/id-length + +
+
+ +### What it does + +This rule enforces a minimum and/or maximum identifier length convention by counting the +graphemes for a given identifier. + +### Why is this bad? + +Very short identifier names like e, x, _t or very long ones like +hashGeneratorResultOutputContainerObject can make code harder to read and potentially less +maintainable. To prevent this, one may enforce a minimum and/or maximum identifier length. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +/*eslint id-length: "error"*/ +// default is minimum 2-chars ({ "min": 2 }) + +const x = 5; +obj.e = document.body; +const foo = function(e) {}; +try { + dangerousStuff(); +} catch (e) { + // ignore as many do +} +const myObj = { a: 1 }; +((a) => { + a * a; +}); +class y {} +class Foo { + x() {} +} +class Bar { + #x() {} +} +class Baz { + x = 1; +} +class Qux { + #x = 1; +} +function bar(...x) {} +function baz([x]) {} +const [z] = arr; +const { prop: [i] } = {}; +function qux({ x }) {} +const { j } = {}; +const { prop: a } = {}; +({ prop: obj.x } = {}); +``` + +Examples of **correct** code for this rule: + +```js +/*eslint id-length: "error"*/ +// default is minimum 2-chars ({ "min": 2 }) + +const num = 5; +function _f() { + return 42; +} +function _func() { + return 42; +} +obj.el = document.body; +const foo = function(evt) {/* do stuff */}; +try { + dangerousStuff(); +} catch (error) { + // ignore as many do +} +const myObj = { apple: 1 }; +((num) => { + num * num; +}); +function bar(num = 0) {} +class MyClass {} +class Foo { + method() {} +} +class Bar { + #method() {} +} +class Baz { + field = 1; +} +class Qux { + #field = 1; +} +function baz(...args) {} +function qux([longName]) {} +const { prop } = {}; +const { prop: [name] } = {}; +const [longName] = arr; +function foobar({ prop }) {} +function foobaz({ a: prop }) {} +const { a: property } = {}; +({ prop: obj.longName } = {}); +const data = { "x": 1 }; // excused because of quotes +data["y"] = 3; // excused because of calculated property access +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny id-length +``` + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "id-length": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/import/no-duplicates.md b/src/docs/guide/usage/linter/rules/import/no-duplicates.md index a5a1cf3cb5..a0d240abf5 100644 --- a/src/docs/guide/usage/linter/rules/import/no-duplicates.md +++ b/src/docs/guide/usage/linter/rules/import/no-duplicates.md @@ -5,7 +5,7 @@ import { data } from '../version.data.js'; const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_linter/src/rules/import/no_duplicates.rs`; -# import/no-duplicates +# import/no-duplicates
diff --git a/src/docs/guide/usage/linter/rules/import/prefer-default-export.md b/src/docs/guide/usage/linter/rules/import/prefer-default-export.md new file mode 100644 index 0000000000..0866f68061 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/import/prefer-default-export.md @@ -0,0 +1,74 @@ + + + + +# import/prefer-default-export + +
+
+ +### What it does + +In exporting files, this rule checks if there is default export or not. + +### Why is this bad? + +This rule exists to standardize module exports by preferring default exports +when a module only has one export, enhancing readability, maintainability. + +### Examples + +Examples of **incorrect** code for the `{ target: "single" }` option: + +```js +export const foo = "foo"; +``` + +Examples of **correct** code for the `{ target: "single" }` option: + +```js +export const foo = "foo"; +const bar = "bar"; +export default bar; +``` + +Examples of **incorrect** code for the `{ target: "any" }` option: + +```js +export const foo = "foo"; +export const baz = "baz"; +``` + +Examples of **correct** code for the `{ target: "any" }` option: + +```js +export default function bar() {} +``` + +## 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/prefer-default-export --import-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["import"], + "rules": { + "import/prefer-default-export": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/jest/valid-title.md b/src/docs/guide/usage/linter/rules/jest/valid-title.md index 809e365051..de081b9c6c 100644 --- a/src/docs/guide/usage/linter/rules/jest/valid-title.md +++ b/src/docs/guide/usage/linter/rules/jest/valid-title.md @@ -57,14 +57,16 @@ test("baz", () => {}); ### Options +```typescript interface Options { -ignoreSpaces?: boolean; -ignoreTypeOfTestName?: boolean; -ignoreTypeOfDescribeName?: boolean; -disallowedWords?: string[]; -mustNotMatch?: Partial> | string; -mustMatch?: Partial> | string; + ignoreSpaces?: boolean; + ignoreTypeOfTestName?: boolean; + ignoreTypeOfDescribeName?: boolean; + disallowedWords?: string[]; + mustNotMatch?: Partial> | string; + mustMatch?: Partial> | string; } +``` ## How to use diff --git a/src/docs/guide/usage/linter/rules/typescript/no-this-alias.md b/src/docs/guide/usage/linter/rules/typescript/no-this-alias.md index a9428b773a..89b25ba6e9 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-this-alias.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-this-alias.md @@ -21,7 +21,6 @@ Disallow aliasing `this` Assigning a variable to `this` instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well. -```` ## How to use To **enable** this rule in the CLI or using the config file, you can use: @@ -30,7 +29,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ```bash [CLI] oxlint --deny typescript/no-this-alias -```` +``` ```json [Config (.oxlintrc.json)] { diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-nested-ternary.md b/src/docs/guide/usage/linter/rules/unicorn/no-nested-ternary.md index 78b5da7627..9598346549 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-nested-ternary.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-nested-ternary.md @@ -5,7 +5,7 @@ import { data } from '../version.data.js'; const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs`; -# unicorn/no-nested-ternary +# unicorn/no-nested-ternary
diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-logical-operator-over-ternary.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-logical-operator-over-ternary.md index dc15a23b82..c9d7a568cc 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-logical-operator-over-ternary.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-logical-operator-over-ternary.md @@ -31,10 +31,12 @@ console.log(foo ? foo : bar); ``` Examples of **correct** code for this rule: + +```javascript const foo = bar || baz; console.log(foo ?? bar); +``` -```` ## How to use To **enable** this rule in the CLI or using the config file, you can use: @@ -43,7 +45,7 @@ To **enable** this rule in the CLI or using the config file, you can use: ```bash [CLI] oxlint --deny unicorn/prefer-logical-operator-over-ternary -```` +``` ```json [Config (.oxlintrc.json)] { diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-string-replace-all.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-string-replace-all.md index debba45bfc..022cb1665d 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-string-replace-all.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-string-replace-all.md @@ -26,7 +26,7 @@ The [`String#replaceAll()`](https://developer.mozilla.org/en-US/docs/Web/JavaScr Examples of **incorrect** code for this rule: ```js -array.reduceRight(reducer, initialValue); +foo.replace(/a/g, bar); ``` Examples of **correct** code for this rule: diff --git a/src/docs/guide/usage/linter/rules/version.data.js b/src/docs/guide/usage/linter/rules/version.data.js index 61c0e011eb..f88e7d050c 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 "94a418d201eac3e81ee295c2f7a4cebc695c7f34"; + return "f1c18d8db2c3f2994ecc8226d816bd8cffcb91df"; }, };