From 6ef24ef828332e80189a489ba50dc44f808c178f Mon Sep 17 00:00:00 2001 From: oxc-bot <176400334+oxc-bot@users.noreply.github.com> Date: Sat, 30 Aug 2025 08:42:23 +0000 Subject: [PATCH] Release 1.14.0 --- src/docs/guide/usage/linter/generated-cli.md | 5 +- .../guide/usage/linter/generated-rules.md | 5 +- .../linter/rules/eslint/arrow-body-style.md | 126 ++++++++++++------ .../rules/eslint/grouped-accessor-pairs.md | 47 +++++++ .../guide/usage/linter/rules/version.data.js | 2 +- .../linter/rules/vue/valid-define-emits.md | 122 +++++++++++++++++ 6 files changed, 263 insertions(+), 44 deletions(-) create mode 100644 src/docs/guide/usage/linter/rules/vue/valid-define-emits.md diff --git a/src/docs/guide/usage/linter/generated-cli.md b/src/docs/guide/usage/linter/generated-cli.md index b99cd4e131..dddefb237e 100644 --- a/src/docs/guide/usage/linter/generated-cli.md +++ b/src/docs/guide/usage/linter/generated-cli.md @@ -1,13 +1,14 @@ ## Usage -**`oxlint`** \[**`-c`**=_`<./oxlintrc.json>`_\] \[_`PATH`_\]... +**`oxlint`** \[**`-c`**=_`<./.oxlintrc.json>`_\] \[_`PATH`_\]... ## Basic Configuration -- **`-c`**, **`--config`**=_`<./oxlintrc.json>`_ — +- **`-c`**, **`--config`**=_`<./.oxlintrc.json>`_ — Oxlint configuration file (experimental) * only `.json` extension is supported +* you can use comments in configuration files. * tries to be compatible with the ESLint v8's format If not provided, Oxlint will look for `.oxlintrc.json` in the current working directory. diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index bf165af6a6..3c9a87f69c 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: 573 +- Total number of rules: 574 - Rules turned on by default: 103 **Legend for 'Fixable?' column:** @@ -13,7 +13,7 @@ The progress of all rule implementations is tracked [here](https://github.com/ox - βš οΈπŸ’‘: a dangerous suggestion is available for this rule - 🚧: an auto-fix or suggestion is possible, but currently not implemented -## Correctness (193): +## Correctness (194): Code that is outright wrong or useless. @@ -212,6 +212,7 @@ Code that is outright wrong or useless. | [prefer-string-starts-ends-with](/docs/guide/usage/linter/rules/unicorn/prefer-string-starts-ends-with.html) | unicorn | βœ… | πŸ› οΈ | | [no-conditional-tests](/docs/guide/usage/linter/rules/vitest/no-conditional-tests.html) | vitest | | | | [require-local-test-context-for-concurrent-snapshots](/docs/guide/usage/linter/rules/vitest/require-local-test-context-for-concurrent-snapshots.html) | vitest | | 🚧 | +| [valid-define-emits](/docs/guide/usage/linter/rules/vue/valid-define-emits.html) | vue | | 🚧 | ## Perf (11): 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 index f5c6c7e8b6..5a0ea1a42e 100644 --- a/src/docs/guide/usage/linter/rules/eslint/arrow-body-style.md +++ b/src/docs/guide/usage/linter/rules/eslint/arrow-body-style.md @@ -16,32 +16,101 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does This rule can enforce or disallow the use of braces around arrow function body. +Arrow functions can use either: + +- a block body `() => { ... }` +- or a concise body `() => expression` with an implicit return. ### 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. +Inconsistent use of block vs. concise bodies makes code harder to read. +Concise bodies are limited to a single expression, whose value is implicitly returned. + +### Options + +First option: + +- Type: `string` +- Enum: `"always"`, `"as-needed"`, `"never"` +- Default: `"never"` + +Possible values: + +- `never` enforces no braces where they can be omitted (default) +- `always` enforces braces around the function body +- `as-needed` enforces no braces around the function body (constrains arrow functions to the role of returning an expression) + +Second option: + +- Type: `object` +- Properties: + - `requireReturnForObjectLiteral`: `boolean` (default: `false`) - requires braces and an explicit return for object literals. + +Note: This option only applies when the first option is `"as-needed"`. + +Example configuration: + +```json +{ + "arrow-body-style": ["error", "as-needed", { "requireReturnForObjectLiteral": true }] +} +``` ### Examples +#### `"never"` (default) + +Examples of **incorrect** code for this rule with the `never` option: + +```js +/* arrow-body-style: ["error", "never"] */ + +/* ✘ Bad: */ +const foo = () => { + return 0; +}; +``` + +Examples of **correct** code for this rule with the `never` option: + +```js +/* arrow-body-style: ["error", "never"] */ + +/* βœ” Good: */ +const foo = () => 0; +const bar = () => ({ foo: 0 }); +``` + +#### `"always"` + Examples of **incorrect** code for this rule with the `always` option: ```js +/* arrow-body-style: ["error", "always"] */ + +/* ✘ Bad: */ const foo = () => 0; ``` Examples of **correct** code for this rule with the `always` option: ```js +/* arrow-body-style: ["error", "always"] */ + +/* βœ” Good: */ const foo = () => { return 0; }; ``` +#### `"as-needed"` + Examples of **incorrect** code for this rule with the `as-needed` option: ```js +/* arrow-body-style: ["error", "as-needed"] */ + +/* ✘ Bad: */ const foo = () => { return 0; }; @@ -50,66 +119,45 @@ const foo = () => { Examples of **correct** code for this rule with the `as-needed` option: ```js +/* arrow-body-style: ["error", "as-needed"] */ + +/* βœ” Good: */ const foo1 = () => 0; const foo2 = (retv, name) => { retv[name] = true; return retv; }; + +const foo3 = () => { + bar(); +}; ``` -Examples of **incorrect** code for this rule with the { "requireReturnForObjectLiteral": true } option: +#### `"as-needed"` with `requireReturnForObjectLiteral` + +Examples of **incorrect** code for this rule with the `{ "requireReturnForObjectLiteral": true }` option: ```js /* arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/ + +/* ✘ Bad: */ const foo = () => ({}); const bar = () => ({ bar: 0 }); ``` -Examples of **correct** code for this rule with the { "requireReturnForObjectLiteral": true } option: +Examples of **correct** code for this rule with the `{ "requireReturnForObjectLiteral": true }` option: ```js /* arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/ + +/* βœ” Good: */ 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: diff --git a/src/docs/guide/usage/linter/rules/eslint/grouped-accessor-pairs.md b/src/docs/guide/usage/linter/rules/eslint/grouped-accessor-pairs.md index 099963f087..dc5bf73dc2 100644 --- a/src/docs/guide/usage/linter/rules/eslint/grouped-accessor-pairs.md +++ b/src/docs/guide/usage/linter/rules/eslint/grouped-accessor-pairs.md @@ -104,6 +104,53 @@ const foo = { }; ``` +### Options + +This rule accepts two arguments: + +1. A string value to control the order of the getter/setter pairs: + - `"anyOrder"` (default): Accessors can be in any order + - `"getBeforeSet"`: Getters must come before setters + - `"setBeforeGet"`: Setters must come before getters +2. An object with the following option: + - `enforceForTSTypes` (boolean, default: false): When enabled, also checks TypeScript interfaces and type aliases for grouped accessor pairs + +### TypeScript + +When `enforceForTSTypes` is enabled, this rule also applies to TypeScript interfaces and type aliases: + +Examples of **incorrect** TypeScript code: + +```ts +interface Foo { + get a(): string; + someProperty: string; + set a(value: string); +} + +type Bar = { + get b(): string; + someProperty: string; + set b(value: string); +}; +``` + +Examples of **correct** TypeScript code: + +```ts +interface Foo { + get a(): string; + set a(value: string); + someProperty: string; +} + +type Bar = { + get b(): string; + set b(value: string); + someProperty: string; +}; +``` + ## 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 8ad78bf3fd..03bcb9bdbf 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 "6efb63a67ede0145468c83ff17217547d2e00ef8"; + return "7fc4aef229419ae73e4feae806eb73b7fed3b983"; }, }; diff --git a/src/docs/guide/usage/linter/rules/vue/valid-define-emits.md b/src/docs/guide/usage/linter/rules/vue/valid-define-emits.md new file mode 100644 index 0000000000..a760110519 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/vue/valid-define-emits.md @@ -0,0 +1,122 @@ + + + + +# vue/valid-define-emits + +
+ +🚧 An auto-fix is still under development. + +
+ +### What it does + +This rule checks whether defineEmits compiler macro is valid. + +This rule reports defineEmits compiler macros in the following cases: + +- `defineEmits` is referencing locally declared variables. +- `defineEmits` has both a literal type and an argument. e.g. `defineEmits<(e: 'foo')=>void>(['bar'])` +- `defineEmits` has been called multiple times. +- Custom events are defined in both `defineEmits` and `export default {}`. +- Custom events are not defined in either `defineEmits` or `export default {}`. + +### Why is this bad? + +Misusing `defineEmits` can lead to runtime errors, unclear component contracts, and lost type safety. +Vue may still compile the code, but emitted events may break silently or be typed incorrectly. + +### Examples + +Examples of **incorrect** code for this rule: + +```vue + +``` + +```vue + +``` + +```vue + +``` + +```vue + + +``` + +Examples of **correct** code for this rule: + +```vue + +``` + +```vue + +``` + +```vue + +``` + +```vue + + +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny vue/valid-define-emits --vue-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["vue"], + "rules": { + "vue/valid-define-emits": "error" + } +} +``` + +::: + +## References + +- Rule Source