pub struct Rule {
pub file: Option<PathBuf>,
pub line: usize,
pub name: String,
pub pattern: Pattern,
pub source: String,
pub message: String,
pub severity: Severity,
pub fix: Option<String>,
pub files: Vec<String>,
pub unless: Vec<Pattern>,
pub record: Option<RecordUnit>,
pub meta: Vec<(String, String)>,
}Expand description
One rule of a pattern file: a named pattern with what a finding of it
says, how serious it is, the fix that replaces the match, the inputs it
reads, the record it holds and the metadata a pipeline filters on. The
rule is also a sub-pattern under its name, so \{name} reads it and a
test line checks it.
Fields§
§file: Option<PathBuf>The pattern file the rule is in, where the set was declared from one.
line: usizeThe line the rule opens on, from one.
name: StringThe rule’s name, the id a finding is reported under.
pattern: PatternWhat the rule matches.
source: StringThe pattern as written.
message: StringWhat a finding says: a report template rendered at each match, with
the match’s registers and their typed slices, its position, and
${rule} and ${severity}.
severity: SeverityHow serious a finding is; a warning where the rule says nothing.
fix: Option<String>The rewrite template a fix renders in the match’s place, where the rule has one.
files: Vec<String>The globs the inputs the rule reads are kept by (*.py) or dropped
by (!test_*), as -g takes them; every input where there are none.
unless: Vec<Pattern>The patterns the record must not hold for the rule to fire.
record: Option<RecordUnit>What a record is, for a rule that fires on a record holding the
pattern and none of unless: a line where a rule names unless and
no record; nothing for a rule that fires on each match.
meta: Vec<(String, String)>The meta.KEY = VALUE lines, in order.
Implementations§
Source§impl Rule
impl Rule
Sourcepub fn on_records(&self) -> bool
pub fn on_records(&self) -> bool
Whether the rule fires on a record rather than on each match: it names a record or a pattern the record must not hold.
Sourcepub fn record_unit(&self) -> RecordUnit
pub fn record_unit(&self) -> RecordUnit
What a record is for this rule: what it names, or a line where it names only what the record must not hold.
The values meta.tags lists, comma-separated.