Linter
Ce contenu n’est pas encore disponible dans votre langue.
Biome’s linter statically analyzes your code to find and fix common errors and to help you write better, modern code. It supports multiple languages and provides a total of 300 rules.
Rules
Section titled RulesThe linter is organized into rules.
A rule emits a diagnostic when it encounters a code that doesn’t meet its requirements.
For example, the noDebugger rule reports the use of the debugger
instruction in JavaScript code.
A rule emits diagnostics with a info
, warn
or error
severity.
Diagnostics with an error
severity cause the command to exit with a non-zero code,
While diagnostics with a info
or a warn
severity don’t cause the command to fail.
You can cause a command that emits warn
diagnostics to fail by using the --error-on-warnings
option:
By default, the Biome linter only runs the recommended rules.
To disable all rules, you can disable the recommended rules in your Biome configuration file.
This may be useful in cases when you only want to enable a few rules.
The recommended rules emit diagnostics with the error
severity.
The rules are divided into groups.
For example, the noDebugger
rule is part of the suspicious
group.
Rules from this group detect code that is likely to be incorrect or useless.
The description of each group can be found on the rules page.
Unlike other linters, we don’t provide any rules that check for code formatting. This kind of checking is covered by our code formatter.
Many rules provide a code fix that can be automatically applied. Biome distinguishes between safe and unsafe code fixes.
Safe fixes
Section titled Safe fixesSafe fixes are guaranteed to not change the semantic of your code. They can be applied without explicit review.
To apply safe fixes, use --write
:
Unsafe fixes
Section titled Unsafe fixesUnsafe fixes may change the semantic of your program. Therefore, it’s advised to manually review the changes.
To apply both safe fixes and unsafe fixes, use --write --unsafe
:
Rule pillars
Section titled Rule pillarsWe 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:
- Explain to the user the error. Generally, this is the message of the diagnostic.
- Explain to the user why the error is triggered. Generally, this is implemented with an additional node.
- 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 open an issue.
The following command runs the linter on all files in the src
directory:
The command accepts a list of files and directories.
For more information about all the available options, check the CLI reference.
Skip a rule or a group
Section titled Skip a rule or a groupSince version v1.8.0, the command biome lint
accepts an option --skip
that allows to disable a rule or rules that belong to a group.
For example, the following command skips all the rules that belong to the style
group and the suspicious/noExplicitAny
rule:
Run a rule or a group
Section titled Run a rule or a groupSince version v1.8.0, the command biome lint
accepts an option --only
that allows you to run a single rule or the rules that belong to a group.
For example, the following command runs only the rulestyle/useNamingConvention
, the rule style/noInferrableTypes
and the rules that belong to a11y
. If the rule is disabled in the configuration, then its severity level is set to error
for a recommended rule or warn
otherwise.
Configuration
Section titled ConfigurationA rule can be configured based on your needs.
Disable a rule
Section titled Disable a ruleA rule is enabled whether its severity is error
, warn
or info
. You can turn off a rule with off
.
The following configuration disables the recommended noDebugger
rule and enables the noShoutyConstants
and useNamingConvention
rules.
The warn
severity is useful in cases where there’s a refactor going on and there’s a need to make the CI pass. The diagnostic message is yellow. You can use --error-on-warnings
to exit with an error code when a rule configured with warn
is triggered.
The info
severity won’t affect the exit status code of the CLI, even when --error-on-warnings
is passed. The diagnostic message color is blue.
Configure the rule fix
Section titled Configure the rule fixSince version v1.8.0, it’s possible to configure the entity of a fix, using the option fix
.
There are three options:
none
: the rule won’t emit a code fix;safe
: the rule will emit a safe fix;unsafe
: the rule will emit an unsafe fix;
Rule options
Section titled Rule optionsA few rules have options. You can set them by shaping the value of the rule differently.
level
will indicate the severity of the diagnostic;options
will change based on the rule.
Ignore code
Section titled Ignore codeThere 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:
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 doesn’t provide ignore comments that ignore an entire file. However, you can ignore a file using the Biome configuration file. Note that you can also ignore the files ignored by your VCS.
Migrate from other linters
Section titled Migrate from other lintersMany 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
If you are migrating from ESLint,
we have a dedicated migration guide.