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    ParameterHasNoDefault,
17    SupportNeverEnds,
18}
19
20impl LintCode {
21    pub const ALL: &'static [LintCode] = &[
22        LintCode::GridRowsPerBar,
23        LintCode::MissingComment,
24        LintCode::MalformedComment,
25        LintCode::MultilineComment,
26        LintCode::LongCommentBlock,
27        LintCode::LongExpressionBody,
28        LintCode::LiteralSampleRate,
29        LintCode::Arity,
30        LintCode::KeyIsNotAPitch,
31        LintCode::ParameterHasNoDefault,
32        LintCode::SupportNeverEnds,
33    ];
34
35    pub fn code_str(self) -> &'static str {
36        match self {
37            LintCode::GridRowsPerBar => "grid-rows-per-bar",
38            LintCode::MissingComment => "missing-comment",
39            LintCode::MalformedComment => "malformed-comment",
40            LintCode::MultilineComment => "multiline-comment",
41            LintCode::LongCommentBlock => "long-comment-block",
42            LintCode::LongExpressionBody => "long-expression-body",
43            LintCode::LiteralSampleRate => "literal-sample-rate",
44            LintCode::Arity => "arity",
45            LintCode::KeyIsNotAPitch => "key-is-not-a-pitch",
46            LintCode::ParameterHasNoDefault => "parameter-has-no-default",
47            LintCode::SupportNeverEnds => "support-never-ends",
48        }
49    }
50
51    /// Exhaustive, so a code cannot be added without saying what to write instead of it.
52    pub fn help(self) -> &'static str {
53        match self {
54            LintCode::GridRowsPerBar => {
55                "make the row count a whole multiple of the filename's bar span, or restate the span"
56            }
57            LintCode::MissingComment | LintCode::MalformedComment => {
58                "give the node one `;`-comment line: `; Models: ... | Neglects: ... | IO: ... -> ... \
59                 | Tags: ...`"
60            }
61            LintCode::MultilineComment => "fold the `;`-comment onto one line",
62            LintCode::LongCommentBlock => {
63                "move the prose out of the node and keep the one `;`-comment line"
64            }
65            LintCode::LongExpressionBody => "split the expression across nodes and `@ref` them",
66            LintCode::LiteralSampleRate => {
67                "write the sample period as `sp` and let the render choose its rate"
68            }
69            LintCode::Arity => "give the call what its builtin reads, as `sva-cli builtins` lists",
70            LintCode::KeyIsNotAPitch => {
71                "hold one note name or a number of hertz in `variables/key`"
72            }
73            LintCode::ParameterHasNoDefault => {
74                "give the parameter a `name = value` line above the expression, so the node plays bare"
75            }
76            LintCode::SupportNeverEnds => {
77                "crop it, or shape it to decay, so a bare render of it ends"
78            }
79        }
80    }
81}