Aller au contenu

Suppressions

Ce contenu n’est pas encore disponible dans votre langue.

Sometimes Biome is wrong about your code, or you have a good reason to break a rule. A suppression comment tells Biome to ignore a specific piece of code, and it records why, so the next person to read the code knows too.

If you want to turn off a rule everywhere, disable it in your configuration instead. Suppressions are for exceptions.

A suppression comment starts with biome-ignore, followed by what to ignore and a reason:

example.js
// biome-ignore lint/suspicious/noDebugger: needed to debug the payment flow
debugger;

The comment has three parts:

  1. biome-ignore decides how much code it covers. See Choose what to cover.
  2. What to ignore, such as lint/suspicious/noDebugger. See Choose what to ignore.
  3. The reason, after the colon. It is required, so write something that helps your teammates.

Comments use the syntax of each language, such as /* biome-ignore ... */ in CSS or <!-- biome-ignore ... --> in HTML.

biome-ignore covers the code that comes right after the comment. In the following example, only the first debugger statement is ignored:

example.js
// biome-ignore lint/suspicious/noDebugger: reason
debugger;
debugger;

biome-ignore-all covers the whole file, which makes it useful for generated code. Place it at the top of the file:

generated.js
// biome-ignore-all lint/suspicious/noDebugger: this file is generated
debugger;
debugger;

If a biome-ignore-all comment is anywhere else, Biome reports it as unused.

biome-ignore-start and biome-ignore-end cover everything in between. Every start comment needs a matching end comment:

example.js
// biome-ignore-start lint/suspicious/noDoubleEquals: legacy comparison logic
a == b;
c == d;
// biome-ignore-end lint/suspicious/noDoubleEquals: legacy comparison logic
e == f;

Here, lines 2 and 3 are ignored, but line 5 is still reported. Ranges for different rules can overlap.

After biome-ignore, write the category of the tool you want to silence. Add a group and a rule name, separated by slashes, to be more specific:

Comment What it ignores
biome-ignore lint: <reason> Every lint rule
biome-ignore lint/suspicious: <reason> Every rule in the suspicious group
biome-ignore lint/suspicious/noDebugger: <reason> Only the noDebugger rule
biome-ignore assist/source/useSortedKeys: <reason> Only the useSortedKeys assist action
biome-ignore format: <reason> The formatter
biome-ignore syntax: <reason> Syntax diagnostics
biome-ignore lint/plugin: <reason> Every plugin
biome-ignore lint/plugin/myPlugin: <reason> Only the myPlugin.grit GritQL plugin
biome-ignore lint/plugin/myRule: <reason> Only the myRule rule exported by a JavaScript plugin

Prefer the most specific form, so that you do not hide other problems by accident. If you are not sure what to write, copy the diagnostic category shown on the rule’s documentation page or in the diagnostic itself.

A few rules also let you ignore a single value by adding it in parentheses, for example lint/correctness/useExhaustiveDependencies(user) ignores only the user dependency. The documentation page of the rule tells you if it supports this.

When your editor shows a Biome diagnostic, its quick fixes include actions that insert a suppression comment for you, either for the next line or for the whole file.

If you never want to see these actions, you can turn them off. Use source.suppressRule.inline.biome for the next-line suppression:

.vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.suppressRule.inline.biome": "never"
}
}

And source.suppressRule.topLevel.biome for the whole-file suppression:

.vscode/settings.json
{
"editor.codeActionsOnSave": {
"source.suppressRule.topLevel.biome": "never"
}
}

When you adopt Biome in an existing project, or enable a new rule, you might get hundreds of diagnostics at once. Instead of fixing them all before you can merge, you can suppress every current violation and fix them over time:

npx biome lint --suppress --reason="TODO: fix after adopting Biome"

Biome adds a biome-ignore comment with your reason above each violation. New code is checked normally, and you can search for the reason to find what is left to fix.

When a suppression comment no longer hides anything, for example because someone fixed the code, Biome reports it as unused. Remove the comment to keep your code clean.