use crate::linter::diagnostic::Diagnostic;
use crate::linter::rules::{Example, Rule, RuleContext};
pub struct UnexplainedSuppression;
impl Rule for UnexplainedSuppression {
fn id(&self) -> &'static str {
"unexplained-suppression"
}
fn default_enabled(&self) -> bool {
false
}
fn description(&self) -> &'static str {
"Flag a `# fatou-ignore` directive that states no reason. The `: \
<reason>` part is optional, so this rule is **off by default**; select \
it in a project that wants every suppression to record why the finding \
was accepted. There is no fix: the reason is the part only the author \
can supply."
}
fn examples(&self) -> &'static [Example] {
&[Example {
caption: "A suppression with nothing to say for itself:",
source: "# fatou-ignore unused-binding\nfunction f()\n handle = open_device()\n 1\nend\n",
}]
}
fn check_file(&self, ctx: &RuleContext<'_>, sink: &mut Vec<Diagnostic>) {
for directive in ctx.suppressions.directives() {
if directive.has_reason() {
continue;
}
let mut diag =
Diagnostic::new(self.id(), directive.comment, "suppression states no reason");
diag.message = diag
.message
.with_suggestion("add one: `# fatou-ignore <rule>: <reason>`");
sink.push(diag);
}
}
}