Ir al contenido

Linter

Esta página aún no está disponible en tu idioma.

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.

Run the lint command from the root of your project:

npx biome lint

Biome 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.

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.

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

In your editor, you can apply safe fixes every time you save a file. See Set up your editor.

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

Editors never apply unsafe fixes on save, but they offer them as quick fixes that you can apply one at a time.

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.

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.

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.

Set a rule to "on" to enable it with its default severity. This is how you turn on rules that are not recommended:

biome.json
{
"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:

biome.json
{
"linter": {
"rules": {
"preset": "none",
"suspicious": {
"noDebugger": "on"
}
}
}
}

Set a rule to "off" to disable it:

biome.json
{
"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:

biome.json
{
"linter": {
"rules": {
"a11y": "off"
}
}
}

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.
biome.json
{
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "warn"
}
}
}
}

You can also set the severity of a whole group, such as "style": "warn".

Some rules accept options. To set them, replace the severity with an object that has a level and an options field:

biome.json
{
"linter": {
"rules": {
"style": {
"useNamingConvention": {
"level": "error",
"options": {
"strictCase": false
}
}
}
}
}
}

The documentation page of each rule lists the options it supports.

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 --write and on save.
  • "unsafe": treat the fix as unsafe, so it only applies with --write --unsafe.
  • "none": do not offer a fix.
biome.jsonc
{
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": {
"level": "error",
"fix": "none" // only report unused variables
}
},
"style": {
"useTemplate": {
"level": "warn",
"fix": "safe" // fix string concatenation on save
}
}
}
}
}

To configure rules differently for some files, use overrides. For example, tests often need looser rules than the rest of your code:

biome.json
{
"overrides": [
{
"includes": ["**/*.test.ts"],
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "off"
}
}
}
}
]
}

To focus on specific problems, pass --only to run nothing but the given rules, groups, or domains:

Terminal window
biome lint --only=suspicious/noDebugger --only=a11y

Or pass --skip to run everything except them:

Terminal window
biome lint --skip=style --skip=suspicious/noExplicitAny

If a rule you pass to --only is disabled in your configuration, Biome runs it anyway.

To skip files that you do not want linted, such as generated code, exclude them with linter.includes:

biome.json
{
"linter": {
"includes": ["**", "!**/generated/**"]
}
}

The formatter and the other tools still process these files. To exclude a file from every tool, use files.includes instead.

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:

biome.json
{
"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.

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:

biome.json
{
"linter": {
"domains": {
"react": "all",
"test": "none"
}
}
}

The Domains page lists every domain, the dependencies that enable it, and the rules it contains.

If a rule reports code that is correct in your case, add a suppression comment above it, with a reason:

example.js
// biome-ignore lint/suspicious/noDebugger: needed to inspect the parser state
debugger;

The Suppressions guide covers every way to write these comments.

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.