Skip to content

Suppressions

A suppression silences a rule at one place, with // ignore:, or in a whole file, with // ignore_for_file:. It is the analyzer’s own comment: it silences a rule of assay as it silences an SDK lint. Every suppression needs a justification, a plain comment on the line directly above it.

// The protocol defines this timeout; it is not a tuning value.
// ignore: assay/no_magic_number
const timeoutSeconds = 37 * 1;
// The protocol defines this retry count.
// ignore: no_magic_number
int retries() => 5;

The first names the rule with the assay/ prefix, the second by its name alone. Both work; see Naming a rule.

At the end of a code line, the justification goes on the line above that code line:

// The plugin interface declares this argument as dynamic; it is checked below.
void onMessage(dynamic message) { // ignore: assay/avoid_dynamic

For a whole file:

// This file mirrors an untyped JavaScript API, so its values are dynamic.
// ignore_for_file: assay/avoid_dynamic

Both forms work alike, in both hosts and by the same line rules:

  • With the prefix, assay/<rule>. The prefix is the plugin’s name, assay, never assay_lints/.
  • By the rule’s name alone, the way you name an SDK lint. It means the rule of assay, because no rule of assay has the name of an SDK lint or an analyzer diagnostic.

In the editor and in dart analyze, the analysis server applies only the prefixed form to a plugin’s rule, so assay’s plugin applies the bare form itself. The result is the same.

Under strict, the SDK lint unnecessary_ignore reports neither form as unneeded. The analyzer leaves a code it does not know alone, because a plugin may report it.

The blanket form // ignore: type=lint silences every rule of assay where it applies, blocking or advisory, in both hosts: to the analyzer, every rule of assay is a lint, whatever its tier. type=warning and type=hint silence no rule of assay.

A blanket suppression is a suppression like any other: it needs a justification, and the gate lists a new one.

Write the reason in a plain // comment on the line directly above the suppression, or above the code line for a suppression at the end of it. These do not count:

  • a documentation comment (///);
  • a blank line;
  • another suppression: each suppression needs its own.

A suppression without a justification is a violation of the blocking rule suppression_requires_justification, whatever it names: a rule of assay, an SDK lint or another plugin’s diagnostic.

/// A suppression without a reason on the line above.
// ignore: no_magic_number
int delay() => 250;
╭─ Violations ─────────────────────────────────────────────────── 1 in 1 file ─╮
│ Line Rule Tier │
│ ────────────────────────────────────────────────── │
│ lib/suppressed.dart 1 violation │
│ ✗ 2:1 suppression_requires_justification blocking │
╰──────────────────────────────────────────────────────────────────────────────╯

assay cannot judge whether the comment is a good reason. It judges that there is one.

assay’s engine records every suppression in a judged file: where it is, what it names, whether it is justified and, at turn end, whether it is new.

  • New means the change under judgement added it. A suppression that only moved with its line is not new.
  • A renamed file keeps its suppressions. In a git repository, a file the change renamed (by git mv, or in a commit since the base), even one it also edited, is compared with the file it was renamed from. A file moved without git, which git does not track yet, has every suppression new.

Every gate result lists the new suppressions apart from the violations:

  • A justified new suppression does not fail the gate, by hand or in CI. The console report, the full report, the JSON result (newSuppressions[]) and the Markdown summary list it.
  • An unjustified one fails the gate through suppression_requires_justification.
  • At turn end, the agent plugin blocks on every new suppression of the session’s change, justified or not, and tells the agent to fix what it hides. See The gate and agent setup.

A coverage-ignore comment (// coverage:ignore-line, -start, -end, -file; see Coverage) takes lines out of the line coverage, much as a suppression takes a violation out of the judgement. So the gate on a change lists the ones the change added, as it lists new suppressions: in every changed Dart file it judges, under lib/ or not, also one that does not compile, and whether or not it is given a coverage report. The project judgement lists none, as it judges no change.

They fail nothing: the verdict and the exit code are the same with them as without. The console report lists them in a box New coverage-ignore comments, each file a sub-heading over its comments, in the report for the terminal and in the full report. The JSON result lists them in newCoverageIgnores (file, line, column, kind, identity) and counts them in summary.newCoverageIgnores.

╭─ New coverage-ignore comments ───────────────────────────────── 2 in 1 file ─╮
│ Line Comment │
│ ─────────────────────────── │
│ lib/src/logging.dart │
│ 14 coverage:ignore-start │
│ 31 coverage:ignore-end │
╰──────────────────────────────────────────────────────────────────────────────╯

At turn end, the agent plugin blocks on a new one as on a new suppression (The gate and agent setup). Only a changed file that holds such a comment now has its state before the change read, so a change without one costs the gate nothing more.

A comment’s identity is its kind, its file, the text of its line (trimmed, each run of spaces made one) and its place among the comments alike. Where it stands is not part of it. A comment is new when the file’s state before the change holds none with its identity.

A region and an ignore-file are also new wherever the lines they take out hold a new line of the change: a line the state before does not hold, by a line diff of the two, the same new lines the coverage of new lines counts. So no line the change wrote leaves the coverage without a comment listed for it.

What the change did New?
Added or removed lines around the comment, so it only moved no
Edited the comment’s line (the code before an ignore-line is part of its line) yes
Changed its kind (ignore-line to ignore-file), or added a second one alike yes
Added an ignore-file where the file held none, wherever it stands yes
Widened or moved a region, or wrote or edited a line in it yes, both comments
Moved the end of a region below new code yes, both comments
Added or edited a line of a file that has an ignore-file yes
Moved a region with the code around it, all of it unchanged no; but one whose own lines the line diff takes for moved, as where a block of code moved past it, can be
Created the file, or the file is one git does not track yet (one moved without git among them), or its state before is not known (a file a list of changes records as rewritten) yes, every comment
Renamed the file in git compared with the file it was renamed from, as for suppressions

An ignore-line is new by its identity alone, which holds the code of its line. A comment new in this way keeps its identity, so a second turn end in the same state lets the agent go, as after any block.

The comments are found by the grammar of the coverage package in the text of each line. So a line of a multi-line string that reads as one is listed too: it takes lines out of the count all the same.

The rule that cannot be suppressed at the gate

Section titled “The rule that cannot be suppressed at the gate”

assay check and assay gate always judge suppression_requires_justification. assay’s engine ignores any suppression that names it, in either form, for a line or for a file, justified or not:

/// A delay.
// ignore: suppression_requires_justification
// ignore: no_magic_number
int delay() => 250;
╭─ Violations ─────────────────────────────────────────────────── 2 in 1 file ─╮
│ Line Rule Tier │
│ ────────────────────────────────────────────────── │
│ lib/unsuppressible.dart 2 violations │
│ ✗ 2:1 suppression_requires_justification blocking │
│ ✗ 3:1 suppression_requires_justification blocking │
╰──────────────────────────────────────────────────────────────────────────────╯

Such a suppression is still recorded and listed like any other.

If you do not want the rule, switch it off under assay: (suppression_requires_justification: false). At turn end that is listed as a configuration change.

  • A result of a cross-file check, an asset check or a project-file check is silenced by the check’s own exclude, not by a suppression comment (Excluding code).
  • assay metrics shows a value over its limit whose violation a suppression hides, marked as suppressed: a value is a measurement, and the suppression a judgement about it.
  • assay fix leaves a violation that a suppression hides as it is.