TODO section 33. Every rule states a Severity (error: would likely fail
to compile or elaborate, or silently mis-synthesize; warning: a probable
bug; style), printed in lucisv check text and JSON, mapped to
ERROR/WARNING/INFORMATION in the editor, grouped in --rules-doc, and
accepted by --select/--ignore and [lint] as a class word. VS Code gains
lucisv.lint.severity.{error,warning,style} and one tri-state
lucisv.lint.rules.<rule> per rule (default/on/off - a client sends
every key, so a boolean cannot say unset), generated by
vlog_linter::vscode with a drift test, and lint::enabled_rules is the
one documented ladder: defaults -> select -> class switches -> per-rule
-> ignore. Nineteen new rules (17 -> 36), one file each with true
positives and near-misses: Error - mismatched-labels,
duplicate-declaration (Semantics::duplicates(), additive),
undeclared-identifier (with a project; silent for macro text, included
fragments, hierarchical tails, any name another file mentions),
unknown-port, unknown-parameter; Warning - forbid-defparam,
invalid-system-task-function, truncated-numeric-literal,
undersized-binary-literal (safe fix), suspicious-semicolon,
packed-dimensions-range-ordering, module-port, module-parameter,
explicit-function-task-parameter-type, plusarg-assignment,
instance-shadowing, forbid-negative-array-dim, void-cast,
incomplete-assignment. Every false-positive class found on opentitan
closed with a named test; 3 383 tests / 48 binaries; corpus 814/820
and byte-identical (formatter untouched); vsix smoke OK.
docs/features/linter-expansion-1/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
89 lines
3.1 KiB
Rust
89 lines
3.1 KiB
Rust
//! `plusarg-assignment` — read a plusarg's value, do not test for its name.
|
|
|
|
use crate::context::LintContext;
|
|
use crate::registry::Rule;
|
|
use crate::severity::Severity;
|
|
use crate::violation::Violation;
|
|
use vlog_parser::token::TokenKind;
|
|
|
|
/// See [`Rule::doc`].
|
|
pub struct PlusargAssignment;
|
|
|
|
const NAME: &str = "plusarg-assignment";
|
|
|
|
/// The system task this rule is about.
|
|
const TEST_PLUSARGS: &str = "$test$plusargs";
|
|
|
|
impl Rule for PlusargAssignment {
|
|
fn name(&self) -> &'static str {
|
|
NAME
|
|
}
|
|
|
|
fn summary(&self) -> &'static str {
|
|
"read a plusarg with `$value$plusargs`, not `$test$plusargs`"
|
|
}
|
|
|
|
fn severity(&self) -> Severity {
|
|
Severity::Warning
|
|
}
|
|
|
|
fn doc(&self) -> &'static str {
|
|
"`$test$plusargs(\"foo\")` answers only whether `+foo` was on the \
|
|
command line, and it matches by *prefix*: `+foobar` makes it true \
|
|
too, so two switches that share a prefix silently turn each other on. \
|
|
`$value$plusargs(\"foo=%d\", v)` matches the whole name, says whether \
|
|
it was there, and hands back the value — everything the other one \
|
|
does, without the trap, which is why a plusarg should always be \
|
|
given and read as a value. Verible's `plusarg-assignment` (\"Checks \
|
|
that plusargs are always assigned a value, by ensuring that plusargs \
|
|
are never accessed using the `$test$plusargs` system task.\", enabled \
|
|
by default) is the same rule and the same default. No automatic fix: \
|
|
the replacement needs a format string and a variable to read into, \
|
|
neither of which the call being replaced has."
|
|
}
|
|
|
|
fn check(&self, ctx: &LintContext) -> Vec<Violation> {
|
|
ctx.tokens()
|
|
.iter()
|
|
.filter(|token| token.kind == TokenKind::SystemIdent && token.text == TEST_PLUSARGS)
|
|
.map(|token| {
|
|
Violation::new(
|
|
NAME,
|
|
"`$test$plusargs` matches by prefix; use `$value$plusargs` and read the value",
|
|
token.span,
|
|
)
|
|
})
|
|
.collect()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
fn violations(src: &str) -> Vec<Violation> {
|
|
PlusargAssignment.check(&LintContext::new(src, None))
|
|
}
|
|
|
|
#[test]
|
|
fn flags_a_test_plusargs_call() {
|
|
let src = "module m;\n initial if ($test$plusargs(\"fast\")) go = 1;\nendmodule\n";
|
|
let found = violations(src);
|
|
assert_eq!(found.len(), 1, "{found:?}");
|
|
assert_eq!(&src[found[0].span.as_range()], "$test$plusargs");
|
|
assert!(found[0].fix.is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn the_value_form_is_what_the_rule_wants() {
|
|
let src = "module m;\n\
|
|
initial if ($value$plusargs(\"speed=%0d\", speed)) go = 1;\n\
|
|
endmodule\n";
|
|
assert!(violations(src).is_empty());
|
|
// And a name that merely contains the words is not the call.
|
|
assert!(violations("module m;\n logic test_plusargs;\nendmodule\n").is_empty());
|
|
assert!(violations("module m;\n initial $display(\"$test$plusargs\");\nendmodule\n")
|
|
.is_empty());
|
|
}
|
|
}
|