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
11 changes: 7 additions & 4 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: 579
- Total number of rules: 582
- Rules turned on by default: 102

**Legend for 'Fixable?' column:**
Expand Down Expand Up @@ -232,12 +232,13 @@ 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 (71):
## Restriction (72):

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? |
| --------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------- | -------- |
| [class-methods-use-this](/docs/guide/usage/linter/rules/eslint/class-methods-use-this.html) | eslint | | |
| [default-case](/docs/guide/usage/linter/rules/eslint/default-case.html) | eslint | | |
| [no-alert](/docs/guide/usage/linter/rules/eslint/no-alert.html) | eslint | | |
| [no-bitwise](/docs/guide/usage/linter/rules/eslint/no-bitwise.html) | eslint | | |
Expand Down Expand Up @@ -310,7 +311,7 @@ Lints which prevent the use of language and library features. Must not be enable
| [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 (41):
## Suspicious (42):

code that is most likely wrong or useless.

Expand All @@ -324,6 +325,7 @@ code that is most likely wrong or useless.
| [no-unneeded-ternary](/docs/guide/usage/linter/rules/eslint/no-unneeded-ternary.html) | eslint | | ⚠️🛠️️ |
| [no-useless-concat](/docs/guide/usage/linter/rules/eslint/no-useless-concat.html) | eslint | | |
| [no-useless-constructor](/docs/guide/usage/linter/rules/eslint/no-useless-constructor.html) | eslint | | 🛠️ |
| [preserve-caught-error](/docs/guide/usage/linter/rules/eslint/preserve-caught-error.html) | eslint | | 🚧 |
| [no-absolute-path](/docs/guide/usage/linter/rules/import/no-absolute-path.html) | import | | 🚧 |
| [no-empty-named-blocks](/docs/guide/usage/linter/rules/import/no-empty-named-blocks.html) | import | | 🛠️ |
| [no-named-as-default](/docs/guide/usage/linter/rules/import/no-named-as-default.html) | import | | |
Expand Down Expand Up @@ -462,7 +464,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 (157):
## Style (158):

Code that should be written in a more idiomatic way.

Expand Down Expand Up @@ -495,6 +497,7 @@ Code that should be written in a more idiomatic way.
| [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 | | |
| [no-useless-computed-key](/docs/guide/usage/linter/rules/eslint/no-useless-computed-key.html) | eslint | | 🚧 |
| [operator-assignment](/docs/guide/usage/linter/rules/eslint/operator-assignment.html) | eslint | | ⚠️🛠️️ |
| [prefer-destructuring](/docs/guide/usage/linter/rules/eslint/prefer-destructuring.html) | eslint | | 🚧 |
| [prefer-exponentiation-operator](/docs/guide/usage/linter/rules/eslint/prefer-exponentiation-operator.html) | eslint | | |
Expand Down
73 changes: 73 additions & 0 deletions src/docs/guide/usage/linter/rules/eslint/class-methods-use-this.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!-- 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/eslint/class_methods_use_this.rs`;
</script>

# eslint/class-methods-use-this <Badge type="info" text="Restriction" />

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

### What it does

Enforce that class methods utilize this.

### Examples

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

```js
class A {
foo() {
console.log("Hello World");
}
}
```

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

```js
class A {
foo() {
this.bar = "Hello World"; // OK, this is used
}
}

class B {
constructor() {
// OK. constructor is exempt
}
}

class C {
static foo() {
// OK. static methods aren't expected to use this.
}
}
```

## How to use

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

::: code-group

```bash [CLI]
oxlint --deny class-methods-use-this
```

```json [Config (.oxlintrc.json)]
{
"rules": {
"class-methods-use-this": "error"
}
}
```

:::

## References

- <a v-bind:href="source" target="_blank" rel="noreferrer">Rule Source</a>
171 changes: 139 additions & 32 deletions src/docs/guide/usage/linter/rules/eslint/func-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,173 @@ Require or disallow named function expressions.

Leaving the name off a function will cause `<anonymous>` to appear in
stack traces of errors thrown in it or any function called within it.
This makes it more difficult to find where an error is thrown. If you
provide the optional name for a function expression then you will get
the name of the function expression in the stack trace.
This makes it more difficult to find where an error is thrown.
Providing an explicit name also improves readability and consistency.

## Configuration
### Options

This rule has a string option:
First option:

- `"always"` requires a function expression to have a name under all
circumstances.
- `"as-needed"` requires a function expression to have a name only when
one will not be automatically inferred by the runtime.
- `"never"` requires a function expression to not have a name under any
circumstances.
- Type: `string`
- Default: `"always"`
- Possible values:
- `"always"` - requires all function expressions to have a name.
- `"as-needed"` - requires a name only if one is not automatically inferred.
- `"never"` - disallows names for function expressions.

Second option:

- Type: `object`
- Properties:
- `generators`: `("always" | "as-needed" | "never")` (default: falls back to first option)
- `"always"` - require named generator function expressions.
- `"as-needed"` - require a name only when not inferred.
- `"never"` - disallow names for generator function expressions.

Example configuration:

```json
{
"func-names": ["error", "as-needed", { "generators": "never" }]
}
```

### Examples

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

```javascript
/*oxlint func-names: "error" */
```js
/* func-names: ["error", "always"] */

// default is "always" and there is an anonymous function
Foo.prototype.bar = function() {};
const cat = { meow: function() {} };
(function() {/* ... */})();
export default function() {}
```

/*oxlint func-names: ["error", "always"] */
Examples of **correct** code for this rule:

// there is an anonymous function
Foo.prototype.bar = function() {};
```js
/* func-names: ["error", "always"] */

Foo.prototype.bar = function bar() {};
const cat = { meow() {} };
(function bar() {/* ... */})();
export default function foo() {}
```

#### `as-needed`

Examples of **incorrect** code for this rule with the `"as-needed"` option:

/*oxlint func-names: ["error", "as-needed"] */
```js
/* func-names: ["error", "as-needed"] */

// there is an anonymous function
// where the name isn’t assigned automatically per the ECMAScript specs
Foo.prototype.bar = function() {};
(function() {/* ... */})();
export default function() {}
```

/*oxlint func-names: ["error", "never"] */
Examples of **correct** code for this rule with the `"as-needed"` option:

// there is a named function
Foo.prototype.bar = function bar() {};
```js
/* func-names: ["error", "as-needed"] */

const bar = function() {};
const cat = { meow: function() {} };
class C {
#bar = function() {};
baz = function() {};
}
quux ??= function() {};
(function bar() {/* ... */})();
export default function foo() {}
```

Examples of *_correct_ code for this rule:
#### `never`

```javascript
/*oxlint func-names: "error" */
Examples of **incorrect** code for this rule with the `"never"` option:

```js
/* func-names: ["error", "never"] */

Foo.prototype.bar = function bar() {};
(function bar() {/* ... */})();
```

/*oxlint func-names: ["error", "always"] */
Examples of **correct** code for this rule with the `"never"` option:

Foo.prototype.bar = function bar() {};
```js
/* func-names: ["error", "never"] */

/*oxlint func-names: ["error", "as-needed"] */
Foo.prototype.bar = function() {};
(function() {/* ... */})();
```

var foo = function() {};
#### `generators`

/*oxlint func-names: ["error", "never"] */
Examples of **incorrect** code for this rule with the `"always", { "generators": "as-needed" }` options:

Foo.prototype.bar = function() {};
```js
/* func-names: ["error", "always", { "generators": "as-needed" }] */

(function*() {/* ... */})();
```

Examples of **correct** code for this rule with the `"always", { "generators": "as-needed" }` options:

```js
/* func-names: ["error", "always", { "generators": "as-needed" }] */

const foo = function*() {};
```

Examples of **incorrect** code for this rule with the `"always", { "generators": "never" }` options:

```js
/* func-names: ["error", "always", { "generators": "never" }] */

const foo = bar(function* baz() {});
```

Examples of **correct** code for this rule with the `"always", { "generators": "never" }` options:

```js
/* func-names: ["error", "always", { "generators": "never" }] */

const foo = bar(function*() {});
```

Examples of **incorrect** code for this rule with the `"as-needed", { "generators": "never" }` options:

```js
/* func-names: ["error", "as-needed", { "generators": "never" }] */

const foo = bar(function* baz() {});
```

Examples of **correct** code for this rule with the `"as-needed", { "generators": "never" }` options:

```js
/* func-names: ["error", "as-needed", { "generators": "never" }] */

const foo = bar(function*() {});
```

Examples of **incorrect** code for this rule with the `"never", { "generators": "always" }` options:

```js
/* func-names: ["error", "never", { "generators": "always" }] */

const foo = bar(function*() {});
```

Examples of **correct** code for this rule with the `"never", { "generators": "always" }` options:

```js
/* func-names: ["error", "never", { "generators": "always" }] */

const foo = bar(function* baz() {});
```

## How to use
Expand Down
Loading