Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/docs/guide/usage/linter/generated-cli.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
## Usage

**`oxlint`** \[**`-c`**=_`<./oxlintrc.json>`_\] \[_`PATH`_\]...
**`oxlint`** \[**`-c`**=_`<./.oxlintrc.json>`_\] \[_`PATH`_\]...

## Basic Configuration

- **`-c`**, **`--config`**=_`<./oxlintrc.json>`_ &mdash;
- **`-c`**, **`--config`**=_`<./.oxlintrc.json>`_ &mdash;
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.
Expand Down
5 changes: 3 additions & 2 deletions src/docs/guide/usage/linter/generated-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand All @@ -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.

Expand Down Expand Up @@ -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):

Expand Down
126 changes: 87 additions & 39 deletions src/docs/guide/usage/linter/rules/eslint/arrow-body-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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:
Expand Down
47 changes: 47 additions & 0 deletions src/docs/guide/usage/linter/rules/eslint/grouped-accessor-pairs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/version.data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default {
load() {
return "6efb63a67ede0145468c83ff17217547d2e00ef8";
return "7fc4aef229419ae73e4feae806eb73b7fed3b983";
},
};
Loading