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
3 changes: 3 additions & 0 deletions src/docs/guide/usage/linter/generated-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`** —
Expand Down
6 changes: 4 additions & 2 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: 605
- Total number of rules: 607
- Rules turned on by default: 103

**Legend for 'Fixable?' column:**
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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 | | |
Expand All @@ -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 | | |
Expand Down
20 changes: 20 additions & 0 deletions src/docs/guide/usage/linter/rules/eslint/no-duplicate-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/docs/guide/usage/linter/rules/nextjs/no-typos.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
71 changes: 71 additions & 0 deletions src/docs/guide/usage/linter/rules/node/no-process-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!-- 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/node/no_process_env.rs`;
</script>

# node/no-process-env <Badge type="info" text="Restriction" />

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

### 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

- <a v-bind:href="source" target="_blank" rel="noreferrer">Rule Source</a>
32 changes: 16 additions & 16 deletions src/docs/guide/usage/linter/rules/oxc/branches-sharing-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,37 @@ 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();
}
```

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();
```
Expand Down
181 changes: 181 additions & 0 deletions src/docs/guide/usage/linter/rules/react/only-export-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<!-- 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/react/only_export_components.rs`;
</script>

# react/only-export-components <Badge type="info" text="Restriction" />

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

### 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(<App />)`) 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 = [<Tab />, <Tab />];
```

```jsx
// 5) Bootstrapping a root within the same module that defines components
const App = () => null;
createRoot(document.getElementById("root")).render(<App />);
```

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(<App />);
```

### 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

- <a v-bind:href="source" target="_blank" rel="noreferrer">Rule Source</a>
2 changes: 1 addition & 1 deletion src/docs/guide/usage/linter/rules/version.data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default {
load() {
return "5c29bb65e7d20e682ff27e534332b3489a344954";
return "6440cde67502bdc72020a1b8992b5445b7b490f3";
},
};