Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/docs/guide/usage/linter/generated-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Arguments:
Enable the React performance plugin and detect rendering performance problems
- **` --promise-plugin`** —
Enable the promise plugin and detect promise usage problems
- **` --node-plugin`** —
Enable the node plugin and detect node usage problems

## Fix Problems

Expand Down
68 changes: 37 additions & 31 deletions src/docs/guide/usage/linter/generated-rules.md

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions src/docs/guide/usage/linter/rules/eslint/no-alert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. -->

# eslint/no-alert <Badge type="info" text="Restriction" />

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

### What it does

Disallow the use of alert, confirm, and prompt

### Why is this bad?

JavaScript’s alert, confirm, and prompt functions are widely considered to be obtrusive as UI elements and should be replaced by a more appropriate custom UI implementation.
Furthermore, alert is often used while debugging code, which should be removed before deployment to production.

### Examples

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

```js
alert("here!");

confirm("Are you sure?");

prompt("What's your name?", "John Doe");
```

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

```js
customAlert("Something happened!");

customConfirm("Are you sure?");

customPrompt("Who are you?");

function foo() {
var alert = myCustomLib.customAlert;
alert();
}
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/eslint/no_alert.rs)
4 changes: 2 additions & 2 deletions src/docs/guide/usage/linter/rules/eslint/no-await-in-loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Instead, they are being run in series, which can lead to poorer performance.

### Example

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

```javascript
async function bad() {
Expand All @@ -26,7 +26,7 @@ async function bad() {
}
```

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

```javascript
async function good() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Forbidding this pattern prevents mistakes resulting from unfamiliarity with the

### Example

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

```rust
class C {
constructor() { return 42; }
}
```

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

```rust
class C {
Expand Down
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 still under development.
</Alert>
</div>

### What it does
Expand Down
8 changes: 6 additions & 2 deletions src/docs/guide/usage/linter/rules/eslint/no-obj-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ Calling them as functions will usually result in a TypeError being thrown.

### Example

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

```javascript
// Bad
let math = Math();
let newMath = new Math();

Expand All @@ -35,8 +36,11 @@ let newIntl = new Intl();

let reflect = Reflect();
let newReflect = new Reflect();
```

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

```javascript
let area = (r) => 2 * Math.PI * r * r;
let object = JSON.parse("{}");
let first = Atomics.load(sharedArray, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ Disallow unused private class members

Private class members that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such class members take up space in the code and can lead to confusion by readers.

### Example
### Examples

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

```javascript
/// bad
class A {
#unusedMember = 5;
}
Expand All @@ -46,14 +47,18 @@ class E {
get #unusedAccessor() {}
set #unusedAccessor(value) {}
}
```

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

/// Good
```javascript
class A {
#usedMember = 42;
method() {
return this.#usedMember;
}
}

class B {
#usedMethod() {
return 42;
Expand All @@ -62,6 +67,7 @@ class B {
return this.#usedMethod();
}
}

class C {
get #usedAccessor() {}
set #usedAccessor(value) {}
Expand Down
8 changes: 6 additions & 2 deletions src/docs/guide/usage/linter/rules/eslint/no-useless-rename.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ It is unnecessary to rename a variable to the same name.

### Example

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

```javascript
// Bad
import { foo as foo } from "foo";
const { bar: bar } = obj;
export { baz as baz };
```

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

```javascript
import { foo } from "foo";
const { bar: renamed } = obj;
export { baz };
Expand Down
38 changes: 38 additions & 0 deletions src/docs/guide/usage/linter/rules/eslint/sort-vars.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. -->

# eslint/sort-vars <Badge type="info" text="Pedantic" />

<div class="rule-meta">
<Alert class="fix" type="info">
<span class="emoji">🚧</span> An auto-fix is still under development.
</Alert>
</div>

### What it does

When declaring multiple variables within the same block, sorting variable names make it
easier to find necessary variable easier at a later time.

### Why is this bad?

Unsorted variable declarations can make the code harder to read and maintain.

### Examples

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

```js
var b, a;
var a, B, c;
```

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

```js
var a, b, c, d;
var B, a, c;
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/eslint/sort_vars.rs)
13 changes: 10 additions & 3 deletions src/docs/guide/usage/linter/rules/import/no-amd.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@

Forbid AMD `require` and `define` calls.

### Example
### Why is this bad?

### Examples

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

```javascript
// fail
require([a, b], function () {});
// pass
```

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

```javascript
require("../name");
require(`../name`);
```
Expand Down
19 changes: 9 additions & 10 deletions src/docs/guide/usage/linter/rules/import/no-default-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ Forbid a module to have a default exports. This help your editor to provide bett

### Examples

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

```javascript
// bad1.js
export default 'bar';

// There is a default export.
export const foo = "foo";
const bar = "bar";
export default "bar";
const foo = 'foo';
export { foo as default }
```

```javascript
// bad2.js
Examples of **correct** code for this rule:

// There is a default export.
const foo = "foo";
export { foo as default };
```javascript
export const foo = "foo";
export const bar = "bar";
```

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

# import/no-dynamic-require <Badge type="info" text="Restriction" />

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

### What it does

Forbid imports which use an expression for the module argument.

### Why is this bad?

Import statements which use an expression resolved at runtime makes it to find where the
import comes from and some static code analysis tools might not be able to resolve them.

### Examples

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

```javascript
require(name);
require(`../${name}`);
```

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

```javascript
require("../name");
require(`../name`);
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/import/no_dynamic_require.rs)
18 changes: 11 additions & 7 deletions src/docs/guide/usage/linter/rules/jsdoc/check-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@ Also reports:

It is important to have a consistent way of specifying access levels.

### Example
### Examples

```javascript
// Passing
/** @access private */

/** @private */
Examples of **incorrect** code for this rule:

// Failing
```javascript
/** @access private @public */

/** @access invalidlevel */
```

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

```javascript
/** @access private */

/** @private */
```

## References

- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/jsdoc/check_access.rs)
15 changes: 10 additions & 5 deletions src/docs/guide/usage/linter/rules/jsdoc/check-property-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,34 @@ Ensures that property names in JSDoc are not duplicated on the same block and th

`@property` tags with the same name can be confusing and may indicate a mistake.

### Example
### Examples

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

```javascript
// Passing
/**
* @typedef {object} state
* @property {number} foo
* @property {string} foo
*/

/**
* @typedef {object} state
* @property {object} foo
* @property {number} foo.bar
*/
```

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

```javascript
/**
* @typedef {object} state
* @property {number} foo
* @property {string} foo
*/

/**
* @typedef {object} state
* @property {object} foo
* @property {number} foo.bar
*/
```
Expand Down
Loading