Skip to main content

sva_core/
lint_code.rs

1// Concern: the `lint` codes a caller branches on, and the remediation each names | Non-concern: finding a violation (sva-cli lint.rs), framing one (cli_error.rs) | IO: (LintCode) -> tag, help
2
3/// Every shape `lint` reports. A caller dispatches on the tag, so the tag is the contract and
4/// the variant is how this workspace spells it.
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6pub enum LintCode {
7    GridRowsPerBar,
8    MissingComment,
9    MalformedComment,
10    MultilineComment,
11    LongCommentBlock,
12    LongExpressionBody,
13    LiteralSampleRate,
14    Arity,
15    KeyIsNotAPitch,
16    QuietTail,
17}
18
19impl LintCode {
20    pub const ALL: &'static [LintCode] = &[
21        LintCode::GridRowsPerBar,
22        LintCode::MissingComment,
23        LintCode::MalformedComment,
24        LintCode::MultilineComment,
25        LintCode::LongCommentBlock,
26        LintCode::LongExpressionBody,
27        LintCode::LiteralSampleRate,
28        LintCode::Arity,
29        LintCode::KeyIsNotAPitch,
30        LintCode::QuietTail,
31    ];
32
33    pub fn code_str(self) -> &'static str {
34        match self {
35            LintCode::GridRowsPerBar => "grid-rows-per-bar",
36            LintCode::MissingComment => "missing-comment",
37            LintCode::MalformedComment => "malformed-comment",
38            LintCode::MultilineComment => "multiline-comment",
39            LintCode::LongCommentBlock => "long-comment-block",
40            LintCode::LongExpressionBody => "long-expression-body",
41            LintCode::LiteralSampleRate => "literal-sample-rate",
42            LintCode::Arity => "arity",
43            LintCode::KeyIsNotAPitch => "key-is-not-a-pitch",
44            LintCode::QuietTail => "quiet-tail",
45        }
46    }
47
48    /// Exhaustive, so a code cannot be added without saying what to write instead of it.
49    pub fn help(self) -> &'static str {
50        match self {
51            LintCode::GridRowsPerBar => {
52                "make the row count a whole multiple of the filename's bar span, or restate the span"
53            }
54            LintCode::MissingComment | LintCode::MalformedComment => {
55                "give the node one `;`-comment line: `; Models: ... | Neglects: ... | IO: ... -> ... \
56                 | Tags: ...`"
57            }
58            LintCode::MultilineComment => "fold the `;`-comment onto one line",
59            LintCode::LongCommentBlock => {
60                "move the prose out of the node and keep the one `;`-comment line"
61            }
62            LintCode::LongExpressionBody => "split the expression across nodes and `@ref` them",
63            LintCode::LiteralSampleRate => {
64                "write the sample period as `sp` and let the render choose its rate"
65            }
66            LintCode::Arity => "give the call what its builtin reads, as `sva-cli builtins` lists",
67            LintCode::KeyIsNotAPitch => {
68                "hold one note name or a number of hertz in `variables/key`"
69            }
70            LintCode::QuietTail => "crop the node where it falls under the resolution",
71        }
72    }
73}