# Linting

> Lint JavaScript and TypeScript with Bun's embedded oxlint engine

`bun lint` lints JavaScript and TypeScript with Bun's embedded native quality engine. Run [`bun n2b`](https://aphrody.app/docs/runtime/n2b) for Node.js-to-Bun migration findings.

```bash terminal icon="terminal"
bun lint
```

```txt
src/index.ts:3:7 warning eslint(no-unused-vars) Variable 'x' is declared but never used.
```

`bun lint` exits with code `1` if it finds an error, and `0` otherwise. Pass `--deny-warnings` to fail on warnings too.

With no paths, Bun lints the working directory. Pass files or directories to lint only those.

```bash terminal icon="terminal"
bun lint src test
```

## Embedded engine

Linting runs directly inside Bun. It does not resolve a project executable, install an npm package or launch a linter subprocess. `BUN_OXLINT`, `BUN_OXFMT` and `BUN_N2B` do not select a backend. `--external-backend` is an unsupported option; after `--`, it is a literal filesystem operand.

Unsupported options and JavaScript plugins fail explicitly. The engine's source and version are fixed by the Bun binary.

## Fix problems

`--fix` applies safe lint fixes. Use `bun n2b --fix` for migration rewrites.

```bash terminal icon="terminal"
bun lint --fix
```

## Output formats

`--format` selects `default`, `json` or `github` diagnostics. Migration findings have their own `bun n2b --report=json` report.

```bash terminal icon="terminal"
bun lint --format=json > lint.json
```

In Oxlint mode with no target files, JSON and XML reporters emit a valid empty document and
put the no-files notice on standard error. Unix output keeps that notice on
standard output. The no-target error exits with code `1`, including with
`--silent`; silencing findings does not hide this failure.

## Native type information

`--type-aware` or `options.typeAware = true` enables rules such as
`typescript/no-floating-promises` through Bun's native type owner. With an
Oxlint configuration, those rules are skipped when type-aware linting is off.
`--type-check` or `options.typeCheck = true` additionally reports TypeScript
errors and requires type-aware linting. Neither option selects an external
checker or linter backend.

## Configure

`bun lint` reads `.oxlintrc.json` the same way oxlint does. See the [oxlint configuration reference](https://oxc.rs/docs/guide/usage/linter/config) for rules, plugins and overrides.

```json .oxlintrc.json icon="file-json"
{
  "plugins": ["typescript", "unicorn", "import"],
  "rules": {
    "no-console": "warn"
  },
  "ignorePatterns": ["dist/**"]
}
```

`--config` selects an explicit JSON/JSONC configuration. `--ignore-pattern` excludes matching paths. Discovery respects Gitignore and prunes generated dependency directories and protected stores.

## Flags

| Flag                   | Description                                                                 |
| ---------------------- | --------------------------------------------------------------------------- |
| `--fix`                | Apply safe fixes                                                            |
| `--format`            | Reporter: `default`, `json` or `github`                                       |
| `-c`, `--config=<path>` | oxlint configuration file                                                  |
| `--ignore-pattern`    | Exclude matching paths                                                     |
| `--no-n2b`            | Accepted for compatibility; native lint runs quality rules only              |
| `--deny-warnings`      | Exit with code `1` on warnings                                              |

Other options fail explicitly. Workspace selection and Git-ref selection are not provided by this command.

## `package.json` scripts

`bun lint` always selects the native command. Use `bun run lint` to run a project's `lint` script:

```json package.json icon="file-json"
{
  "scripts": {
    "lint": "bun lint --deny-warnings"
  }
}
```

To format code, use [`bun fmt`](https://aphrody.app/docs/runtime/fmt).
