Suppressions
Este conteúdo não está disponível em sua língua ainda.
The Biome analyzer is the foundation of the linter and assist; in fact, both tools share a lot of similarities.
Among them, they share the same suppression engine, which means that you can suppress a lint rule the same way you would suppress an assist action.
With suppression, it’s possible to turn off a lint rule (or action) for a specific line of code, a range, or the entire file.
Suppression is achievable with suppression comments.
Suppression syntax
Section titled “Suppression syntax”Suppression comments have the following format:
// biome-ignore lint: <explanation>// biome-ignore assist: <explanation>// biome-ignore syntax: <explanation>// biome-ignore lint/suspicious: <explanation>// biome-ignore lint/suspicious/noDebugger: <explanation>// biome-ignore lint/suspicious/noDebugger(foo): <explanation>// biome-ignore-all lint: <explanation>// biome-ignore-start lint: <explanation>// biome-ignore-end lint: <explanation>Let’s break it down:
biome-ignore,biome-ignore-all,biome-ignore-startandbiome-ignore-endare the start of a suppression comment.- After the space follows the category of the suppression comment. It can be
lint,assist, orsyntax. - The category is followed by an optional group, or group and name, separated by slashes. For example,
/suspiciousor/suspicious/noDebugger. The more you specify, the more specific (i.e. targeted) your suppression is. - Some rules even allow you to specify values during suppression. These can be specified between parentheses, for example:
(foo). Refer to the rule documentation to see whether a rule supports suppression with values. <explanation>explanation why the rule is disabled.
If you’re unsure of the exact category of a rule/action, you can refer to their documentation page and use their diagnostic category.
Inline suppressions
Section titled “Inline suppressions”They disable a lint rule for the next line of code.
In the following example, the suppression comment biome-ignore lint/suspicious/noDebugger: reason will disable the debugger; statement at line 2, but the debugger at line 3 will still raise a diagnostic:
// biome-ignore lint/suspicious/noDebugger: reasondebugger;debugger;Top-level suppressions
Section titled “Top-level suppressions”They disable a lint rule for an entire file. They must be placed at the top of the file, and they must start with biome-ignore-all.
These suppression comments are very useful when you want to suppression some lint rule for a particular file, and you don’t want to rely on a single configuration override to achieve that.
In the following example, the suppression comment biome-ignore-all lint/suspicious/noDebugger: reason will disable the lint rule for all lines in generated.js:
// biome-ignore-all lint/suspicious/noDebugger: reason
debuggerdebuggerWhen a top-level suppression comment isn’t at the top of the file, it is considered unused and Biome will emit a diagnostic with category suppression/unused.
Range suppressions
Section titled “Range suppressions”They disable a lint rule from a particular range in the file, starting from the line with the start comment, until the line with the end comment.
To mark the beginning of a range suppression, the suppression comment must start with // biome-ignore-start. To mark the end of it, the suppression comment must start with // biome-ignore-end.
The following example will disable the rule lint/suspicious/noDoubleEquals for line 2 and 3, but line 5 will raise a diagnostic:
// biome-ignore-start lint/suspicious/noDoubleEquals: reasona == b;c == d;// biome-ignore-end lint/suspicious/noDoubleEquals: reasonf == g;Range suppressions can also overlap. Consider the following example:
debugger;// biome-ignore-start lint/suspicious/noDebugger: reasondebugger// biome-ignore-start lint/suspicious/noDoubleEquals: reasona == b;c == d;// biome-ignore-end lint/suspicious/noDoubleEquals: reasondebuggerf == g;// biome-ignore-end lint/suspicious/noDebugger: reasonIn the above code:
- The
debuggerstatement at line 1 will raise a diagnostic because there’s no suppression comment that disables it. - The comment
// biome-ignore-start lint/suspicious/noDebugger: reasonat line 2 starts disablingnoDebuggerfrom line 3 onwards. - The comment
// biome-ignore-start lint/suspicious/noDoubleEquals: reasonat line 4 starts disablingnoDoubleEqualsfrom line 5 onwards. - The comment
// biome-ignore-end lint/suspicious/noDoubleEquals: reasonat line 7 terminates the suppression ofnoDoubleEqualsthat was started by the suppression comment at line 4. - The
debuggerstatement at line 8 doesn’t raise diagnostics due to the suppression comment at line 2. - The
f == gstatement raises a diagnostic because the rulenoDoubleEqualsisn’t suppressed anymore. - The comment
// biome-ignore-end lint/suspicious/noDebugger: reasonat line 7 terminates the suppression ofnoDebuggerthat was started by the suppression comment at line 2.
Copyright (c) 2023-present Biome Developers and Contributors.