suppression_requires_justification
Reports a suppression with no justification. Write why on the line directly above it.
- Tier
- blocking
- Scope
- Dart
- Fix
- none
What it reports
Section titled “What it reports”A suppression with no justification. The violation covers the suppression comment.
The rule judges every // ignore: <codes> and // ignore_for_file: <codes> in a file, whatever it names: an assay rule (assay/avoid_dynamic or avoid_dynamic), an SDK lint (unused_import), another plugin’s rule, or type=lint.
The justification is a plain comment on the line directly above the suppression:
// The caller has already tested the text for null.// ignore: assay/avoid_non_null_assertionreturn text!.length;For a suppression at the end of a code line, it is the comment line directly above that code line:
// The caller has already tested the text for null.return text!.length; // ignore: assay/avoid_non_null_assertionThese do not count, and the suppression is reported:
- a blank line between the comment and the suppression;
- a documentation comment,
///or/** … */; - another suppression: name both codes in one suppression, or give each its own comment;
- an empty comment,
//, or a comment at the end of a code line; - a reason on the same line, after the codes:
// ignore: unused_import because ….
A suppression is the cheapest way to make a violation go away, and without a reason beside it nobody can tell a considered exception from a shortcut. An AI coding agent stopped by a blocking rule can reach for // ignore: instead of fixing the code. With this rule, the turn still does not pass until the suppression says why, where a reviewer reads it.
Example
Section titled “Example”int portOf(Map<String, Object?> settings) { // ignore: assay/avoid_non_null_assertion return (settings['port'] as int?)!;}int portOf(Map<String, Object?> settings) { final port = settings['port']; return port is int ? port : defaultPort;}int portOf(Map<String, Object?> settings) { // The settings were validated on load, and a missing port stops the start. // ignore: assay/avoid_non_null_assertion return (settings['port'] as int?)!;}Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
assay: rules: suppression_requires_justification: exclude: - lib/generated/**Suppressing it
Section titled “Suppressing it”Details
Section titled “Details”All cases
What it reports, in full
Section titled “What it reports, in full”A suppression is the analyzer’s own comment: // ignore: <codes> for one place, // ignore_for_file: <codes> for a whole file. An assay rule can be named with the prefix, assay/avoid_dynamic, or alone, avoid_dynamic. Both forms work in both hosts, this rule judges both, and the gate lists both when a change adds one.
The rule judges every suppression in a file, whatever it names:
- an assay rule:
assay/avoid_dynamic; - an SDK lint or another analyzer diagnostic:
unused_import; - another plugin’s rule:
other_plugin/some_rule; - a whole class of diagnostics:
type=lint.
It reads Dart files only: a suppression in analysis_options.yaml or pubspec.yaml is not judged. In a file that does not compile, assay’s engine judges the suppressions once the file compiles.
// ignore_for_file: takes the same two lines:
// This file mirrors a wire format whose names are fixed.// ignore_for_file: non_constant_identifier_namesA comment is a justification when it has some text and a line to itself, whatever the text says. A block comment that is not a documentation comment counts when it has its lines to itself and ends on the line directly above: /* The caller has tested the text. */. These do not count, and the suppression below them is reported:
- nothing, or a line of code;
- a blank line between the comment and the suppression;
- a documentation comment,
///or/** … */; - another suppression. Two suppressions under one comment leave the second without a justification: name both codes in one suppression, or give each its own comment.
- an empty comment,
//; - a comment at the end of a code line:
var ready = false; // Set by the loader.
It does not report:
- a suppression in the two-line form, whatever the comment says;
- text that only looks like a suppression: in a string, in a block comment such as
/* ignore: unused_import */, or in a comment that mentions one,// Use ignore: unused_import with care.; // ignore:with no code, which silences nothing.
Why the line above
Section titled “Why the line above”The reason goes on the line above, not after the codes on the same line. One form is easier to read and check than two, and the same-line form relies on undocumented parsing in the analyzer.
The rule cannot judge whether the comment is a real reason: // Lorem ipsum. passes. It guarantees there is a place for the reason, and that it is not empty.
The SDK lint document_ignores has the same aim. assay’s presets switch it off, so a missing justification is reported once, by this rule, which has a tier and runs in assay’s engine.
The blanket form type=lint
Section titled “The blanket form type=lint”// ignore: type=lint and // ignore_for_file: type=lint silence every assay rule where they apply, blocking or advisory, in both hosts. To the analyzer, an assay rule is a lint whatever its tier. type=warning and type=hint silence no assay rule.
The one exception: in assay’s engine, type=lint does not silence this rule (see below).
A type=lint form is a suppression like any other. It needs a justification, check records it, and the gate lists a new one, so a rule silenced wholesale does not go unnoticed.
It cannot be suppressed in check or at the gate
Section titled “It cannot be suppressed in check or at the gate”This is the one assay rule that no suppression silences in assay’s own engine.
| Where | A suppression of this rule |
|---|---|
assay check and assay gate |
is ignored. The rule is always judged, whether the suppression is prefixed or not, for one place or a whole file, justified or not. // ignore_for_file: type=lint silences every other assay rule in the file and leaves this one judged. The suppression is still recorded and listed, and needs a justification itself. |
The editor and dart analyze |
is honoured, in every form: prefixed or not, for one place or a whole file, and a type=lint that covers the line. |
The hosts differ because of who applies suppressions. In the editor, the analyzer applies them before asking the plugin anything, and a plugin cannot exempt one of its rules. assay’s engine applies suppressions itself, so it can make the exception. Without it, one justified file-wide suppression of this rule would remove the need for a justification from every other suppression in that file.
So for this one rule the editor can show a file as clean that check and the gate still fail. Their output names the rule and the place. This is the only place where the two hosts differ on suppressions.
In the editor, such a suppression looks like any other:
// This file is generated; the generator writes its suppressions bare.// ignore_for_file: assay/suppression_requires_justificationIt silences the editor and the standard analysis command, and nothing else. What works everywhere is configuration: switch the rule off, or exclude paths from it, as in the example under Rule parameters. That holds in both hosts, and the gate lists the change when it is made during the work it judges.