diff --git a/.vitepress/data/rules.json b/.vitepress/data/rules.json index 2255f1d0df8..e66d5ae0e4c 100644 --- a/.vitepress/data/rules.json +++ b/.vitepress/data/rules.json @@ -1246,7 +1246,7 @@ "value": "no-useless-constructor", "category": "suspicious", "type_aware": false, - "fix": "fixable_fix", + "fix": "fixable_suggestion", "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-useless-constructor.html" }, @@ -4382,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-conversion", + "category": "nursery", + "type_aware": true, + "fix": "none", + "default": false, + "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-conversion.html" + }, { "scope": "typescript", "value": "no-unnecessary-type-parameters", @@ -5809,7 +5818,7 @@ "value": "prefer-string-slice", "category": "pedantic", "type_aware": false, - "fix": "fixable_fix", + "fix": "conditional_fix", "default": false, "docs_url": "https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-string-slice.html" }, diff --git a/src/docs/guide/usage/formatter/generated-config.md b/src/docs/guide/usage/formatter/generated-config.md index dd47c23bfee..227249cfff5 100644 --- a/src/docs/guide/usage/formatter/generated-config.md +++ b/src/docs/guide/usage/formatter/generated-config.md @@ -386,7 +386,11 @@ by including a `{ "newlinesBetween": boolean }` marker object in the `groups` li ####### overrides[n].options.sortImports.groups[n] -type: `array | string` +type: `object | array | string` + +######## overrides[n].options.sortImports.groups[n].newlinesBetween + +type: `boolean` ###### overrides[n].options.sortImports.ignoreCase @@ -771,7 +775,11 @@ by including a `{ "newlinesBetween": boolean }` marker object in the `groups` li #### sortImports.groups[n] -type: `array | string` +type: `object | array | string` + +##### sortImports.groups[n].newlinesBetween + +type: `boolean` ### sortImports.ignoreCase diff --git a/src/docs/guide/usage/linter/generated-cli.md b/src/docs/guide/usage/linter/generated-cli.md index 8fd77594762..91fe73fe8d2 100644 --- a/src/docs/guide/usage/linter/generated-cli.md +++ b/src/docs/guide/usage/linter/generated-cli.md @@ -11,12 +11,12 @@ search: false - **`-c`**, **`--config`**=_`<./.oxlintrc.json>`_ — Oxlint configuration file -* `.json` config files are supported in all runtimes +* `.json` and `.jsonc` config files are supported in all runtimes * JavaScript/TypeScript config files are experimental and require running via Node.js * you can use comments in configuration files. * tries to be compatible with ESLint v8's format - If not provided, Oxlint will look for `.oxlintrc.json` in the current working directory. + If not provided, Oxlint will look for a `.oxlintrc.json`, `.oxlintrc.jsonc`, or `oxlint.config.ts` file in the current working directory. - **` --tsconfig`**=_`<./tsconfig.json>`_ — TypeScript `tsconfig.json` path for reading path alias and project references for import plugin. If not provided, will look for `tsconfig.json` in the current working directory. diff --git a/src/docs/guide/usage/linter/generated-config.md b/src/docs/guide/usage/linter/generated-config.md index a8adcdf14dd..5edb90fc1f4 100644 --- a/src/docs/guide/usage/linter/generated-config.md +++ b/src/docs/guide/usage/linter/generated-config.md @@ -6,13 +6,7 @@ search: false This configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`). -Usage: `oxlint -c oxlintrc.json --import-plugin` - -::: danger NOTE - -Only the `.json` format is supported. You can use comments in configuration files. - -::: +Usage: `oxlint -c oxlintrc.json` Example @@ -57,6 +51,42 @@ Example } ``` +`oxlint.config.ts` + +```ts +import { defineConfig } from "oxlint"; + +export default defineConfig({ +plugins: ["import", "typescript", "unicorn"], +env: { +"browser": true +}, +globals: { +"foo": "readonly" +}, +settings: { +react: { +version: "18.2.0" +}, +custom: { option: true } +}, +rules: { +"eqeqeq": "warn", +"import/no-cycle": "error", +"react/self-closing-comp": ["error", { "html": false }] +}, +overrides: [ +{ +files: ["*.test.ts", "*.spec.ts"], +rules: { +"@typescript-eslint/no-explicit-any": "off" +} +} +] +} +}); +``` + ## $schema type: `string` @@ -234,6 +264,30 @@ type: `object` Options for the linter. +### options.denyWarnings + +type: `boolean` + +Ensure warnings produce a non-zero exit code. + +Equivalent to passing `--deny-warnings` on the CLI. + +### options.maxWarnings + +type: `integer` + +Specify a warning threshold. Exits with an error status if warnings exceed this value. + +Equivalent to passing `--max-warnings` on the CLI. + +### options.reportUnusedDisableDirectives + +Report unused disable directives (e.g. `// oxlint-disable-line` or `// eslint-disable-line`). + +Equivalent to passing `--report-unused-disable-directives-severity` on the CLI. +CLI flags take precedence over this value when both are set. +Only supported in the root configuration file. + ### options.typeAware type: `boolean` @@ -242,6 +296,8 @@ Enable rules that require type information. Equivalent to passing `--type-aware` on the CLI. +Note that this requires the `oxlint-tsgolint` package to be installed. + ### options.typeCheck type: `boolean` @@ -250,6 +306,8 @@ Enable experimental type checking (includes TypeScript compiler diagnostics). Equivalent to passing `--type-check` on the CLI. +Note that this requires the `oxlint-tsgolint` package to be installed. + ## overrides type: `array` diff --git a/src/docs/guide/usage/linter/rules/eslint/no-useless-constructor.md b/src/docs/guide/usage/linter/rules/eslint/no-useless-constructor.md index 7ca90c3f083..d27a71ba447 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-useless-constructor.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-useless-constructor.md @@ -3,7 +3,7 @@ title: "eslint/no-useless-constructor" category: "Suspicious" default: false type_aware: false -fix: "fixable_fix" +fix: "fixable_suggestion" --- diff --git a/src/docs/guide/usage/linter/rules/import/extensions.md b/src/docs/guide/usage/linter/rules/import/extensions.md index a60b9f139a0..38492c77990 100644 --- a/src/docs/guide/usage/linter/rules/import/extensions.md +++ b/src/docs/guide/usage/linter/rules/import/extensions.md @@ -24,7 +24,16 @@ In order to provide a consistent use of file extensions across your code base, t ### Why is this bad? -ESM-based file resolve algorithms (e.g., the one that Vite provides) recommend specifying the file extension to improve performance. +ESM-based file resolve algorithms (e.g., the one that Vite provides) recommend +specifying the file extension to improve performance. Without extensions, the +bundler must check for various possible file extensions, which can slow down +the build process on large projects. In addition, common ESM environments +(such as browsers and Node.js) typically require fully specified relative imports, +which means extensionless imports are not supported there. + +For personal preference and compatibility reasons, the rule also allows configuration +to _disallow_ extensions in imports. This is generally not recommended, but it can be +done if preferred. ### Examples @@ -83,6 +92,21 @@ import foo from "./foo"; // ✓ OK - no extension import bar from "lodash/fp"; // ✓ OK - package import, ignored (ignorePackages sets this to true) ``` +### Differences compared to `eslint-plugin-import` + +If you see differences between this rule implementation and the original `eslint-plugin-import` +rule, please note that there are some intentional, inherent differences in the behavior of this +rule and the original. + +Oxlint understands and can resolve TypeScript paths out-of-the-box. If your ESLint +configuration did not include `eslint-import-resolver-typescript` or similar, then the original +rule will not have been able to resolve TypeScript paths correctly, and so the behavior +between ESLint and Oxlint may differ. Generally, this means that Oxlint will catch _more_ +valid violations than the original rule, though this depends on the specific configuration. + +Oxlint is also able to resolve multiple `tsconfig.json` files in a single repo, and so in a +monorepo setup will be more capable with regards to resolving file paths. + ## Configuration This rule accepts three types of configuration: diff --git a/src/docs/guide/usage/linter/rules/import/no-named-as-default.md b/src/docs/guide/usage/linter/rules/import/no-named-as-default.md index b7363b77fc9..bf8a588c28b 100644 --- a/src/docs/guide/usage/linter/rules/import/no-named-as-default.md +++ b/src/docs/guide/usage/linter/rules/import/no-named-as-default.md @@ -35,7 +35,7 @@ Given ```javascript // foo.js export default "foo"; -export const bar = "baz"; +export const bar = true; ``` Examples of **incorrect** code for this rule: @@ -52,6 +52,16 @@ Examples of **correct** code for this rule: import foo from "./foo.js"; ``` +### Differences compared to `eslint-plugin-import` + +If you see differences between this rule implementation and the original `eslint-plugin-import` +rule, please note that the behavior may differ in certain cases due to differences in how +module resolution is implemented and configured. + +For example, the original rule may require additional resolver configuration to handle certain +imports, especially when TypeScript paths are used or in monorepo setups with multiple +`tsconfig.json` files. + ## 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/react/forbid-dom-props.md b/src/docs/guide/usage/linter/rules/react/forbid-dom-props.md index 9cc23b2183f..6a33e7a10f2 100644 --- a/src/docs/guide/usage/linter/rules/react/forbid-dom-props.md +++ b/src/docs/guide/usage/linter/rules/react/forbid-dom-props.md @@ -69,10 +69,30 @@ Examples: #### forbid[n] -type: `string` +type: `object | string` A forbidden prop, either as a plain prop name string or with options. +##### forbid[n].disallowedFor + +type: `string[]` + +A list of DOM element names (e.g. `["div", "span"]`) on which this +prop is forbidden. If empty or omitted, the prop is forbidden on all +DOM elements. + +##### forbid[n].message + +type: `string` + +A custom message to display when this prop is used. + +##### forbid[n].propName + +type: `string` + +The name of the prop to forbid. + ## 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/typescript/no-deprecated.md b/src/docs/guide/usage/linter/rules/typescript/no-deprecated.md index 34ee7d6644c..9bd571ffd63 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-deprecated.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-deprecated.md @@ -74,7 +74,7 @@ Use this to allow specific deprecated APIs that you intentionally want to contin #### allow[n] -type: `string` +type: `object | string` Type or value specifier for matching specific declarations @@ -108,6 +108,27 @@ Supports four types of specifiers: { "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" } ``` +##### allow[n].from + +type: `"file"` + +##### allow[n].name + +type: `array | string` + +Name specifier that can be a single string or array of strings + +###### allow[n].name[n] + +type: `string` + +##### allow[n].path + +type: `string` + +Optional file path to specify where the types or values must be declared. +If omitted, all files will be matched. + ## 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/typescript/no-floating-promises.md b/src/docs/guide/usage/linter/rules/typescript/no-floating-promises.md index cb1b8ba862c..23045643482 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-floating-promises.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-floating-promises.md @@ -97,7 +97,7 @@ Allows specific calls to be ignored, specified as type or value specifiers. #### allowForKnownSafeCalls[n] -type: `string` +type: `object | string` Type or value specifier for matching specific declarations @@ -131,6 +131,27 @@ Supports four types of specifiers: { "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" } ``` +##### allowForKnownSafeCalls[n].from + +type: `"file"` + +##### allowForKnownSafeCalls[n].name + +type: `array | string` + +Name specifier that can be a single string or array of strings + +###### allowForKnownSafeCalls[n].name[n] + +type: `string` + +##### allowForKnownSafeCalls[n].path + +type: `string` + +Optional file path to specify where the types or values must be declared. +If omitted, all files will be matched. + ### allowForKnownSafePromises type: `array` @@ -141,7 +162,7 @@ Allows specific Promise types to be ignored, specified as type or value specifie #### allowForKnownSafePromises[n] -type: `string` +type: `object | string` Type or value specifier for matching specific declarations @@ -175,6 +196,27 @@ Supports four types of specifiers: { "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" } ``` +##### allowForKnownSafePromises[n].from + +type: `"file"` + +##### allowForKnownSafePromises[n].name + +type: `array | string` + +Name specifier that can be a single string or array of strings + +###### allowForKnownSafePromises[n].name[n] + +type: `string` + +##### allowForKnownSafePromises[n].path + +type: `string` + +Optional file path to specify where the types or values must be declared. +If omitted, all files will be matched. + ### checkThenables type: `boolean` diff --git a/src/docs/guide/usage/linter/rules/typescript/no-misused-spread.md b/src/docs/guide/usage/linter/rules/typescript/no-misused-spread.md index 2d8bba1bcdc..550f6c3722a 100644 --- a/src/docs/guide/usage/linter/rules/typescript/no-misused-spread.md +++ b/src/docs/guide/usage/linter/rules/typescript/no-misused-spread.md @@ -77,7 +77,7 @@ even if they would normally be flagged as misused. #### allow[n] -type: `string` +type: `object | string` Type or value specifier for matching specific declarations @@ -111,6 +111,27 @@ Supports four types of specifiers: { "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" } ``` +##### allow[n].from + +type: `"file"` + +##### allow[n].name + +type: `array | string` + +Name specifier that can be a single string or array of strings + +###### allow[n].name[n] + +type: `string` + +##### allow[n].path + +type: `string` + +Optional file path to specify where the types or values must be declared. +If omitted, all files will be matched. + ## 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/typescript/no-unnecessary-type-conversion.md b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-conversion.md new file mode 100644 index 00000000000..a681d42b68d --- /dev/null +++ b/src/docs/guide/usage/linter/rules/typescript/no-unnecessary-type-conversion.md @@ -0,0 +1,65 @@ +--- +title: "typescript/no-unnecessary-type-conversion" +category: "Nursery" +default: false +type_aware: true +fix: "none" +--- + + + + + + + +### What it does + +Disallow unnecessary type conversion expressions. + +### Why is this bad? + +Type conversions that do not change a value's type or runtime behavior +add noise and can obscure intent. + +### Examples + +Examples of **incorrect** code for this rule: + +```ts +const value = String("asdf"); +``` + +Examples of **correct** code for this rule: + +```ts +const value = "asdf"; +``` + +## 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-conversion": "error" + } +} +``` + +```bash [CLI] +oxlint --type-aware --deny typescript/no-unnecessary-type-conversion +``` + +::: + +## References + +- Rule Source +- Rule Source (tsgolint) diff --git a/src/docs/guide/usage/linter/rules/typescript/only-throw-error.md b/src/docs/guide/usage/linter/rules/typescript/only-throw-error.md index 16d7b21e79b..6b2b99cb0d2 100644 --- a/src/docs/guide/usage/linter/rules/typescript/only-throw-error.md +++ b/src/docs/guide/usage/linter/rules/typescript/only-throw-error.md @@ -83,7 +83,7 @@ Use this to allow throwing custom error types. #### allow[n] -type: `string` +type: `object | string` Type or value specifier for matching specific declarations @@ -117,6 +117,27 @@ Supports four types of specifiers: { "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" } ``` +##### allow[n].from + +type: `"file"` + +##### allow[n].name + +type: `array | string` + +Name specifier that can be a single string or array of strings + +###### allow[n].name[n] + +type: `string` + +##### allow[n].path + +type: `string` + +Optional file path to specify where the types or values must be declared. +If omitted, all files will be matched. + ### allowRethrowing type: `boolean` diff --git a/src/docs/guide/usage/linter/rules/typescript/prefer-nullish-coalescing.md b/src/docs/guide/usage/linter/rules/typescript/prefer-nullish-coalescing.md index fa37c48ee30..e7badec06fe 100644 --- a/src/docs/guide/usage/linter/rules/typescript/prefer-nullish-coalescing.md +++ b/src/docs/guide/usage/linter/rules/typescript/prefer-nullish-coalescing.md @@ -109,7 +109,7 @@ logical expression (with `&&`). ### ignorePrimitives -type: `boolean` +type: `object | boolean` Represents the different ways `ignorePrimitives` can be specified in JSON. Can be: @@ -117,6 +117,38 @@ Can be: - `true` - ignore all primitive types - An object specifying which primitives to ignore +#### ignorePrimitives.bigint + +type: `boolean` + +default: `false` + +Ignore bigint primitive types. + +#### ignorePrimitives.boolean + +type: `boolean` + +default: `false` + +Ignore boolean primitive types. + +#### ignorePrimitives.number + +type: `boolean` + +default: `false` + +Ignore number primitive types. + +#### ignorePrimitives.string + +type: `boolean` + +default: `false` + +Ignore string primitive types. + ### ignoreTernaryTests type: `boolean` 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 index 940b98b2ad9..e5114facd4b 100644 --- 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 @@ -65,7 +65,7 @@ Type/value specifiers that should be exempt from this rule. #### allow[n] -type: `string` +type: `object | string` Type or value specifier for matching specific declarations @@ -99,6 +99,27 @@ Supports four types of specifiers: { "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" } ``` +##### allow[n].from + +type: `"file"` + +##### allow[n].name + +type: `array | string` + +Name specifier that can be a single string or array of strings + +###### allow[n].name[n] + +type: `string` + +##### allow[n].path + +type: `string` + +Optional file path to specify where the types or values must be declared. +If omitted, all files will be matched. + ### checkParameterProperties type: `boolean` diff --git a/src/docs/guide/usage/linter/rules/typescript/restrict-template-expressions.md b/src/docs/guide/usage/linter/rules/typescript/restrict-template-expressions.md index 56374503c38..a6da37e57fc 100644 --- a/src/docs/guide/usage/linter/rules/typescript/restrict-template-expressions.md +++ b/src/docs/guide/usage/linter/rules/typescript/restrict-template-expressions.md @@ -93,7 +93,7 @@ Defaults include Error, URL, and URLSearchParams from lib. #### allow[n] -type: `string` +type: `object | string` Type or value specifier for matching specific declarations @@ -127,6 +127,27 @@ Supports four types of specifiers: { "from": "package", "name": ["Observable", "Subject"], "package": "rxjs" } ``` +##### allow[n].from + +type: `"file"` + +##### allow[n].name + +type: `array | string` + +Name specifier that can be a single string or array of strings + +###### allow[n].name[n] + +type: `string` + +##### allow[n].path + +type: `string` + +Optional file path to specify where the types or values must be declared. +If omitted, all files will be matched. + ### allowAny type: `boolean` diff --git a/src/docs/guide/usage/linter/rules/unicorn/consistent-assert.md b/src/docs/guide/usage/linter/rules/unicorn/consistent-assert.md index 3eae9ba5d3a..7a78a666ac9 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/consistent-assert.md +++ b/src/docs/guide/usage/linter/rules/unicorn/consistent-assert.md @@ -21,7 +21,11 @@ Enforces consistent usage of the `assert` module. ### Why is this bad? -Inconsistent usage of the `assert` module can lead to confusion and errors. +Inconsistent usage of the `assert` module can make code +harder to follow and understand. + +`assert.ok(...)` is preferred as it makes the intent of +the assertion clearer. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/explicit-length-check.md b/src/docs/guide/usage/linter/rules/unicorn/explicit-length-check.md index e5d9167ad0d..390df20bbd8 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/explicit-length-check.md +++ b/src/docs/guide/usage/linter/rules/unicorn/explicit-length-check.md @@ -17,10 +17,14 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Enforce explicitly comparing the length or size property of a value. +Enforce explicitly comparing the `length` or `size` property of a value. ### Why is this bad? +Using the explicit `length` or `size` properties can help make code clearer +and easier to understand, as it avoids relying on implicit truthy/falsy +evaluations. + ### Examples Examples of **incorrect** code for this rule: @@ -41,6 +45,11 @@ Examples of **correct** code for this rule: ```javascript const isEmpty = foo.length === 0; + +if (foo.length > 0 || bar.length > 0) { +} + +const unicorn = foo.length > 0 ? 1 : 2; ``` ## Configuration diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-accessor-recursion.md b/src/docs/guide/usage/linter/rules/unicorn/no-accessor-recursion.md index 535f52c4094..29227dc9d80 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-accessor-recursion.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-accessor-recursion.md @@ -17,12 +17,13 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallow recursive access to this within getters and setters +Disallow recursive access to `this` within getters and setters. ### Why is this bad? -This rule prevents recursive access to this within getter and setter methods in objects and classes, -avoiding infinite recursion and stack overflow errors. +This rule prevents recursive access to `this` within getter and +setter methods in objects and classes, avoiding infinite recursion +and stack overflow errors. ### Examples @@ -34,6 +35,12 @@ const foo = { return this.bar; }, }; + +const baz = { + set bar(value) { + this.bar = value; + }, +}; ``` Examples of **correct** code for this rule: @@ -41,7 +48,13 @@ Examples of **correct** code for this rule: ```js const foo = { get bar() { - return this.baz; + return this.qux; + }, +}; + +const baz = { + set bar(value) { + this._bar = value; }, }; ``` diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-console-spaces.md b/src/docs/guide/usage/linter/rules/unicorn/no-console-spaces.md index 26ca1abba47..5d083e7a4d5 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-console-spaces.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-console-spaces.md @@ -21,7 +21,9 @@ Disallows leading/trailing space inside `console.log()` and similar methods. ### Why is this bad? -The `console.log()` method and similar methods join the parameters with a space so adding a leading/trailing space to a parameter, results in two spaces being added. +The `console.log()` method and similar methods join the parameters +with a space so adding a leading/trailing space to a parameter, +results in two spaces being added. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-document-cookie.md b/src/docs/guide/usage/linter/rules/unicorn/no-document-cookie.md index 9de67631e89..ad86b1a9a63 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-document-cookie.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-document-cookie.md @@ -17,7 +17,7 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallow direct use of +Disallows direct use of [`document.cookie`](https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie). ### Why is this bad? @@ -27,7 +27,7 @@ It's not recommended to use directly as it's easy to get the string wrong. Instead, you should use the [Cookie Store API](https://developer.mozilla.org/en-US/docs/Web/API/Cookie_Store_API) -or a [cookie library](https://www.npmjs.com/search?q=cookie). +or a [cookie library](https://npmx.dev/search?q=cookie). ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-hex-escape.md b/src/docs/guide/usage/linter/rules/unicorn/no-hex-escape.md index 930a06b442c..3448d6cbd10 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-hex-escape.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-hex-escape.md @@ -17,10 +17,15 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Enforces a convention of using [Unicode escapes](https://mathiasbynens.be/notes/javascript-escapes#unicode) instead of [hexadecimal escapes](https://mathiasbynens.be/notes/javascript-escapes#hexadecimal) for consistency and clarity. +Enforces a convention of using [Unicode escapes](https://mathiasbynens.be/notes/javascript-escapes#unicode) +instead of [hexadecimal escapes](https://mathiasbynens.be/notes/javascript-escapes#hexadecimal) for +consistency and clarity. ### Why is this bad? +Using hexadecimal escapes can be less readable and harder to understand +when compared to Unicode escapes. + ### Examples Examples of **incorrect** code for this rule: diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-instanceof-array.md b/src/docs/guide/usage/linter/rules/unicorn/no-instanceof-array.md index 1cc5c4aa26e..b20e4a8b8bf 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-instanceof-array.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-instanceof-array.md @@ -21,7 +21,8 @@ Require `Array.isArray()` instead of `instanceof Array`. ### Why is this bad? -The instanceof Array check doesn't work across realms/contexts, for example, frames/windows in browsers or the vm module in Node.js. +The `instanceof Array` check doesn't work across realms/contexts. +For example, frames/windows in browsers or the `vm` module in Node.js. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-magic-array-flat-depth.md b/src/docs/guide/usage/linter/rules/unicorn/no-magic-array-flat-depth.md index bd5eb946717..8fcfc4d783d 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-magic-array-flat-depth.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-magic-array-flat-depth.md @@ -17,11 +17,15 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallow magic numbers for `Array.prototype.flat` depth. +Disallow magic numbers for [`Array.prototype.flat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) +depth. ### Why is this bad? -Magic numbers are hard to understand and maintain. When calling `Array.prototype.flat`, it is usually called with `1` or infinity. If you are using a different number, it is better to add a comment explaining the depth. +Magic numbers are hard to understand and maintain. +When calling `Array.prototype.flat`, it is usually called with +`1` or `Infinity`. If you are using a different number, it is +better to add a comment explaining the reason for the depth provided. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-process-exit.md b/src/docs/guide/usage/linter/rules/unicorn/no-process-exit.md index 76da8b33c8e..32532d302ed 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-process-exit.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-process-exit.md @@ -17,29 +17,36 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallow `process.exit()`. +Disallow all usage of `process.exit()`. ### Why is this bad? -Only use `process.exit()` in CLI apps. Throw an error instead. +`process.exit()` should generally only be used in command-line utilities. In all other +types of applications, the code should throw an error instead. ### Examples Examples of **incorrect** code for this rule: ```javascript -if (problem) process.exit(1); +if (problem) { + process.exit(1); +} ``` Examples of **correct** code for this rule: ```javascript -if (problem) throw new Error("message"); +if (problem) { + throw new Error("message"); +} ``` ``` #!/usr/bin/env node -if (problem) process.exit(1); +if (problem) { + process.exit(1); +} ``` ## How to use diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-single-promise-in-promise-methods.md b/src/docs/guide/usage/linter/rules/unicorn/no-single-promise-in-promise-methods.md index 191f424e62b..e9a0d80febf 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-single-promise-in-promise-methods.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-single-promise-in-promise-methods.md @@ -17,7 +17,7 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallow passing single-element arrays to Promise methods +Disallow passing single-element arrays to `Promise` methods. ### Why is this bad? diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-static-only-class.md b/src/docs/guide/usage/linter/rules/unicorn/no-static-only-class.md index 2ac04aa58f3..98bd4d617a7 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-static-only-class.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-static-only-class.md @@ -17,11 +17,11 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallow classes that only have static members. +Disallow `class` declarations that exclusively contain `static` members. ### Why is this bad? -A class with only static members could just be an object instead. +A `class` with only `static` members should just be defined as an object instead. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-thenable.md b/src/docs/guide/usage/linter/rules/unicorn/no-thenable.md index 94ce66d075a..f2bfb31c07b 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-thenable.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-thenable.md @@ -17,12 +17,12 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallow `then` property +Disallow defining a `then` property. ### Why is this bad? If an object is defined as "thenable", once it's accidentally -used in an await expression, it may cause problems: +used in an `await` expression, it may cause problems. ### Examples @@ -37,7 +37,7 @@ async function example() { const { unicorn } = await foo; - console.log("after"); //<- This will never execute + console.log("after"); // <- This will never execute } ``` diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-unnecessary-slice-end.md b/src/docs/guide/usage/linter/rules/unicorn/no-unnecessary-slice-end.md index ad152a91d71..7d042426657 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-unnecessary-slice-end.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-unnecessary-slice-end.md @@ -17,13 +17,15 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Omitting the end argument defaults it to the object's .length. -Passing it explicitly or using Infinity is unnecessary +Disallows unnecessarily passing a second argument to `slice(...)`, for +cases where it would not change the result. ### Why is this bad? -In JavaScript, omitting the end index already causes .slice() to run to the end of the target, -so explicitly passing its length or Infinity is redundant. +When using `.slice(...)` without a second argument, the second argument +defaults to the object's length. As such, passing the length explicitly + +- or using `Infinity` - is unnecessary. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-unreadable-array-destructuring.md b/src/docs/guide/usage/linter/rules/unicorn/no-unreadable-array-destructuring.md index ccbb322925b..e9156db4539 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-unreadable-array-destructuring.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-unreadable-array-destructuring.md @@ -17,12 +17,13 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallow unreadable array destructuring +Disallows destructuring values from an array in ways that are difficult to read. ### Why is this bad? -Destructuring is very useful, but it can also make some code harder to read. -This rule prevents ignoring consecutive values when destructuring from an array. +Destructuring can be very useful, but it can also make some code harder to read. +This rule prevents ignoring consecutive values (e.g. `let [,,foo] = array`) +when destructuring from an array. ### Examples @@ -30,12 +31,18 @@ Examples of **incorrect** code for this rule: ```javascript const [, , foo] = parts; +const [, , ...rest] = parts; ``` Examples of **correct** code for this rule: ```javascript const [foo] = parts; +const foo = parts[3]; +const rest = parts.slice(2); + +// One is fine +const [, foo] = parts; ``` ## How to use diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-useless-collection-argument.md b/src/docs/guide/usage/linter/rules/unicorn/no-useless-collection-argument.md index b8b0e9e5a34..a0446c549b5 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-useless-collection-argument.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-useless-collection-argument.md @@ -17,12 +17,15 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallow useless values or fallbacks in Set, Map, WeakSet, or WeakMap +Disallow useless values or fallbacks in `Set`, `Map`, `WeakSet`, or `WeakMap`. ### Why is this bad? -It's unnecessary to pass an empty array or string when constructing a Set, Map, WeakSet, or WeakMap, since they accept nullish values. -It's also unnecessary to provide a fallback for possible nullish values. +It is unnecessary to pass an empty array or empty string when +constructing a `Set`, `Map`, `WeakSet`, or `WeakMap`, since +they accept nullish values. + +It is also unnecessary to provide a fallback for possible nullish values. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-useless-promise-resolve-reject.md b/src/docs/guide/usage/linter/rules/unicorn/no-useless-promise-resolve-reject.md index 1b1519cfc7d..0a99efac205 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-useless-promise-resolve-reject.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-useless-promise-resolve-reject.md @@ -17,11 +17,19 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallows returning values wrapped in `Promise.resolve` or `Promise.reject` in an async function or a `Promise#then`/`catch`/`finally` callback. +Disallows returning values wrapped in `Promise.resolve` or `Promise.reject` +in an async function or a `Promise#then`/`catch`/`finally` callback. ### Why is this bad? -Wrapping a return value in `Promise.resolve` in an async function or a `Promise#then`/`catch`/`finally` callback is unnecessary as all return values in async functions and promise callback functions are already wrapped in a `Promise`. Similarly, returning an error wrapped in `Promise.reject` is equivalent to simply `throw`ing the error. This is the same for `yield`ing in async generators as well. +Wrapping a return value in `Promise.resolve` in an async function +or a `Promise#then`/`catch`/`finally` callback is unnecessary as all +return values in async functions and promise callback functions are +already wrapped in a `Promise`. + +Similarly, returning an error wrapped in `Promise.reject` is equivalent +to simply `throw`ing the error. This is the same for `yield`ing in +async generators as well. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-useless-switch-case.md b/src/docs/guide/usage/linter/rules/unicorn/no-useless-switch-case.md index 2a66e5a31e4..d3a3c92d7fe 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-useless-switch-case.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-useless-switch-case.md @@ -17,11 +17,12 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Disallows useless default cases in switch statements. +Disallows useless `default` cases in `switch` statements. ### Why is this bad? -An empty case before the last default case is useless. +An empty case before the last `default` case is useless, as the +`default` case will catch it regardless. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/no-useless-undefined.md b/src/docs/guide/usage/linter/rules/unicorn/no-useless-undefined.md index 94781053cf8..10f48d14c89 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/no-useless-undefined.md +++ b/src/docs/guide/usage/linter/rules/unicorn/no-useless-undefined.md @@ -17,11 +17,19 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Do not use useless `undefined`. +Prevents usage of `undefined` in cases where it would be useless. + +::: warning +This rule can conflict with the default behaviors of the `eslint/array-callback-return` +and `eslint/getter-return` rules. For both rules, you can set +the `allowImplicit` option to avoid conflicts. +::: ### Why is this bad? -`undefined` is the default value for new variables, parameters, return statements, etc… so specifying it doesn't make any difference. +`undefined` is the default value for new variables, parameters, +return statements, etc, so specifying `undefined` in these cases +is pointless. ### Examples @@ -29,12 +37,14 @@ Examples of **incorrect** code for this rule: ```javascript let foo = undefined; +const noop = () => undefined; ``` Examples of **correct** code for this rule: ```javascript let foo; +const noop = () => {}; ``` ## Configuration diff --git a/src/docs/guide/usage/linter/rules/unicorn/numeric-separators-style.md b/src/docs/guide/usage/linter/rules/unicorn/numeric-separators-style.md index 9efdfc9a7b6..bf78b2e1aac 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/numeric-separators-style.md +++ b/src/docs/guide/usage/linter/rules/unicorn/numeric-separators-style.md @@ -21,10 +21,20 @@ Enforces a convention of grouping digits using numeric separators. ### Why is this bad? -Long numbers can become really hard to read, so cutting it into groups of digits, -separated with a \_, is important to keep your code clear. This rule also enforces -a proper usage of the numeric separator, by checking if the groups of digits are -of the correct size. +A long series of digits can be difficult to read, and +it can be difficult to determine the value of the number at a glance. +Breaking up the digits with numeric separators (`_`) can greatly +improve readability. + +Compare the following two numbers and how easy it is to understand their magnitude: + +```js +1000000000; +1_000_000_000; +``` + +This rule also enforces proper group size, for example +enforcing that the `_` separator is used every 3 digits. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-at.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-at.md index c5685560c71..0389c69769e 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-at.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-at.md @@ -17,12 +17,16 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Prefer `.at()` method for index access and `String#charAt()`. +Prefer the [`Array#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at) and +[`String#at()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at) +methods for index access. + +This rule also discourages using [`String#charAt()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt). ### Why is this bad? The `.at()` method is more readable and consistent for accessing elements by index, -especially for negative indices which access elements from the end. +especially for negative indices which access elements from the end of the array or string. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-class-fields.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-class-fields.md index 8984ea1eca1..186e2bef034 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-class-fields.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-class-fields.md @@ -29,12 +29,26 @@ and makes the intent clearer. Examples of **incorrect** code for this rule: -```js +```ts class Foo { constructor() { this.bar = 1; } } + +class MyError extends Error { + constructor(message: string) { + super(message); + this.name = "MyError"; + } +} + +class Foo { + foo = "foo"; + constructor() { + this.foo = "bar"; + } +} ``` Examples of **correct** code for this rule: @@ -43,6 +57,14 @@ Examples of **correct** code for this rule: class Foo { bar = 1; } + +class MyError extends Error { + name = "MyError"; +} + +class Foo { + foo = "bar"; +} ``` ## How to use diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-dom-node-remove.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-dom-node-remove.md index a63b57e40f4..45ac2d8e1c7 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-dom-node-remove.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-dom-node-remove.md @@ -21,7 +21,8 @@ Prefers the use of `child.remove()` over `parentNode.removeChild(child)`. ### Why is this bad? -The DOM function [`Node#remove()`](https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove) is preferred over the indirect removal of an object with [`Node#removeChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild). +The DOM function [`Node#remove()`](https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove) is preferred +over the indirect removal of an object with [`Node#removeChild()`](https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild). ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-global-this.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-global-this.md index 92741da3bd4..ec0bbcde1c0 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-global-this.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-global-this.md @@ -19,15 +19,17 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin Enforces the use of [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) instead of environment‑specific global object aliases (`window`, `self`, or `global`). + Using the standard `globalThis` makes your code portable across browsers, Web Workers, Node.js, and future JavaScript runtimes. ### Why is this bad? -• **Portability** – `window` is only defined in browser main threads, `self` is used in Web Workers, +**Portability** – `window` is only defined in browser main threads, `self` is used in Web Workers, and `global` is Node‑specific. Choosing the wrong alias causes runtime crashes when the code is executed outside of its original environment. -• **Clarity** – `globalThis` clearly communicates that you are referring to the global object itself + +**Clarity** – `globalThis` clearly communicates that you are referring to the global object itself rather than a particular platform. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-keyboard-event-key.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-keyboard-event-key.md index bd5ee269602..4f7586750b5 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-keyboard-event-key.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-keyboard-event-key.md @@ -17,12 +17,16 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Enforces the use of [`KeyboardEvent#key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) over [`KeyboardEvent#keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode) which is deprecated. +Enforces the use of [`KeyboardEvent#key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) +over [`KeyboardEvent#keyCode`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode), +which is deprecated. + The `.key` property is also more semantic and readable. ### Why is this bad? -The `keyCode`, `which`, and `charCode` properties are deprecated and should be avoided in favor of the `key` property. +The `keyCode`, `which`, and `charCode` properties are deprecated +and should be avoided in favor of the `key` property. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-negative-index.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-negative-index.md index b8f6c06c4ff..ec94bcbdcb8 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-negative-index.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-negative-index.md @@ -17,11 +17,12 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Prefer negative index over `.length` - index when possible +Prefer using a negative index over `.length - index` when possible. ### Why is this bad? -Conciseness and readability +Using a negative index with `at` or `slice` is generally more readable +and concise than using `.length - index`. ### Examples diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-query-selector.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-query-selector.md index 47e74053933..b03136a9af8 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-query-selector.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-query-selector.md @@ -17,7 +17,8 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Prefer `.querySelector()` over `.getElementById()`, `.querySelectorAll()` over `.getElementsByClassName()` and `.getElementsByTagName()`. +Prefer `.querySelector()` over `.getElementById()`. And prefer `.querySelectorAll()` +over `.getElementsByClassName()`, `.getElementsByTagName()`, and `.getElementsByName()`. ### Why is this bad? @@ -33,6 +34,7 @@ document.getElementById("foo"); document.getElementsByClassName("foo bar"); document.getElementsByTagName("main"); document.getElementsByClassName(fn()); +document.getElementsByName("foo"); ``` Examples of **correct** code for this rule: diff --git a/src/docs/guide/usage/linter/rules/unicorn/prefer-string-slice.md b/src/docs/guide/usage/linter/rules/unicorn/prefer-string-slice.md index 702d4a72a6e..8902a7d2094 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/prefer-string-slice.md +++ b/src/docs/guide/usage/linter/rules/unicorn/prefer-string-slice.md @@ -3,7 +3,7 @@ title: "unicorn/prefer-string-slice" category: "Pedantic" default: false type_aware: false -fix: "fixable_fix" +fix: "conditional_fix" --- diff --git a/src/docs/guide/usage/linter/rules/unicorn/require-post-message-target-origin.md b/src/docs/guide/usage/linter/rules/unicorn/require-post-message-target-origin.md index 80c08991644..3c1bbcccd63 100644 --- a/src/docs/guide/usage/linter/rules/unicorn/require-post-message-target-origin.md +++ b/src/docs/guide/usage/linter/rules/unicorn/require-post-message-target-origin.md @@ -17,11 +17,18 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Enforce using the targetOrigin argument with window.postMessage() +Enforce using the `targetOrigin` argument with `window.postMessage()`. + +Note that this rule may have false positives, as it is not capable of +detecting all cases correctly without type information. As such, it +may not be a good idea to enable in cases where `postMessage()` may +be used with `BroadcastChannel` or worker/service worker contexts +(for example, `WorkerGlobalScope#postMessage`, where the second argument +is a transfer list or options object, not `targetOrigin`). ### Why is this bad? -When calling window.postMessage() without the targetOrigin argument, +When calling `window.postMessage()` without the `targetOrigin` argument, the message cannot be received by any window. ### Examples diff --git a/src/docs/guide/usage/linter/rules/version.data.js b/src/docs/guide/usage/linter/rules/version.data.js index 676406b5279..5f0b0c2b709 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 "8ec232e98d935a6980d8523aafa9c30b7e9e7b93"; + return "0b67b8a6fca0ccc25455f6c30ddfc17db769e141"; }, }; diff --git a/src/docs/guide/usage/linter/rules/vue/max-props.md b/src/docs/guide/usage/linter/rules/vue/max-props.md index 177f28e9a19..608544a053e 100644 --- a/src/docs/guide/usage/linter/rules/vue/max-props.md +++ b/src/docs/guide/usage/linter/rules/vue/max-props.md @@ -17,12 +17,16 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Enforce maximum number of props in Vue component. +Enforce a maximum number of props defined for a given Vue component. ### Why is this bad? -This rule enforces a maximum number of props in a Vue SFC, -in order to aid in maintainability and reduce complexity. +A large number of props on a component can indicate that it is trying +to do too much and may be difficult to maintain or understand. + +By limiting the number of props, developers are encouraged to avoid +overly complex components and instead create smaller, more focused +components that are easier to reason about. ### Examples @@ -57,7 +61,7 @@ type: `integer` default: `1` -The maximum number of props allowed in a Vue Single File Component (SFC). +The maximum number of props allowed in a Vue SFC. ## How to use diff --git a/src/docs/guide/usage/rule-count.data.js b/src/docs/guide/usage/rule-count.data.js index 1077bf51a4e..60bc6cec1a1 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 695; + return 696; }, };