网页
综合
更新时间 2026-11-16 08:41:25
Linter | Bun Docs
自动蜘蛛
bun.sh
正文约 4950 字
Bun's fast, built-in linter for JavaScript, TypeScript, and JSX
Bun ships with a fast, built-in linter. There's nothing to install and nothing to configure.
bun lint checks every .js, .jsx, .ts, and .tsx file in the current directory (plus the .mjs, .cjs, .mts, .cts variants). It skips node_modules and anything in your .gitignore or .git/info/exclude.
To lint specific files, pass paths or globs.
An argument that starts with ! leaves files out of what the other arguments select, as it does for bun fmt. This holds with an ESLint or oxlint config too.
The exit code is 1 if there are errors and 0 if there are only warnings.
Many rules can fix what they report. --fix applies those fixes and writes the files.
--fix is for changes that keep what your program does and keep your comments. Where a rule's fix is known to alter behavior or drop a comment, the problem is still reported, but only --fix-suggestions or --fix-dangerously applies the fix, even if ESLint or oxlint apply it with --fix. Each rule's page says which flag it needs.
With no config, bun lint turns on the rules that catch real bugs:
Likely bugs are errors. Unused code, style suggestions, and code that people often write on purpose, like while (match = re.exec(text)), are warnings. A warning doesn't fail the run.
A few defaults differ from ESLint's, so that ordinary code isn't reported:
Each rule's page says what differs and how to change it.
Rules live in bunfig.toml. Every built-in rule works the same way, with nothing to install. The exceptions are the rules for JSON and Markdown, which need an ESLint config.
An option you don't set keeps its default.
To create the section, run bun lint --init.
A typo is an error, not a silent no-op:
Browse all rules, or look one up from the terminal. In most terminals you can also click the rule name in a report.
Need a rule that isn't built in? Load any ESLint plugin, from npm or your own. The default rules stay on.
Categories switch on many rules at once: correctness, suspicious, pedantic, perf, style, restriction, nursery.
A category includes the React, Next.js, Jest and Vitest rules only if your package.json lists that package. See lint.categories.
Use * as the rule name to turn off every rule of a plugin. A setting for a single rule overrides it.
The patterns use .gitignore syntax and are relative to bunfig.toml. With an eslint.config.* file they're ESLint ignores instead.
bun lint works out whether a file is an ES module or CommonJS from the file itself, the way Node.js does:
A CommonJS file can return at the top level, and it's only in strict mode if it starts with "use strict".
To decide for every file yourself, set sourceType to "module", "commonjs" or "script":
Next to an eslint.config.js, ESLint's defaults apply instead: .js and .mjs files are modules and .cjs files are CommonJS, unless languageOptions.sourceType says otherwise.
bun lint uses ESLint's comments, so existing ones keep working. oxlint's oxlint-disable comments mean the same, except next to an ESLint config, where they are ordinary comments as in ESLint.
A comment that no longer disables anything gets a warning, and --fix removes it.
Some bugs only show up with types, like a promise nobody awaits. --type-aware turns on the recommended rules that use them.
Types come from bun check, Bun's built-in type checker. It's slower than a plain run, because your code is type checked first. To make it the default:
Only want one of them? Turn it on like any other rule. You don't need typeAware.
To report type errors too, like bun check does, set typeCheck = true or pass --type-check.
Each file is type checked with the tsconfig.json your editor would use for it. To use one tsconfig.json for the whole run, pass --tsconfig.
A tsconfig.json without "include" covers every file below it. At the root of a monorepo, that can mean loading the whole repository to lint one package. Bun warns you when that happens.
With an oxlint config, --tsconfig does what it does in oxlint. It sets the tsconfig.json that the import rules resolve imports with, for its paths. It doesn't change which tsconfig.json a file is type checked with, so the warning only suggests "include".
--staged lints only the files you're about to commit, so you don't need lint-staged.
If a file has both staged and unstaged changes, Bun lints the staged version, which is what the commit gets. --fix doesn't write such a file, because staging it again would commit the rest. If it has something to fix, Bun names the file and exits with code 2.
The same goes for the files that a staged file imports, which the type-aware rules and the import rules read. A file you staged and then deleted is still linted. Config files, such as bunfig.toml and eslint.config.js, are read from disk.
--changed lints the files that differ from your default branch. Pass a ref to compare with something else.
In GitHub Actions, bun lint annotates the pull request diff automatically.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。