SuppressionMap
SuppressionMap is the per-source index of every suppression directive a file declares. Every source file gets one scan for directives during Source construction, and the map is the result. It records the format-suppression spans (# fmt: off / # fmt: on, # prose: off / # prose: on, and the # yapf: disable / # yapf: enable aliases), the statement-level format markers (# fmt: skip and its # prose: skip alias), the per-rule format directives (# prose: skip[<rule>]), and the per-line lint directives (# prose: ignore and # prose: ignore[<rule>]). The Pipeline reads the map at the point edits are emitted and drops a suppressed fix group or lint diagnostic before it reaches the caller.
Public Surface
The SuppressionMap type itself is pub(crate) today, so neither the type nor its methods are reachable from a downstream Rust consumer. The suppression behavior is reachable through Pipeline::run, which filters emitted edits and lint diagnostics against the map.
A downstream consumer works with suppression through the directives in the source files:
- A source file declares its directives inline (
# fmt: off,# fmt: skip,# prose: skip[<rule>],# prose: ignore[<rule>]). - The
Pipelinereads the directives duringrun. - Diagnostics and edits a directive covers are dropped from the returned vectors, with no notice.
The type opens toward 1.0, when the lookup methods become public so downstream tooling can inspect suppression spans (IDE highlighting of suppressed ranges, lint-coverage reports, suppression audits).
Internal Surface
For code inside the Prose crate, the map exposes a constructor and a set of predicates:
from_comments(source, comments, tokens, first_code_offset, cell_offsets) -> Selfbuilds the map by scanning the comment ranges for the directive forms the map recognizes.tokensresolves the logical line each skip directive covers,first_code_offsetis whatfile_is_suppressedcompares an unmatched opener against, andcell_offsetscloses an unmatched opener at the end of its notebook cell.file_is_suppressed() -> boolreturns true when an unmatched# prose: off(or# fmt: off) sits at or before the first non-blank, non-comment line of the file, so the pipeline returns the source unchanged before any rule runs.has_format_suppression() -> boolreports whether any# prose: offregion, bare# prose: skipspan, or# prose: skip[<rule>]directive sits in the file.has_lint_suppression() -> boolreports the same for# prose: ignoredirectives.intersects<R: Ranged>(ranged: R) -> boolreturns true when the given range overlaps a# prose: offregion, which is the check the lint filter reads, so a bare# prose: skipopens nothing here and a lint diagnostic on its statement survives.is_lint_suppressed_at(line: OneIndexed, rule: RuleId) -> boolreturns true when the line carries a# prose: ignoredirective that names the rule, or a bare directive that covers every rule.suppresses<R: Ranged>(ranged: R, rule: RuleId) -> boolreturns true when the given range overlaps a# prose: offregion, a bare# prose: skipspan, or a# prose: skip[<rule>]span naming the rule, which is the check the rewrite filter reads.
The Source accessor suppression_map(&self) -> &SuppressionMap is also pub(crate). Every entry point above opens at 1.0.
Directive Recognition
The directives that feed the map share a grammar the Suppression chapter covers, and the forms the map records are these:
# fmt: offopens a format-suppression span and# fmt: oncloses it. A span with no closer runs to the end of the file, or to the end of its notebook cell. Nested or overlapping# fmt: offmarkers flatten, so the first# fmt: onafter any number ofoffmarkers closes the span.# prose: offand# prose: onuse the same span machinery, so a project picks whichever prefix reads better. When# prose: offsits at or before the first non-blank, non-comment line of the file and no# prose: onfollows, the map setsfile_is_suppressed.# yapf: disableand# yapf: enableare recognized as aliases for# fmt: offand# fmt: on, so a project's existing yapf markers keep working. Other yapf directives are not recognized.# fmt: skipat the end of a line exempts that one logical line from rewrites, scoped to that statement, and leaves its lint diagnostics to report.# prose: skipis the equivalent alias.# prose: skip[<rule>, <rule>, …]exempts the listed auto-fix rules across the same logical line# fmt: skipcovers, with whitespace inside the brackets tolerated and two bracketed directives on one line unioning their rule sets. An unknown rule slug is dropped with no notice.# prose: ignore[<rule>, <rule>, …]exempts the listed lint rules on the directive's line, with the same bracket-whitespace tolerance and union behavior. A bare# prose: ignorecovers every lint rule on the line.
Re-Using This Primitive
The Pipeline is the canonical consumer, applying the filter at the point edits are emitted, so a new rule emits its edits unconditionally and the pipeline drops the suppressed groups. A rule whose fix group would otherwise span an exempt row reads suppresses itself before grouping, the way the alignment rules exclude a skip-exempt row through the aligner's is_held before a column is resolved. alphabetize-siblings, band-constants, and modernize-annotations read it the same way. The map is built once per source and handed to every reader by reference.
A consumer reusing the suppression directives in a different formatter would build the same map and apply the same filter at its own edit-emission point, taking the whole directive set (format spans, statement-level format markers, per-rule format directives, and per-line lint directives) without re-implementing the scan.
The Cargo dependency line (prose = { git = "...", tag = "<version>" }) lives on the Source page. A downstream consumer reaches the map only through Pipeline::run dropping suppressed diagnostics, not through direct method calls, and the user-facing directives are covered in full by the Suppression chapter.
Related
- The Suppression chapter covers the directives the map records, with the syntax for block markers, line markers, and lint directives.
Sourcebuilds the map during construction and exposes it throughsuppression_map().Pipelinereads the map at the point edits are emitted, dropping suppressed entries before they reach the caller.RuleIdis the handle the bracketed directives name inside the# prose: skip[<slug>]and# prose: ignore[<slug>]syntax.
For the rule catalog whose diagnostics this map filters, the Rules page lists every shipped rule by category.