diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index 4563068e18..bf165af6a6 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: 570 +- Total number of rules: 573 - Rules turned on by default: 103 **Legend for 'Fixable?' column:** @@ -308,7 +308,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 (39): +## Suspicious (40): code that is most likely wrong or useless. @@ -332,6 +332,7 @@ code that is most likely wrong or useless. | [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 | | | +| [always-return](/docs/guide/usage/linter/rules/promise/always-return.html) | promise | | | | [no-promise-in-callback](/docs/guide/usage/linter/rules/promise/no-promise-in-callback.html) | promise | | | | [iframe-missing-sandbox](/docs/guide/usage/linter/rules/react/iframe-missing-sandbox.html) | react | | 🚧 | | [jsx-no-comment-textnodes](/docs/guide/usage/linter/rules/react/jsx-no-comment-textnodes.html) | react | | | @@ -457,7 +458,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 (153): +## Style (155): Code that should be written in a more idiomatic way. @@ -533,6 +534,7 @@ Code that should be written in a more idiomatic way. | [no-test-prefixes](/docs/guide/usage/linter/rules/jest/no-test-prefixes.html) | jest | | 🛠️ | | [no-test-return-statement](/docs/guide/usage/linter/rules/jest/no-test-return-statement.html) | jest | | | | [no-untyped-mock-factory](/docs/guide/usage/linter/rules/jest/no-untyped-mock-factory.html) | jest | | 🛠️ | +| [padding-around-test-blocks](/docs/guide/usage/linter/rules/jest/padding-around-test-blocks.html) | jest | | 🛠️ | | [prefer-called-with](/docs/guide/usage/linter/rules/jest/prefer-called-with.html) | jest | | | | [prefer-comparison-matcher](/docs/guide/usage/linter/rules/jest/prefer-comparison-matcher.html) | jest | | 🛠️ | | [prefer-each](/docs/guide/usage/linter/rules/jest/prefer-each.html) | jest | | | @@ -562,6 +564,7 @@ Code that should be written in a more idiomatic way. | [jsx-boolean-value](/docs/guide/usage/linter/rules/react/jsx-boolean-value.html) | react | | 🛠️ | | [jsx-curly-brace-presence](/docs/guide/usage/linter/rules/react/jsx-curly-brace-presence.html) | react | | 🛠️ | | [jsx-fragments](/docs/guide/usage/linter/rules/react/jsx-fragments.html) | react | | 🛠️ | +| [jsx-handler-names](/docs/guide/usage/linter/rules/react/jsx-handler-names.html) | react | | | | [no-set-state](/docs/guide/usage/linter/rules/react/no-set-state.html) | react | | | | [prefer-es6-class](/docs/guide/usage/linter/rules/react/prefer-es6-class.html) | react | | | | [self-closing-comp](/docs/guide/usage/linter/rules/react/self-closing-comp.html) | react | | 🛠️ | diff --git a/src/docs/guide/usage/linter/rules/eslint/func-style.md b/src/docs/guide/usage/linter/rules/eslint/func-style.md index 4aa5547e43..ad4bee8348 100644 --- a/src/docs/guide/usage/linter/rules/eslint/func-style.md +++ b/src/docs/guide/usage/linter/rules/eslint/func-style.md @@ -24,20 +24,22 @@ You can specify which you prefer in the configuration. ### Examples +```js // function declaration function doSomething() { -// ... + // ... } // arrow function expression assigned to a variable const doSomethingElse = () => { -// ... + // ... }; // function expression assigned to a variable const doSomethingAgain = function() { -// ... + // ... }; +``` Examples of incorrect code for this rule with the default "expression" option: @@ -82,23 +84,25 @@ export var bar = () => {}; Examples of correct code for this rule with the default "expression" option: -````js +```js /*eslint func-style: ["error", "expression"]*/ var foo = function() { - // ... + // ... }; +``` Examples of correct code for this rule with the "declaration" option: + ```js /*eslint func-style: ["error", "declaration"]*/ function foo() { - // ... + // ... } - // Methods (functions assigned to objects) are not checked by this rule +// Methods (functions assigned to objects) are not checked by this rule SomeObject.foo = function() { - // ... + // ... }; -```` +``` Examples of additional correct code for this rule with the "declaration", { "allowArrowFunctions": true } options: diff --git a/src/docs/guide/usage/linter/rules/eslint/no-console.md b/src/docs/guide/usage/linter/rules/eslint/no-console.md index 90ff28ed48..86095351e5 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-console.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-console.md @@ -60,7 +60,7 @@ Example of **incorrect** code for this option: console.log("foo"); ``` -Example of **incorrect** code for this option: +Example of **correct** code for this option: ```javascript console.info("foo"); diff --git a/src/docs/guide/usage/linter/rules/jest/padding-around-test-blocks.md b/src/docs/guide/usage/linter/rules/jest/padding-around-test-blocks.md new file mode 100644 index 0000000000..df0711881d --- /dev/null +++ b/src/docs/guide/usage/linter/rules/jest/padding-around-test-blocks.md @@ -0,0 +1,77 @@ + + + + +# jest/padding-around-test-blocks + +
+ +🛠️ An auto-fix is available for this rule. + +
+ +### What it does + +This rule enforces a line of padding before and after 1 or more test/it statements + +### Examples + +Examples of **incorrect** code for this rule: + +```js +const thing = 123; +test("foo", () => {}); +test("bar", () => {}); +``` + +```js +const thing = 123; +it("foo", () => {}); +it("bar", () => {}); +``` + +Examples of **correct** code for this rule: + +```js +const thing = 123; + +test("foo", () => {}); + +test("bar", () => {}); +``` + +```js +const thing = 123; + +it("foo", () => {}); + +it("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 jest/padding-around-test-blocks --jest-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["jest"], + "rules": { + "jest/padding-around-test-blocks": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/promise/always-return.md b/src/docs/guide/usage/linter/rules/promise/always-return.md new file mode 100644 index 0000000000..cd6e2dc930 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/promise/always-return.md @@ -0,0 +1,170 @@ + + + + +# promise/always-return + +
+
+ +### What it does + +Require returning inside each `then()` to create readable and reusable Promise chains. +We also allow someone to throw inside a `then()` which is essentially the same as return `Promise.reject()`. + +### Why is this bad? + +Broken Promise Chain. +Inside the first `then()` callback, a function is called but not returned. +This causes the next `then()` in the chain to execute immediately without waiting for the called function to complete. + +### Examples + +Examples of **incorrect** code for this rule: + +```javascript +myPromise.then(function(val) {}); +myPromise.then(() => { + doSomething(); +}); +myPromise.then((b) => { + if (b) { + return "yes"; + } else { + forgotToReturn(); + } +}); +``` + +Examples of **correct** code for this rule: + +```javascript +myPromise.then((val) => val * 2); +myPromise.then(function(val) { + return val * 2; +}); +myPromise.then(doSomething); // could be either +myPromise.then((b) => { + if (b) { + return "yes"; + } else { + return "no"; + } +}); +``` + +### Options + +#### `ignoreLastCallback` + +You can pass an `{ ignoreLastCallback: true }` as an option to this rule so that +the last `then()` callback in a promise chain does not warn if it does not have +a `return`. Default is `false`. + +```javascript +// OK +promise.then((x) => { + console.log(x); +}); +// OK +void promise.then((x) => { + console.log(x); +}); +// OK +await promise.then((x) => { + console.log(x); +}); + +promise + // NG + .then((x) => { + console.log(x); + }) + // OK + .then((x) => { + console.log(x); + }); + +// NG +const v = promise.then((x) => { + console.log(x); +}); +// NG +const v = await promise.then((x) => { + console.log(x); +}); +function foo() { + // NG + return promise.then((x) => { + console.log(x); + }); +} +``` + +#### `ignoreAssignmentVariable` + +You can pass an `{ ignoreAssignmentVariable: [] }` as an option to this rule +with a list of variable names so that the last `then()` callback in a promise +chain does not warn if it does an assignment to a global variable. Default is +`["globalThis"]`. + +```javascript +/* eslint promise/always-return: ["error", { ignoreAssignmentVariable: ["globalThis"] }] */ + +// OK +promise.then((x) => { + globalThis = x; +}); + +promise.then((x) => { + globalThis.x = x; +}); + +// OK +promise.then((x) => { + globalThis.x.y = x; +}); + +// NG +promise.then((x) => { + anyOtherVariable = x; +}); + +// NG +promise.then((x) => { + anyOtherVariable.x = x; +}); + +// NG +promise.then((x) => { + x(); +}); +``` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny promise/always-return --promise-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["promise"], + "rules": { + "promise/always-return": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/react/jsx-handler-names.md b/src/docs/guide/usage/linter/rules/react/jsx-handler-names.md new file mode 100644 index 0000000000..c63c745af9 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/react/jsx-handler-names.md @@ -0,0 +1,85 @@ + + + + +# react/jsx-handler-names + +
+
+ +### What it does + +Ensures that any component or prop methods used to handle events are correctly prefixed. + +### Why is this bad? + +Inconsistent naming of event handlers and props can reduce code readability and maintainability. + +### Examples + +Examples of **incorrect** code for this rule: + +```jsx + + +``` + +Examples of **correct** code for this rule: + +```jsx + + +``` + +### Options + +```json +{ + "react/jsx-handler-names": [, { + "eventHandlerPrefix": , + "eventHandlerPropPrefix": , + "checkLocalVariables": , + "checkInlineFunction": , + "ignoreComponentNames": Array + }] +} +``` + +- `eventHandlerPrefix`: Prefix for component methods used as event handlers. + Defaults to `handle` +- `eventHandlerPropPrefix`: Prefix for props that are used as event handlers + Defaults to `on` +- `checkLocalVariables`: Determines whether event handlers stored as local variables + are checked. Defaults to `false` +- `checkInlineFunction`: Determines whether event handlers set as inline functions are + checked. Defaults to `false` +- `ignoreComponentNames`: Array of glob strings, when matched with component name, + ignores the rule on that component. Defaults to `[]` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny react/jsx-handler-names --react-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["react"], + "rules": { + "react/jsx-handler-names": "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 4581836798..8ad78bf3fd 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 "66a350eba5cadfa0df0fb9f90c848090531aadfc"; + return "6efb63a67ede0145468c83ff17217547d2e00ef8"; }, };