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
9 changes: 6 additions & 3 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: 570
- Total number of rules: 573
- Rules turned on by default: 103

**Legend for 'Fixable?' column:**
Expand Down Expand Up @@ -308,7 +308,7 @@ Lints which prevent the use of language and library features. Must not be enable
| [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 (39):
## Suspicious (40):

code that is most likely wrong or useless.

Expand All @@ -332,6 +332,7 @@ code that is most likely wrong or useless.
| [approx-constant](/docs/guide/usage/linter/rules/oxc/approx-constant.html) | oxc | | |
| [misrefactored-assign-op](/docs/guide/usage/linter/rules/oxc/misrefactored-assign-op.html) | oxc | | 🚧 |
| [no-async-endpoint-handlers](/docs/guide/usage/linter/rules/oxc/no-async-endpoint-handlers.html) | oxc | | |
| [always-return](/docs/guide/usage/linter/rules/promise/always-return.html) | promise | | |
| [no-promise-in-callback](/docs/guide/usage/linter/rules/promise/no-promise-in-callback.html) | promise | | |
| [iframe-missing-sandbox](/docs/guide/usage/linter/rules/react/iframe-missing-sandbox.html) | react | | 🚧 |
| [jsx-no-comment-textnodes](/docs/guide/usage/linter/rules/react/jsx-no-comment-textnodes.html) | react | | |
Expand Down Expand Up @@ -457,7 +458,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 (153):
## Style (155):

Code that should be written in a more idiomatic way.

Expand Down Expand Up @@ -533,6 +534,7 @@ Code that should be written in a more idiomatic way.
| [no-test-prefixes](/docs/guide/usage/linter/rules/jest/no-test-prefixes.html) | jest | | 🛠️ |
| [no-test-return-statement](/docs/guide/usage/linter/rules/jest/no-test-return-statement.html) | jest | | |
| [no-untyped-mock-factory](/docs/guide/usage/linter/rules/jest/no-untyped-mock-factory.html) | jest | | 🛠️ |
| [padding-around-test-blocks](/docs/guide/usage/linter/rules/jest/padding-around-test-blocks.html) | jest | | 🛠️ |
| [prefer-called-with](/docs/guide/usage/linter/rules/jest/prefer-called-with.html) | jest | | |
| [prefer-comparison-matcher](/docs/guide/usage/linter/rules/jest/prefer-comparison-matcher.html) | jest | | 🛠️ |
| [prefer-each](/docs/guide/usage/linter/rules/jest/prefer-each.html) | jest | | |
Expand Down Expand Up @@ -562,6 +564,7 @@ Code that should be written in a more idiomatic way.
| [jsx-boolean-value](/docs/guide/usage/linter/rules/react/jsx-boolean-value.html) | react | | 🛠️ |
| [jsx-curly-brace-presence](/docs/guide/usage/linter/rules/react/jsx-curly-brace-presence.html) | react | | 🛠️ |
| [jsx-fragments](/docs/guide/usage/linter/rules/react/jsx-fragments.html) | react | | 🛠️ |
| [jsx-handler-names](/docs/guide/usage/linter/rules/react/jsx-handler-names.html) | react | | |
| [no-set-state](/docs/guide/usage/linter/rules/react/no-set-state.html) | react | | |
| [prefer-es6-class](/docs/guide/usage/linter/rules/react/prefer-es6-class.html) | react | | |
| [self-closing-comp](/docs/guide/usage/linter/rules/react/self-closing-comp.html) | react | | 🛠️ |
Expand Down
22 changes: 13 additions & 9 deletions src/docs/guide/usage/linter/rules/eslint/func-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ You can specify which you prefer in the configuration.

### Examples

```js
// function declaration
function doSomething() {
// ...
// ...
}

// arrow function expression assigned to a variable
const doSomethingElse = () => {
// ...
// ...
};

// function expression assigned to a variable
const doSomethingAgain = function() {
// ...
// ...
};
```

Examples of incorrect code for this rule with the default "expression" option:

Expand Down Expand Up @@ -82,23 +84,25 @@ export var bar = () => {};

Examples of correct code for this rule with the default "expression" option:

````js
```js
/*eslint func-style: ["error", "expression"]*/
var foo = function() {
// ...
// ...
};
```

Examples of correct code for this rule with the "declaration" option:

```js
/*eslint func-style: ["error", "declaration"]*/
function foo() {
// ...
// ...
}
// Methods (functions assigned to objects) are not checked by this rule
// Methods (functions assigned to objects) are not checked by this rule
SomeObject.foo = function() {
// ...
// ...
};
````
```

Examples of additional correct code for this rule with the "declaration", { "allowArrowFunctions": true } options:

Expand Down
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/eslint/no-console.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Example of **incorrect** code for this option:
console.log("foo");
```

Example of **incorrect** code for this option:
Example of **correct** code for this option:

```javascript
console.info("foo");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->

<script setup>
import { data } from '../version.data.js';
const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_linter/src/rules/jest/padding_around_test_blocks.rs`;
</script>

# jest/padding-around-test-blocks <Badge type="info" text="Style" />

<div class="rule-meta">
<Alert class="fix" type="info">
<span class="emoji">🛠️</span> An auto-fix is available for this rule.
</Alert>
</div>

### What it does

This rule enforces a line of padding before and after 1 or more test/it statements

### Examples

Examples of **incorrect** code for this rule:

```js
const thing = 123;
test("foo", () => {});
test("bar", () => {});
```

```js
const thing = 123;
it("foo", () => {});
it("bar", () => {});
```

Examples of **correct** code for this rule:

```js
const thing = 123;

test("foo", () => {});

test("bar", () => {});
```

```js
const thing = 123;

it("foo", () => {});

it("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 jest/padding-around-test-blocks --jest-plugin
```

```json [Config (.oxlintrc.json)]
{
"plugins": ["jest"],
"rules": {
"jest/padding-around-test-blocks": "error"
}
}
```

:::

## References

- <a v-bind:href="source" target="_blank" rel="noreferrer">Rule Source</a>
170 changes: 170 additions & 0 deletions src/docs/guide/usage/linter/rules/promise/always-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->

<script setup>
import { data } from '../version.data.js';
const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_linter/src/rules/promise/always_return.rs`;
</script>

# promise/always-return <Badge type="info" text="Suspicious" />

<div class="rule-meta">
</div>

### What it does

Require returning inside each `then()` to create readable and reusable Promise chains.
We also allow someone to throw inside a `then()` which is essentially the same as return `Promise.reject()`.

### Why is this bad?

Broken Promise Chain.
Inside the first `then()` callback, a function is called but not returned.
This causes the next `then()` in the chain to execute immediately without waiting for the called function to complete.

### Examples

Examples of **incorrect** code for this rule:

```javascript
myPromise.then(function(val) {});
myPromise.then(() => {
doSomething();
});
myPromise.then((b) => {
if (b) {
return "yes";
} else {
forgotToReturn();
}
});
```

Examples of **correct** code for this rule:

```javascript
myPromise.then((val) => val * 2);
myPromise.then(function(val) {
return val * 2;
});
myPromise.then(doSomething); // could be either
myPromise.then((b) => {
if (b) {
return "yes";
} else {
return "no";
}
});
```

### Options

#### `ignoreLastCallback`

You can pass an `{ ignoreLastCallback: true }` as an option to this rule so that
the last `then()` callback in a promise chain does not warn if it does not have
a `return`. Default is `false`.

```javascript
// OK
promise.then((x) => {
console.log(x);
});
// OK
void promise.then((x) => {
console.log(x);
});
// OK
await promise.then((x) => {
console.log(x);
});

promise
// NG
.then((x) => {
console.log(x);
})
// OK
.then((x) => {
console.log(x);
});

// NG
const v = promise.then((x) => {
console.log(x);
});
// NG
const v = await promise.then((x) => {
console.log(x);
});
function foo() {
// NG
return promise.then((x) => {
console.log(x);
});
}
```

#### `ignoreAssignmentVariable`

You can pass an `{ ignoreAssignmentVariable: [] }` as an option to this rule
with a list of variable names so that the last `then()` callback in a promise
chain does not warn if it does an assignment to a global variable. Default is
`["globalThis"]`.

```javascript
/* eslint promise/always-return: ["error", { ignoreAssignmentVariable: ["globalThis"] }] */

// OK
promise.then((x) => {
globalThis = x;
});

promise.then((x) => {
globalThis.x = x;
});

// OK
promise.then((x) => {
globalThis.x.y = x;
});

// NG
promise.then((x) => {
anyOtherVariable = x;
});

// NG
promise.then((x) => {
anyOtherVariable.x = x;
});

// NG
promise.then((x) => {
x();
});
```

## How to use

To **enable** this rule in the CLI or using the config file, you can use:

::: code-group

```bash [CLI]
oxlint --deny promise/always-return --promise-plugin
```

```json [Config (.oxlintrc.json)]
{
"plugins": ["promise"],
"rules": {
"promise/always-return": "error"
}
}
```

:::

## References

- <a v-bind:href="source" target="_blank" rel="noreferrer">Rule Source</a>
Loading