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
21 changes: 13 additions & 8 deletions src/docs/guide/usage/linter/generated-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

The progress of all rule implementations is tracked [here](https://github.com/oxc-project/oxc/issues/481).

- Total number of rules: 574
- Rules turned on by default: 103
- Total number of rules: 579
- Rules turned on by default: 102

**Legend for 'Fixable?' column:**

Expand Down Expand Up @@ -174,7 +174,6 @@ Code that is outright wrong or useless.
| [await-thenable](/docs/guide/usage/linter/rules/typescript/await-thenable.html) | typescript | ✅ | 🚧 |
| [no-array-delete](/docs/guide/usage/linter/rules/typescript/no-array-delete.html) | typescript | ✅ | 🚧 |
| [no-base-to-string](/docs/guide/usage/linter/rules/typescript/no-base-to-string.html) | typescript | ✅ | 🚧 |
| [no-confusing-void-expression](/docs/guide/usage/linter/rules/typescript/no-confusing-void-expression.html) | typescript | ✅ | 🚧 |
| [no-duplicate-enum-values](/docs/guide/usage/linter/rules/typescript/no-duplicate-enum-values.html) | typescript | ✅ | |
| [no-duplicate-type-constituents](/docs/guide/usage/linter/rules/typescript/no-duplicate-type-constituents.html) | typescript | ✅ | 🚧 |
| [no-extra-non-null-assertion](/docs/guide/usage/linter/rules/typescript/no-extra-non-null-assertion.html) | typescript | ✅ | |
Expand All @@ -184,7 +183,7 @@ Code that is outright wrong or useless.
| [no-meaningless-void-operator](/docs/guide/usage/linter/rules/typescript/no-meaningless-void-operator.html) | typescript | ✅ | 🚧 |
| [no-misused-new](/docs/guide/usage/linter/rules/typescript/no-misused-new.html) | typescript | ✅ | |
| [no-misused-spread](/docs/guide/usage/linter/rules/typescript/no-misused-spread.html) | typescript | ✅ | 🚧 |
| [no-non-null-asserted-optional-chain](/docs/guide/usage/linter/rules/typescript/no-non-null-asserted-optional-chain.html) | typescript | ✅ | 🛠️ |
| [no-non-null-asserted-optional-chain](/docs/guide/usage/linter/rules/typescript/no-non-null-asserted-optional-chain.html) | typescript | ✅ | 💡 |
| [no-redundant-type-constituents](/docs/guide/usage/linter/rules/typescript/no-redundant-type-constituents.html) | typescript | ✅ | 🚧 |
| [no-this-alias](/docs/guide/usage/linter/rules/typescript/no-this-alias.html) | typescript | ✅ | |
| [no-unnecessary-parameter-property-assignment](/docs/guide/usage/linter/rules/typescript/no-unnecessary-parameter-property-assignment.html) | typescript | ✅ | 💡 |
Expand Down Expand Up @@ -213,6 +212,7 @@ Code that is outright wrong or useless.
| [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 | | 🚧 |
| [valid-define-props](/docs/guide/usage/linter/rules/vue/valid-define-props.html) | vue | | 🚧 |

## Perf (11):

Expand All @@ -232,7 +232,7 @@ Code that can be written to run faster.
| [prefer-array-flat-map](/docs/guide/usage/linter/rules/unicorn/prefer-array-flat-map.html) | unicorn | | 🛠️ |
| [prefer-set-has](/docs/guide/usage/linter/rules/unicorn/prefer-set-has.html) | unicorn | | ⚠️🛠️️ |

## Restriction (70):
## Restriction (71):

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.

Expand Down Expand Up @@ -308,8 +308,9 @@ Lints which prevent the use of language and library features. Must not be enable
| [prefer-modern-math-apis](/docs/guide/usage/linter/rules/unicorn/prefer-modern-math-apis.html) | unicorn | | 🚧 |
| [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 | | ⚠️🛠️️ |
| [no-multiple-slot-args](/docs/guide/usage/linter/rules/vue/no-multiple-slot-args.html) | vue | | 🚧 |

## Suspicious (40):
## Suspicious (41):

code that is most likely wrong or useless.

Expand Down Expand Up @@ -352,11 +353,12 @@ code that is most likely wrong or useless.
| [no-unsafe-type-assertion](/docs/guide/usage/linter/rules/typescript/no-unsafe-type-assertion.html) | typescript | | 🚧 |
| [consistent-function-scoping](/docs/guide/usage/linter/rules/unicorn/consistent-function-scoping.html) | unicorn | | 🚧 |
| [no-accessor-recursion](/docs/guide/usage/linter/rules/unicorn/no-accessor-recursion.html) | unicorn | | |
| [no-array-reverse](/docs/guide/usage/linter/rules/unicorn/no-array-reverse.html) | unicorn | | 🛠️ |
| [no-instanceof-builtins](/docs/guide/usage/linter/rules/unicorn/no-instanceof-builtins.html) | unicorn | | 🚧 |
| [prefer-add-event-listener](/docs/guide/usage/linter/rules/unicorn/prefer-add-event-listener.html) | unicorn | | 🚧 |
| [require-post-message-target-origin](/docs/guide/usage/linter/rules/unicorn/require-post-message-target-origin.html) | unicorn | | 💡 |

## Pedantic (96):
## Pedantic (97):

Lints which are rather strict or have occasional false positives.

Expand Down Expand Up @@ -402,6 +404,7 @@ Lints which are rather strict or have occasional false positives.
| [rules-of-hooks](/docs/guide/usage/linter/rules/react/rules-of-hooks.html) | react | | |
| [ban-ts-comment](/docs/guide/usage/linter/rules/typescript/ban-ts-comment.html) | typescript | | 🛠️ |
| [ban-types](/docs/guide/usage/linter/rules/typescript/ban-types.html) | typescript | | 🚧 |
| [no-confusing-void-expression](/docs/guide/usage/linter/rules/typescript/no-confusing-void-expression.html) | typescript | | 🚧 |
| [no-misused-promises](/docs/guide/usage/linter/rules/typescript/no-misused-promises.html) | typescript | | 🚧 |
| [no-mixed-enums](/docs/guide/usage/linter/rules/typescript/no-mixed-enums.html) | typescript | | 🚧 |
| [no-unsafe-argument](/docs/guide/usage/linter/rules/typescript/no-unsafe-argument.html) | typescript | | 🚧 |
Expand Down Expand Up @@ -459,7 +462,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 (155):
## Style (157):

Code that should be written in a more idiomatic way.

Expand Down Expand Up @@ -620,6 +623,8 @@ Code that should be written in a more idiomatic way.
| [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 | | 🛠️ |
| [define-emits-declaration](/docs/guide/usage/linter/rules/vue/define-emits-declaration.html) | vue | | 🚧 |
| [define-props-declaration](/docs/guide/usage/linter/rules/vue/define-props-declaration.html) | vue | | |

## Nursery (8):

Expand Down
69 changes: 64 additions & 5 deletions src/docs/guide/usage/linter/rules/eslint/block-scoped-var.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,97 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin

### What it does

Generates warnings when variables are used outside of the block in which they were defined.
This emulates C-style block scope.
Enforces that variables are both **declared** and **used** within the same block scope.
This rule prevents accidental use of variables outside their intended block, mimicking C-style block scoping in JavaScript.

### Why is this bad?

This rule aims to reduce the usage of variables outside of their binding context
and emulate traditional block scope from other languages.
This is to help newcomers to the language avoid difficult bugs with variable hoisting.
JavaScript’s `var` declarations are hoisted to the top of their enclosing function, which can cause variables declared in a block (e.g., inside an `if` or `for`) to be accessible outside of it.
This can lead to hard-to-find bugs.
By enforcing block scoping, this rule helps avoid hoisting issues and aligns more closely with how other languages treat block variables.

### Options

No options available for this rule.

### Examples

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

```js
/* block-scoped-var: "error" */

function doIf() {
if (true) {
var build = true;
}
console.log(build);
}

function doLoop() {
for (var i = 0; i < 10; i++) {
// do something
}
console.log(i); // i is accessible here
}

function doSomething() {
if (true) {
var foo = 1;
}
if (false) {
foo = 2;
}
}

function doTry() {
try {
var foo = 1;
} catch (e) {
console.log(foo);
}
}
```

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

```js
/* block-scoped-var: "error" */

function doIf() {
var build;
if (true) {
build = true;
}
console.log(build);
}

function doLoop() {
var i;
for (i = 0; i < 10; i++) {
// do something
}
console.log(i);
}

function doSomething() {
var foo;
if (true) {
foo = 1;
}
if (false) {
foo = 2;
}
}

function doTry() {
var foo;
try {
foo = 1;
} catch (e) {
console.log(foo);
}
}
```

## How to use
Expand Down
31 changes: 24 additions & 7 deletions src/docs/guide/usage/linter/rules/eslint/default-case-last.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin

### What it does

Enforce default clauses in switch statements to be last
Requires the `default` clause in `switch` statements to be the last one.

### Why is this bad?

A switch statement can optionally have a default clause.
If present, it’s usually the last clause, but it doesn’t need to be. It is also allowed to put the default clause before all case clauses, or anywhere between. The behavior is mostly the same as if it was the last clause. The default block will be still executed only if there is no match in the case clauses (including those defined after the default), but there is also the ability to “fall through” from the default clause to the following clause in the list. However, such flow is not common and it would be confusing to the readers.
Even if there is no “fall through” logic, it’s still unexpected to see the default clause before or between the case clauses. By convention, it is expected to be the last clause.
If a switch statement should have a default clause, it’s considered a best practice to define it as the last clause.
By convention and for readability, the `default` clause should be the last one in a `switch`.
While it is legal to place it before or between `case` clauses, doing so is confusing and may
lead to unexpected "fall-through" behavior.

### Options

No options available for this rule

### Examples

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

```javascript
```js
/* default-case-last: "error" */

switch (foo) {
default:
bar();
Expand All @@ -50,7 +55,9 @@ switch (foo) {

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

```javascript
```js
/* default-case-last: "error" */

switch (foo) {
case 1:
bar();
Expand All @@ -62,6 +69,16 @@ switch (foo) {
baz();
break;
}

switch (foo) {
case "x":
bar();
break;
case "y":
default:
baz();
break;
}
```

## How to use
Expand Down
69 changes: 37 additions & 32 deletions src/docs/guide/usage/linter/rules/eslint/default-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,39 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin

### What it does

Require default cases in switch statements
Enforces that all `switch` statements include a `default` case,
unless explicitly marked with a configured comment.

### Why is this bad?

Some code conventions require that all switch statements have a default case,
even if the default case is empty. The thinking is that it’s better to always
explicitly state what the default behavior should be so that it’s clear
whether or not the developer forgot to include the default behavior by mistake.
Without a `default` case, it is unclear whether the omission was
intentional or an oversight. Adding a `default` or a special comment
makes the code more explicit and reduces mistakes.

You may optionally include a `// no default` after the last case if there is
no default case. The comment may be in any desired case, such as `// No Default`.

### Examples
### Options

First option:

- Type: `object`
- Properties:
- `commentPattern`: `string` (default: `/^no default$/i`) - A regex pattern used to detect comments that mark the absence of a `default` case as intentional.

Example configuration:

```json
{
"default-case": ["error", { "commentPattern": "^skip\\sdefault" }]
}
```

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

```javascript
```js
/* default-case: ["error"] */

switch (foo) {
case 1:
break;
Expand All @@ -37,56 +53,45 @@ switch (foo) {

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

```javascript
```js
/* default-case: ["error"] */

switch (a) {
case 1:
/* code */
break;

default:
/* code */
break;
}
```

```javascript
switch (a) {
case 1:
/* code */
break;

// no default
}
```

```javascript
#### `commentPattern`

Examples of **incorrect** code for this rule with the `{ "commentPattern": "^skip\\sdefault" }` option:

```js
/* default-case: ["error", { "commentPattern": "^skip\\sdefault" }] */

switch (a) {
case 1:
/* code */
break;

// No Default
// no default
}
```

### Options

#### commentPattern

`{ type: string, default: "/^no default$/i" }`
Examples of **correct** code for this rule with the `{ "commentPattern": "^skip\\sdefault" }` option:

This option is for specifying an alternative regular expression which
will override the default `/^no default$/i` comment test pattern.
```js
/* default-case: ["error", { "commentPattern": "^skip\\sdefault" }] */

For example if `{ "commentPattern": "^skip\\sdefault" }` were used
then the following example would not violate the rule:

```javascript
switch (a) {
case 1:
/* code */
break;

// skip default
}
```
Expand Down
Loading