Skip to content

Linter

Biome’s linter statically analyzes your code to catch common errors and to help writing idiomatic code.

Biome's linter has a total of 209 rules

You can start by running the CLI to check for possible errors using the following command:

Terminal window
biome lint ./src

For more information about all the available options, check the CLI page

We believe that rules should be informative and explain to the user why a rule is triggered and tell the user what they should to do fix the error. A rule should follow these pillars:

  1. Explain to the user the error. Generally, this is the message of the diagnostic.
  2. Explain to the user why the error is triggered. Generally, this is implemented with an additional node.
  3. Tell the user what they should do. Generally, this is implemented using a code action. If a code action is not applicable a note should tell the user what they should do to fix the error.

If you think a rule doesn’t follow these pillars, please file an issue.

Lint rules may provide automatic code fixes. Biome distinguishes between two types of fixes.

Safe fixes are guaranteed to not change the semantic of your code. They can be applied without explicit review.

To apply safe fixes, use --apply:

Terminal window
biome check --apply ./src

Unsafe fixes may change the semantic of your program. Therefore, it’s advised to manually review the changes.

To apply unsafe fixes, use --apply-unsafe:

Terminal window
biome check --apply-unsafe ./src

When the linter is enabled, it recommends a number of rules. Recommended rules will emit error diagnostics. Below the list of recommended rules:

There are times when a developer wants to ignore a lint rule for a specific line of the code. You can achieve this by adding a suppression comment above the line that emits the lint diagnostic.

Suppression comments have the following format:

// biome-ignore lint: <explanation>
// biome-ignore lint/suspicious/noDebugger: <explanation>

Where

  • biome-ignore is the start of a suppression comment;
  • lint suppresses the linter;
  • /suspicious/noDebugger: optional, group and name of the rule you want to suppress;
  • <explanation> explanation why the rule is disabled

Here’s an example:

// biome-ignore lint: reason
debugger;
// biome-ignore lint/suspicious/noDebugger: reason
debugger;

Recommended rules are enabled by default and emit diagnostics with the error severity. Rules that are not recommended are disabled by default, but they can be enabled via configuration. The diagnostics emitted by these rules are displayed with the warning severity in the documentation.

To enable rules, you need to change their diagnostic severity based on your needs:

biome.json
{
"linter": {
"enabled": true,
"rules": {
"style": {
"useBlockStatements": "error",
"useShorthandArrayType": "error",
"noShoutyConstants": "warn"
}
}
}
}

Just add "off" as value inside its configuration. For example:

biome.json
{
"linter": {
"enabled": true,
"rules": {
"suspicious": {
"noCommentText": "off"
},
"style": {
"noUnusedTemplateLiteral": "off"
}
}
}
}

Change the diagnostic severity

Section titled Change the diagnostic severity

Most of Biome’s rules will emit an error, but you are free to change their severity. Just add "warn" as value of the rule. Example:

biome.json
{
"linter": {
"enabled": true,
"rules": {
"suspicious": {
"noCommentText": "warn"
}
}
}
}

This is useful in cases there’s being a refactor going on and there’s need to make the CI passing.

A few rules have options. When they do accept some, you can pass them by shaping the value of the rule differently.

biome.json
{
"linter": {
"enabled": true,
"rules": {
"correctness": {
"noCommentText": {
"level": "warn",
"options": {}
}
}
}
}
}
  • level will indicate the severity of the diagnostic, valid values are: "off", "warn" and "error";
  • options will change based on the rule.

Many of Biome lint rules are inspired from other linters. If you want to migrate from other linters such as ESLint or typescript-eslint, check the rules sources page