diff --git a/src/docs/guide/usage/linter/generated-cli.md b/src/docs/guide/usage/linter/generated-cli.md index dddefb237e6..7fc783d5701 100644 --- a/src/docs/guide/usage/linter/generated-cli.md +++ b/src/docs/guide/usage/linter/generated-cli.md @@ -95,6 +95,9 @@ Arguments: - **`--no-ignore`** — Disables excluding of files from .eslintignore files, **`--ignore-path`** flags and **`--ignore-pattern`** flags +> [!NOTE] +> `.gitignore` is only respected inside a Git repository. + ## Handle Warnings - **`--quiet`** — diff --git a/src/docs/guide/usage/linter/generated-rules.md b/src/docs/guide/usage/linter/generated-rules.md index 3ef9301d352..4ec5462b6d1 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: 605 +- Total number of rules: 607 - Rules turned on by default: 103 **Legend for 'Fixable?' column:** @@ -235,7 +235,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 (75): +## Restriction (77): 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. @@ -273,6 +273,7 @@ Lints which prevent the use of language and library features. Must not be enable | [empty-tags](/docs/guide/usage/linter/rules/jsdoc/empty-tags.html) | jsdoc | | | | [anchor-ambiguous-text](/docs/guide/usage/linter/rules/jsx_a11y/anchor-ambiguous-text.html) | jsx_a11y | | | | [no-new-require](/docs/guide/usage/linter/rules/node/no-new-require.html) | node | | | +| [no-process-env](/docs/guide/usage/linter/rules/node/no-process-env.html) | node | | | | [bad-bitwise-operator](/docs/guide/usage/linter/rules/oxc/bad-bitwise-operator.html) | oxc | | | | [no-async-await](/docs/guide/usage/linter/rules/oxc/no-async-await.html) | oxc | | | | [no-barrel-file](/docs/guide/usage/linter/rules/oxc/no-barrel-file.html) | oxc | | | @@ -286,6 +287,7 @@ Lints which prevent the use of language and library features. Must not be enable | [jsx-filename-extension](/docs/guide/usage/linter/rules/react/jsx-filename-extension.html) | react | | đźš§ | | [no-danger](/docs/guide/usage/linter/rules/react/no-danger.html) | react | | | | [no-unknown-property](/docs/guide/usage/linter/rules/react/no-unknown-property.html) | react | | đźš§ | +| [only-export-components](/docs/guide/usage/linter/rules/react/only-export-components.html) | react | | | | [explicit-function-return-type](/docs/guide/usage/linter/rules/typescript/explicit-function-return-type.html) | typescript | | | | [explicit-module-boundary-types](/docs/guide/usage/linter/rules/typescript/explicit-module-boundary-types.html) | typescript | | | | [no-dynamic-delete](/docs/guide/usage/linter/rules/typescript/no-dynamic-delete.html) | typescript | | | diff --git a/src/docs/guide/usage/linter/rules/eslint/no-duplicate-imports.md b/src/docs/guide/usage/linter/rules/eslint/no-duplicate-imports.md index 914b6b9e63e..61651b8a6e1 100644 --- a/src/docs/guide/usage/linter/rules/eslint/no-duplicate-imports.md +++ b/src/docs/guide/usage/linter/rules/eslint/no-duplicate-imports.md @@ -81,6 +81,26 @@ export * as something from "module"; export * from "module"; ``` +#### allowSeparateTypeImports + +`{ type: boolean, default: false }` + +When `true`, imports with only type specifiers (inline types or type imports) are +considered separate from imports with value specifiers, so they can be imported from the +same module on separate import statements. + +Examples of **correct** code when `allowSeparateTypeImports` is set to `true`: + +```js +import { foo } from "module"; +import type { Bar } from "module"; +``` + +```js +import { type Foo } from "module"; +import type { Bar } from "module"; +``` + ## How to use To **enable** this rule in the CLI or using the config file, you can use: diff --git a/src/docs/guide/usage/linter/rules/nextjs/no-typos.md b/src/docs/guide/usage/linter/rules/nextjs/no-typos.md index 1c476f0e826..cfe7d030492 100644 --- a/src/docs/guide/usage/linter/rules/nextjs/no-typos.md +++ b/src/docs/guide/usage/linter/rules/nextjs/no-typos.md @@ -15,10 +15,12 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin ### What it does -Prevent common typos in Next.js's data fetching functions +Detects common typos in Next.js data fetching function names. ### Why is this bad? +Next.js will not call incorrectly named data fetching functions, causing pages to render without expected data. + ### Examples Examples of **incorrect** code for this rule: diff --git a/src/docs/guide/usage/linter/rules/node/no-process-env.md b/src/docs/guide/usage/linter/rules/node/no-process-env.md new file mode 100644 index 00000000000..f3cf53c288c --- /dev/null +++ b/src/docs/guide/usage/linter/rules/node/no-process-env.md @@ -0,0 +1,71 @@ + + + + +# node/no-process-env + +
+
+ +### What it does + +Disallows use of `process.env`. + +### Why is this bad? + +Directly reading `process.env` can lead to implicit runtime configuration, +make code harder to test, and bypass configuration validation. + +### Examples + +Examples of **incorrect** code for this rule: + +```js +if (process.env.NODE_ENV === "development") { + // ... +} +``` + +Examples of **correct** code for this rule: + +```js +import config from "./config"; + +if (config.env === "development") { + // ... +} +``` + +## Configuration + +### allowedVariables + +type: `string[]` + +## How to use + +To **enable** this rule in the CLI or using the config file, you can use: + +::: code-group + +```bash [CLI] +oxlint --deny node/no-process-env --node-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["node"], + "rules": { + "node/no-process-env": "error" + } +} +``` + +::: + +## References + +- Rule Source diff --git a/src/docs/guide/usage/linter/rules/oxc/branches-sharing-code.md b/src/docs/guide/usage/linter/rules/oxc/branches-sharing-code.md index 3971e511ced..10cfa596fd6 100644 --- a/src/docs/guide/usage/linter/rules/oxc/branches-sharing-code.md +++ b/src/docs/guide/usage/linter/rules/oxc/branches-sharing-code.md @@ -24,20 +24,20 @@ and easier to maintain. Examples of **incorrect** code for this rule: ```javascript -let foo = if (condition) { - console.log("Hello"); - 13 +if (condition) { + console.log("Hello"); + return 13; } else { - console.log("Hello"); - 42 -}; + console.log("Hello"); + return 42; +} if (condition) { - doSomething(); - cleanup(); + doSomething(); + cleanup(); } else { - doSomethingElse(); - cleanup(); + doSomethingElse(); + cleanup(); } ``` @@ -45,16 +45,16 @@ Examples of **correct** code for this rule: ```javascript console.log("Hello"); -let foo = if (condition) { - 13 +if (condition) { + return 13; } else { - 42 -}; + return 42; +} if (condition) { - doSomething(); + doSomething(); } else { - doSomethingElse(); + doSomethingElse(); } cleanup(); ``` diff --git a/src/docs/guide/usage/linter/rules/react/only-export-components.md b/src/docs/guide/usage/linter/rules/react/only-export-components.md new file mode 100644 index 00000000000..d7868d49b71 --- /dev/null +++ b/src/docs/guide/usage/linter/rules/react/only-export-components.md @@ -0,0 +1,181 @@ + + + + +# react/only-export-components + +
+
+ +### What it does + +Ensures that modules only **export React components (and related HMR-safe items)** so +that Fast Refresh (a.k.a. hot reloading) can safely preserve component state. +Concretely, it validates the shape of your module’s exports and common entrypoints +(e.g. `createRoot(...).render()`) to match what integrations like +`react-refresh` expect. The rule name is `react-refresh/only-export-components`. + +### Why is this bad? + +Fast Refresh can only reliably retain state if a module exports components and +avoids patterns that confuse the refresh runtime. Problematic patterns (like +`export *`, anonymous default functions, exporting arrays of JSX, or mixing +non-component exports in unsupported ways) can cause: + +- Components to remount and lose state on edit +- Missed updates (no refresh) or overly broad reloads +- Fragile HMR behavior that differs between bundlers + +By enforcing predictable exports, edits stay fast and stateful during development. + +### Examples + +Examples of **incorrect** code for this rule: + +```jsx +// 1) Mixing util exports with components in unsupported ways +export const foo = () => {}; // util, not a component +export const Bar = () => <>; // component +``` + +```jsx +// 2) Anonymous default export (name is required) +export default function() {} +``` + +```jsx +// 3) Re-exporting everything hides what’s exported +export * from "./foo"; +``` + +```jsx +// 4) Exporting JSX collections makes components non-discoverable +const Tab = () => null; +export const tabs = [, ]; +``` + +```jsx +// 5) Bootstrapping a root within the same module that defines components +const App = () => null; +createRoot(document.getElementById("root")).render(); +``` + +Examples of **correct** code for this rule: + +```jsx +// Named or default component exports are fine +export default function Foo() { + return null; +} +``` + +```jsx +// Utilities may coexist if allowed by options or naming conventions +const foo = () => {}; +export const Bar = () => null; +``` + +```jsx +// Entrypoint files may render an imported component +import { App } from "./App"; +createRoot(document.getElementById("root")).render(); +``` + +### Options (or not) + +#### allowExportNames + +`{ type: string[], default: [] }` + +Treat specific named exports as HMR-safe (useful for frameworks that hot-replace +certain exports). For example, in Remix: + +```json +{ + "react/only-export-components": [ + "error", + { "allowExportNames": ["meta", "links", "headers", "loader", "action"] } + ] +} +``` + +#### allowConstantExport + +`{ type: boolean, default: false }` + +Allow exporting primitive constants (string/number/boolean/template literal) +alongside component exports without triggering a violation. Recommended when your +bundler’s Fast Refresh integration supports this (enabled by the plugin’s `vite` +preset). + +```json +{ + "react/only-export-components": [ + "error", + { "allowConstantExport": true } + ] +} +``` + +```jsx +// Allowed when allowConstantExport: true +export const VERSION = "3"; +export const Foo = () => null; +``` + +#### customHOCs + +`{ type: string[], default: [] }` + +If you export components wrapped in custom higher-order components, list their +identifiers here to avoid false positives: + +```json +{ + "react/only-export-components": [ + "error", + { "customHOCs": ["observer", "withAuth"] } + ] +} +``` + +#### checkJS + +`{ type: boolean, default: false }` + +Check `.js` files that contain JSX (in addition to `.tsx`/`.jsx`). To reduce +false positives, only files that import React are checked when this is enabled. + +```json +{ + "react/only-export-components": ["error", { "checkJS": true }] +} +``` + +## 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/only-export-components --react-plugin +``` + +```json [Config (.oxlintrc.json)] +{ + "plugins": ["react"], + "rules": { + "react/only-export-components": "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 dbe26346673..c43a2b0a5d7 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 "5c29bb65e7d20e682ff27e534332b3489a344954"; + return "6440cde67502bdc72020a1b8992b5445b7b490f3"; }, };