Linter
Цей контент ще не доступний вашою мовою.
Biome’s linter finds bugs, risky patterns, and outdated code, and fixes many of them for you. It comes with 880 rules across all supported languages, and a recommended set of them is enabled out of the box. When no built-in rule covers a convention of your project, you can enforce it with a plugin.
Lint your files
Section titled “Lint your files”Run the lint command from the root of your project:
npx biome lintpnpm biome lintbunx biome lintdeno run -A npm:@biomejs/biome lintyarn biome lintbiome lintBiome reports each problem as a diagnostic that explains what is wrong, why it matters, and how to fix it. You can pass files and folders to lint only part of your project, such as biome lint ./src. To choose files with glob patterns, use linter.includes instead, because your shell expands the globs you pass.
To format, lint, and sort imports in a single pass, use biome check instead. See the CLI reference for every option of the lint command.
Fix problems automatically
Section titled “Fix problems automatically”Many rules come with a fix. Biome splits fixes into two kinds, depending on how confident it is that the fix keeps your code working the same way.
Safe fixes
Section titled “Safe fixes”A safe fix never changes what your code does, so you can apply it without reviewing it. Apply all safe fixes with --write:
npx biome lint --writepnpm biome lint --writebunx biome lint --writedeno run -A npm:@biomejs/biome lint --writeyarn biome lint --writebiome lint --writeIn your editor, you can apply safe fixes every time you save a file. See Set up your editor.
Unsafe fixes
Section titled “Unsafe fixes”An unsafe fix might change what your code does, so you should review it before keeping it. Apply both safe and unsafe fixes with --write --unsafe:
npx biome lint --write --unsafepnpm biome lint --write --unsafebunx biome lint --write --unsafedeno run -A npm:@biomejs/biome lint --write --unsafeyarn biome lint --write --unsafebiome lint --write --unsafeEditors never apply unsafe fixes on save, but they offer them as quick fixes that you can apply one at a time.
Rule groups
Section titled “Rule groups”Rules are organized into groups that describe what kind of problem they catch:
| Group | What its rules catch |
|---|---|
a11y |
Accessibility problems. |
complexity |
Code that is more complicated than it needs to be. |
correctness |
Code that is guaranteed to be wrong or useless. |
nursery |
Varies: these are new rules that are still being developed. See Nursery. |
performance |
Code that could run faster or use fewer resources. |
security |
Potential security flaws. |
style |
Inconsistent or non-idiomatic code. These rules emit warnings by default. |
suspicious |
Code that is likely to be wrong or unintended. |
Rule names also tell you what they do: rules that start with no forbid something, like noDebugger, and rules that start with use require something, like useConst.
Nursery
Section titled “Nursery”The nursery group holds new rules that might still have bugs or performance issues. On stable releases, you must enable them explicitly, even if they are marked as recommended. Once a rule is stable, it moves to another group.
Configure rules
Section titled “Configure rules”Every rule belongs to a group, and you configure it under that group in your biome.json file. The documentation page of each rule shows its group, its default severity, and whether it is recommended. Browse them all in the list of lint rules.
Enable a rule
Section titled “Enable a rule”Set a rule to "on" to enable it with its default severity. This is how you turn on rules that are not recommended:
{ "linter": { "rules": { "style": { "noShoutyConstants": "on" } } }}If you only want a handful of rules, start from an empty set with preset and enable the rules you need:
{ "linter": { "rules": { "preset": "none", "suspicious": { "noDebugger": "on" } } }}Disable a rule
Section titled “Disable a rule”Set a rule to "off" to disable it:
{ "linter": { "rules": { "suspicious": { "noDebugger": "off" } } }}To disable every rule of a group at once, set the group itself to "off". For example, a backend project might not need the accessibility rules:
{ "linter": { "rules": { "a11y": "off" } }}Change the severity
Section titled “Change the severity”Instead of "on", you can choose the severity of a rule’s diagnostics. The severity decides whether a violation fails your CI:
"error": the CLI exits with an error code. Use it for problems that must block a merge."warn": the CLI reports the problem but still succeeds, unless you pass--error-on-warnings."info": the CLI reports the problem and always succeeds, even with--error-on-warnings.
{ "linter": { "rules": { "suspicious": { "noExplicitAny": "warn" } } }}You can also set the severity of a whole group, such as "style": "warn".
Rule options
Section titled “Rule options”Some rules accept options. To set them, replace the severity with an object that has a level and an options field:
{ "linter": { "rules": { "style": { "useNamingConvention": { "level": "error", "options": { "strictCase": false } } } } }}The documentation page of each rule lists the options it supports.
Configure the code fix
Section titled “Configure the code fix”For rules that have a fix, you can change how it is applied with the fix field:
"safe": treat the fix as safe, so it applies with--writeand on save."unsafe": treat the fix as unsafe, so it only applies with--write --unsafe."none": do not offer a fix.
{ "linter": { "rules": { "correctness": { "noUnusedVariables": { "level": "error", "fix": "none" // only report unused variables } }, "style": { "useTemplate": { "level": "warn", "fix": "safe" // fix string concatenation on save } } } }}Lint some files differently
Section titled “Lint some files differently”To configure rules differently for some files, use overrides. For example, tests often need looser rules than the rest of your code:
{ "overrides": [ { "includes": ["**/*.test.ts"], "linter": { "rules": { "suspicious": { "noExplicitAny": "off" } } } } ]}Run only some rules
Section titled “Run only some rules”To focus on specific problems, pass --only to run nothing but the given rules, groups, or domains:
biome lint --only=suspicious/noDebugger --only=a11yOr pass --skip to run everything except them:
biome lint --skip=style --skip=suspicious/noExplicitAnyIf a rule you pass to --only is disabled in your configuration, Biome runs it anyway.
Lint only some files
Section titled “Lint only some files”To skip files that you do not want linted, such as generated code, exclude them with linter.includes:
{ "linter": { "includes": ["**", "!**/generated/**"] }}The formatter and the other tools still process these files. To exclude a file from every tool, use files.includes instead.
Disable the linter
Section titled “Disable the linter”If you want to keep another linter for now, such as ESLint, and only use Biome for formatting, disable Biome’s linter with linter.enabled:
{ "linter": { "enabled": false }}Biome then stops reporting lint diagnostics, both in the CLI and in your editor, while the formatter and assist actions keep working.
Enable rules for your stack
Section titled “Enable rules for your stack”Some rules only make sense for a particular framework or tool, such as React, Vue, or your test runner. Biome groups these rules into domains.
Biome enables the recommended rules of a domain automatically when it finds the matching dependency in your package.json. For example, if your project depends on vitest, Biome enables the recommended rules of the test domain.
You can also configure domains yourself. Set a domain to "recommended" to enable its recommended rules, to "all" to enable every rule in it, or to "none" to disable it:
{ "linter": { "domains": { "react": "all", "test": "none" } }}The Domains page lists every domain, the dependencies that enable it, and the rules it contains.
Ignore a rule in part of a file
Section titled “Ignore a rule in part of a file”If a rule reports code that is correct in your case, add a suppression comment above it, with a reason:
// biome-ignore lint/suspicious/noDebugger: needed to inspect the parser statedebugger;The Suppressions guide covers every way to write these comments.
Coming from ESLint
Section titled “Coming from ESLint”Most Biome rules are based on ESLint rules and popular ESLint plugins. To convert your ESLint configuration, follow the migration guide. To adopt Biome step by step, suppress the existing violations and fix them over time. To find the Biome equivalent of a rule, check the rule sources.
© 2023-present Biome developers and contributors.