From 55ee367ada8734f0d4af9c5899e06905520d103e Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Tue, 16 Sep 2025 18:57:30 +0000 Subject: [PATCH] Release 1.16.0 --- .../guide/usage/linter/generated-rules.md | 11 +- .../rules/eslint/class-methods-use-this.md | 73 ++++++++ .../usage/linter/rules/eslint/func-names.md | 171 ++++++++++++++---- .../rules/eslint/no-useless-computed-key.md | 127 +++++++++++++ .../rules/eslint/preserve-caught-error.md | 78 ++++++++ .../guide/usage/linter/rules/version.data.js | 2 +- 6 files changed, 425 insertions(+), 37 deletions(-) create mode 100644 src/docs/guide/usage/linter/rules/eslint/class-methods-use-this.md create mode 100644 src/docs/guide/usage/linter/rules/eslint/no-useless-computed-key.md create mode 100644 src/docs/guide/usage/linter/rules/eslint/preserve-caught-error.md diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index 6878639abe6..31fe0e3c8cc 100644 --- a/src/docs/guide/usage/linter/generated-rules.md +++ b/src/docs/guide/usage/linter/generated-rules.md @@ -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:** @@ -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 | | | @@ -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. @@ -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 | | | @@ -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. @@ -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 | | | diff --git a/src/docs/guide/usage/linter/rules/eslint/class-methods-use-this.md b/src/docs/guide/usage/linter/rules/eslint/class-methods-use-this.md new file mode 100644 index 00000000000..f055ca6d421 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/eslint/class-methods-use-this.md @@ -0,0 +1,73 @@ + + + + +# eslint/class-methods-use-this + +
+
+ +### 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 + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/eslint/func-names.md b/src/docs/guide/usage/linter/rules/eslint/func-names.md index 7a118e6be0c..a3784d970ed 100644 --- a/src/docs/guide/usage/linter/rules/eslint/func-names.md +++ b/src/docs/guide/usage/linter/rules/eslint/func-names.md @@ -21,66 +21,173 @@ Require or disallow named function expressions. Leaving the name off a function will cause `` 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 diff --git a/src/docs/guide/usage/linter/rules/eslint/no-useless-computed-key.md b/src/docs/guide/usage/linter/rules/eslint/no-useless-computed-key.md new file mode 100644 index 00000000000..c1106b11ae4 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/eslint/no-useless-computed-key.md @@ -0,0 +1,127 @@ + + + + +# eslint/no-useless-computed-key + +
+ +๐Ÿšง An auto-fix is still under development. + +
+ +### What it does + +Disallow unnecessary computed property keys in objects and classes + +### Why is this bad? + +Itโ€™s unnecessary to use computed properties with literals such as: + +```js +const foo = { ["a"]: "b" }; +``` + +The code can be rewritten as: + +```js +const foo = { "a": "b" }; +``` + +### Examples + +Examples of **incorrect** code for this rule: + +```js +const a = { ["0"]: 0 }; +const b = { ["0+1,234"]: 0 }; +const c = { [0]: 0 }; +const e = { ["x"]() {} }; + +class Foo { + ["foo"] = "bar"; + [0]() {} + static ["foo"] = "bar"; + get ["b"]() {} + set ["c"](value) {} +} +``` + +Examples of **correct** code for this rule: + +```js +const a = { "a": 0 }; +const b = { 0: 0 }; +const c = { x() {} }; +const e = { "0+1,234": 0 }; + +class Foo { + "foo" = "bar"; + 0() {} + "a"() {} + static "foo" = "bar"; +} +``` + +Examples of additional **correct** code for this rule: + +```js +const c = { + "__proto__": foo, // defines object's prototype + ["__proto__"]: bar, // defines a property named "__proto__" +}; +class Foo { + ["constructor"]; // instance field named "constructor" + "constructor"() {} // the constructor of this class + static ["constructor"]; // static field named "constructor" + static ["prototype"]; // runtime error, it would be a parsing error without `[]` +} +``` + +### Options + +#### enforceForClassMembers + +`{ type: boolean, default: true }` + +The `enforceForClassMembers` option controls whether the rule applies to +class members (methods and properties). + +Examples of **correct** code for this rule with the `{ "enforceForClassMembers": false }` option: + +```js +class SomeClass { + ["foo"] = "bar"; + [42] = "baz"; + get ["b"]() {} + set ["c"](value) {} + static ["foo"] = "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 no-useless-computed-key +``` + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "no-useless-computed-key": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/eslint/preserve-caught-error.md b/src/docs/guide/usage/linter/rules/eslint/preserve-caught-error.md new file mode 100644 index 00000000000..ca4885bae4e --- /dev/null +++ b/src/docs/guide/usage/linter/rules/eslint/preserve-caught-error.md @@ -0,0 +1,78 @@ + + + + +# eslint/preserve-caught-error + +
+ +๐Ÿšง An auto-fix is still under development. + +
+ +### What it does + +Enforces that when re-throwing an error in a catch block, the original error +is preserved using the 'cause' property. + +### Why is this bad? + +Re-throwing an error without preserving the original error loses important +debugging information and makes it harder to trace the root cause of issues. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +try { + doSomething(); +} catch (err) { + throw new Error("Something failed"); +} +``` + +Examples of **correct** code for this rule: + +```js +try { + doSomething(); +} catch (err) { + throw new Error("Something failed", { cause: err }); +} +``` + +## Configuration + +This rule accepts a configuration object with the following properties: + +### requireCatchParameter + +type: `boolean` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny preserve-caught-error +``` + +```json [Config (.oxlintrc.json)] +{ + "rules": { + "preserve-caught-error": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/version.data.js b/src/docs/guide/usage/linter/rules/version.data.js index 5f3fa91285f..3c777689f19 100644 --- a/src/docs/guide/usage/linter/rules/version.data.js +++ b/src/docs/guide/usage/linter/rules/version.data.js @@ -1,5 +1,5 @@ export default { load() { - return "b20b56df4f00f5f03bc3bd3977725c52d43bbb91"; + return "a2c91cd5104af39a6b644e77879d3117c72b0ea6"; }, };