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
17 changes: 11 additions & 6 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: 414
- Total number of rules: 419
- Rules turned on by default: 93

## Correctness (166):
Expand Down Expand Up @@ -132,7 +132,7 @@ Code that is outright wrong or useless.
| [bad-object-literal-comparison](/docs/guide/usage/linter/rules/oxc/bad-object-literal-comparison.html) | oxc | ✅ | |
| [bad-replace-all-arg](/docs/guide/usage/linter/rules/oxc/bad-replace-all-arg.html) | oxc | ✅ | |
| [const-comparisons](/docs/guide/usage/linter/rules/oxc/const-comparisons.html) | oxc | ✅ | |
| [double-comparisons](/docs/guide/usage/linter/rules/oxc/double-comparisons.html) | oxc | ✅ | |
| [double-comparisons](/docs/guide/usage/linter/rules/oxc/double-comparisons.html) | oxc | ✅ | 🛠️ |
| [erasing-op](/docs/guide/usage/linter/rules/oxc/erasing-op.html) | oxc | ✅ | |
| [missing-throw](/docs/guide/usage/linter/rules/oxc/missing-throw.html) | oxc | ✅ | 💡 |
| [number-arg-out-of-range](/docs/guide/usage/linter/rules/oxc/number-arg-out-of-range.html) | oxc | ✅ | |
Expand Down Expand Up @@ -189,7 +189,7 @@ Code that can be written to run faster.
| [jsx-no-new-function-as-prop](/docs/guide/usage/linter/rules/react_perf/jsx-no-new-function-as-prop.html) | react_perf | | |
| [jsx-no-new-object-as-prop](/docs/guide/usage/linter/rules/react_perf/jsx-no-new-object-as-prop.html) | react_perf | | |

## Restriction (53):
## Restriction (55):

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.
| Rule name | Source | Default | Fixable? |
Expand Down Expand Up @@ -224,6 +224,8 @@ Lints which prevent the use of language and library features. Must not be enable
| [no-optional-chaining](/docs/guide/usage/linter/rules/oxc/no-optional-chaining.html) | oxc | | |
| [no-rest-spread-properties](/docs/guide/usage/linter/rules/oxc/no-rest-spread-properties.html) | oxc | | |
| [avoid-new](/docs/guide/usage/linter/rules/promise/avoid-new.html) | promise | | |
| [catch-or-return](/docs/guide/usage/linter/rules/promise/catch-or-return.html) | promise | | |
| [spec-only](/docs/guide/usage/linter/rules/promise/spec-only.html) | promise | | |
| [button-has-type](/docs/guide/usage/linter/rules/react/button-has-type.html) | react | | |
| [no-danger](/docs/guide/usage/linter/rules/react/no-danger.html) | react | | |
| [no-unknown-property](/docs/guide/usage/linter/rules/react/no-unknown-property.html) | react | | |
Expand All @@ -248,7 +250,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 (17):
## Suspicious (18):

code that is most likely wrong or useless.
| Rule name | Source | Default | Fixable? |
Expand All @@ -263,6 +265,7 @@ code that is most likely wrong or useless.
| [no-commented-out-tests](/docs/guide/usage/linter/rules/jest/no-commented-out-tests.html) | jest | | |
| [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 | | |
| [jsx-no-comment-textnodes](/docs/guide/usage/linter/rules/react/jsx-no-comment-textnodes.html) | react | | |
| [react-in-jsx-scope](/docs/guide/usage/linter/rules/react/react-in-jsx-scope.html) | react | | |
| [no-confusing-non-null-assertion](/docs/guide/usage/linter/rules/typescript/no-confusing-non-null-assertion.html) | typescript | | |
Expand Down Expand Up @@ -342,10 +345,10 @@ Lints which are rather strict or have occasional false positives.
| [prefer-regexp-test](/docs/guide/usage/linter/rules/unicorn/prefer-regexp-test.html) | unicorn | | 🛠️ |
| [prefer-string-replace-all](/docs/guide/usage/linter/rules/unicorn/prefer-string-replace-all.html) | unicorn | | 🛠️ |
| [prefer-string-slice](/docs/guide/usage/linter/rules/unicorn/prefer-string-slice.html) | unicorn | | 🛠️ |
| [prefer-type-error](/docs/guide/usage/linter/rules/unicorn/prefer-type-error.html) | unicorn | | 🚧 |
| [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 (94):
## Style (96):

Code that should be written in a more idiomatic way.
| Rule name | Source | Default | Fixable? |
Expand All @@ -358,6 +361,7 @@ Code that should be written in a more idiomatic way.
| [no-continue](/docs/guide/usage/linter/rules/eslint/no-continue.html) | eslint | | |
| [no-label-var](/docs/guide/usage/linter/rules/eslint/no-label-var.html) | eslint | | |
| [no-multi-str](/docs/guide/usage/linter/rules/eslint/no-multi-str.html) | eslint | | |
| [no-new-func](/docs/guide/usage/linter/rules/eslint/no-new-func.html) | eslint | | |
| [no-script-url](/docs/guide/usage/linter/rules/eslint/no-script-url.html) | eslint | | |
| [no-template-curly-in-string](/docs/guide/usage/linter/rules/eslint/no-template-curly-in-string.html) | eslint | | |
| [no-ternary](/docs/guide/usage/linter/rules/eslint/no-ternary.html) | eslint | | |
Expand Down Expand Up @@ -443,6 +447,7 @@ Code that should be written in a more idiomatic way.
| [no-import-node-test](/docs/guide/usage/linter/rules/vitest/no-import-node-test.html) | vitest | | 🛠️ |
| [prefer-each](/docs/guide/usage/linter/rules/vitest/prefer-each.html) | vitest | | |
| [prefer-to-be-falsy](/docs/guide/usage/linter/rules/vitest/prefer-to-be-falsy.html) | vitest | | 🛠️ |
| [prefer-to-be-object](/docs/guide/usage/linter/rules/vitest/prefer-to-be-object.html) | vitest | | 🛠️ |
| [prefer-to-be-truthy](/docs/guide/usage/linter/rules/vitest/prefer-to-be-truthy.html) | vitest | | 🛠️ |

## Nursery (10):
Expand Down
39 changes: 39 additions & 0 deletions src/docs/guide/usage/linter/rules/eslint/no-new-func.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->

# eslint/no-new-func <Badge type="info" text="Style" />

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

### What it does

The rule disallow `new` operators with the `Function` object.

### Why is this bad?

Using `new Function` or `Function` can lead to code that is difficult to understand and maintain. It can introduce security risks similar to those associated with `eval` because it generates a new function from a string of code, which can be a vector for injection attacks. Additionally, it impacts performance negatively as these functions are not optimized by the JavaScript engine.

### Examples

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

```js
var x = new Function("a", "b", "return a + b");
var x = Function("a", "b", "return a + b");
var x = Function.call(null, "a", "b", "return a + b");
var x = Function.apply(null, ["a", "b", "return a + b"]);
var x = Function.bind(null, "a", "b", "return a + b")();
var f = Function.bind(null, "a", "b", "return a + b");
```

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

```js
let x = function (a, b) {
return a + b;
};
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/eslint/no_new_func.rs)
3 changes: 3 additions & 0 deletions src/docs/guide/usage/linter/rules/oxc/double-comparisons.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<Alert class="default-on" type="success">
<span class="emoji">✅</span> This rule is turned on by default.
</Alert>
<Alert class="fix" type="info">
<span class="emoji">🛠️</span> An auto-fix is available for this rule.
</Alert>
</div>

### What it does
Expand Down
7 changes: 6 additions & 1 deletion src/docs/guide/usage/linter/rules/oxc/erasing-op.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ The whole expression can be replaced by zero. This is most likely not the intend

### Example

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

```javascript
// Bad
let x = 1;
let y = x * 0;
```

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

```javascript
let x = 1;
let y = 0;
```
Expand Down
12 changes: 11 additions & 1 deletion src/docs/guide/usage/linter/rules/oxc/no-accumulating-spread.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

### What it does

Prevents using object or array spreads on accumulators in `Array.prototype.reduce()`.
Prevents using object or array spreads on accumulators in `Array.prototype.reduce()` and in loops.

### Why is this bad?

Expand Down Expand Up @@ -38,13 +38,23 @@ Object.keys(obj).reduce((acc, el) => {
acc[el] = { ...obj[el] };
return acc;
}, {});

let foo = [];
for (let i = 0; i < 10; i++) {
foo.push(i);
}
```

Fail

```javascript
arr.reduce((acc, x) => ({ ...acc, [x]: fn(x) }), {});
Object.keys(obj).reduce((acc, el) => ({ ...acc, [el]: fn(el) }), {});

let foo = [];
for (let i = 0; i < 10; i++) {
foo = [...foo, i];
}
```

## References
Expand Down
117 changes: 117 additions & 0 deletions src/docs/guide/usage/linter/rules/oxc/no-async-endpoint-handlers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->

# oxc/no-async-endpoint-handlers <Badge type="info" text="Suspicious" />

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

### What it does

Disallows the use of `async` functions as Express endpoint handlers.

### Why is this bad?

Before v5, Express will not automatically handle Promise rejections from
handler functions with your application's error handler. You must
instead explicitly pass the rejected promise to `next()`.

```js
const app = express();
app.get("/", (req, res, next) => {
new Promise((resolve, reject) => {
return User.findById(req.params.id);
})
.then((user) => res.json(user))
.catch(next);
});
```

If this is not done, your server will crash with an unhandled promise
rejection.

```js
const app = express();
app.get("/", async (req, res) => {
// Server will crash if User.findById rejects
const user = await User.findById(req.params.id);
res.json(user);
});
```

See [Express' Error Handling
Guide](https://expressjs.com/en/guide/error-handling.html) for more
information.

### Examples

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

```js
const app = express();
app.get("/", async (req, res) => {
const user = await User.findById(req.params.id);
res.json(user);
});

const router = express.Router();
router.use(async (req, res, next) => {
const user = await User.findById(req.params.id);
req.user = user;
next();
});

const createUser = async (req, res) => {
const user = await User.create(req.body);
res.json(user);
};
app.post("/user", createUser);

// Async handlers that are imported will not be detected because each
// file is checked in isolation. This does not trigger the rule, but still
// violates it and _will_ result in server crashes.
const asyncHandler = require("./asyncHandler");
app.get("/async", asyncHandler);
```

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

```js
const app = express();
// not async
app.use((req, res, next) => {
req.receivedAt = Date.now();
});

app.get("/", (req, res, next) => {
fs.readFile("/file-does-not-exist", (err, data) => {
if (err) {
next(err); // Pass errors to Express.
} else {
res.send(data);
}
});
});

const asyncHandler = async (req, res) => {
const user = await User.findById(req.params.id);
res.json(user);
};
app.get("/user", (req, res, next) => asyncHandler(req, res).catch(next));
```

## Configuration

This rule takes the following configuration:

```ts
type NoAsyncEndpointHandlersConfig = {
/**
* An array of names that are allowed to be async.
*/
allowedNames?: string[];
};
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/oxc/no_async_endpoint_handlers.rs)
38 changes: 38 additions & 0 deletions src/docs/guide/usage/linter/rules/promise/catch-or-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->

# promise/catch-or-return <Badge type="info" text="Restriction" />

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

### What it does

Ensure that each time a then() is applied to a promise, a catch() is applied as well.
Exceptions are made if you are returning that promise.

### Why is this bad?

Not catching errors in a promise can cause hard to debug problems or missing handling of
error conditions.

### Example

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

```javascript
myPromise.then(doSomething);
myPromise.then(doSomething, catchErrors); // catch() may be a little better
```

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

```javascript
myPromise.then(doSomething).catch(errors);
function doSomethingElse() {
return myPromise.then(doSomething);
}
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/promise/catch_or_return.rs)
32 changes: 32 additions & 0 deletions src/docs/guide/usage/linter/rules/promise/spec-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->

# promise/spec-only <Badge type="info" text="Restriction" />

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

### What it does

Disallow use of non-standard Promise static methods.

### Why is this bad?

Non-standard Promises may cost more maintenance work.

### Examples

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

```js
Promise.done();
```

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

```js
Promise.resolve();
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/promise/spec_only.rs)
Loading