Linter expansion, wave 2: per-rule options end to end, options on the naming rules, and eighteen Style rules
TODO section 34 (36 -> 54 rules). Options: OptionSpec/OptionKind/OptionValue/RuleOptions in vlog_linter with one validator behind both front ends - [lint.<rule>] tables in lucisv.toml (accepted now; stored raw by lucisv_core::config, resolved per file by the CLI with <config>:<line> on the first bad entry) and the editor's lucisv.lint.options object (bad entries logged and dropped) - precedence editor > toml > default key by key, --rules-doc listing every option. A small anchored regex engine of our own: a Thompson-NFA simulation, linear in pattern x name by construction (QA's first cut found the backtracking matcher exponential on (a*)*b), unknown escapes refused by name through both doors, a 71-row table verified against CPython. The four naming rules take Verible's option spellings with defaults that keep today's verdicts byte-identical. Eighteen Style rules, one file each with true positives and near- misses: line-length (the formatter's width), posix-eof (safe fix), forbid-consecutive-null-statements (safe fix), generate-label and generate-label-prefix, package-filename, one-module-per-file (off), signal/interface/macro/constraint/parameter-type-name-style, port-name-suffix (off), banned-declared-name-patterns (off), typedef-enums, typedef-structs-unions (allow_anonymous_nested defaults true here - opentitan's 3 159 findings were all generated register packages, and its own config disables the rule), always-comb (unsafe fix), explicit-begin (off, Verible's eleven enables). Four rules ask parsed_cleanly() first after a census showed error-recovered UVM files rebound as generate blocks. package.json regenerated (drift test). 3 549 tests / 48 binaries; corpus 814/820 byte-identical; naming-rule finding lists identical to 0.36.0; opentitan check timing unchanged. docs/features/linter-expansion-2/README.md. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
10b63e665d
commit
5e5813a2a9
59 files changed
+7298
-158
No files matched your search
@@ -3,18 +3,46 @@ title: Lint rules
|
||||
description: Complete reference for every lucisv lint rule, its severity, default, fix, and rationale.
|
||||
---
|
||||
|
||||
<span class="badge">36 rules indexed</span>
|
||||
<span class="badge">54 rules indexed</span>
|
||||
|
||||
Every rule is in one of three **severity** classes. `error` is code that would very likely fail to compile, elaborate or synthesize; `warning` is code that compiles and very likely does not mean what it says; `style` is code that is correct and reads badly. The class is the word in the CLI diagnostic line (`FILE:LINE:COL: warning: …`), the `severity` field of `--output-format json`, and the colour of the editor's squiggle — and it is accepted wherever a rule name is, so `--ignore style` and `--select error` both work.
|
||||
|
||||
Every `error`-class rule is held to one discipline: it goes **silent whenever the run cannot answer** — a file that did not fully parse, a module the project does not hold or holds twice, a name a macro produces, a fragment written to be `` `include``d. A wrong accusation in that class is worse than a hundred missed ones.
|
||||
|
||||
This page is hand-written prose. The generated truth is `lucisv check --rules-doc`, which prints every rule with its class, default, fix and rationale straight from the registry.
|
||||
This page is hand-written prose. The generated truth is `lucisv check --rules-doc`, which prints every rule with its class, default, fix and rationale straight from the registry — **and every option a rule takes, with its kind and default**.
|
||||
|
||||
A configurable rule is configured in a `[lint.<rule-name>]` table of a `lucisv.toml`, or from an editor in the `lucisv.lint.options` object; the option names are Verible's wherever it has the same option. An unknown rule or option name, a value of the wrong kind, an out-of-range integer or a pattern that does not compile fails a CLI run naming the file and the line, and is ignored (with a log line) in an editor.
|
||||
|
||||
```toml
|
||||
[lint.line-length]
|
||||
length = 120
|
||||
|
||||
[lint.typedef-structs-unions]
|
||||
allow_anonymous_nested = true
|
||||
```
|
||||
|
||||
A rule marked **on (project)** runs by default only where lucisv can see the other files of your project — `lucisv check <dir>`, or the language server. Over a single file or a stdin buffer it is off and must be `--select`ed, because its one false-positive mode is a use in another file. Turn any rule off with `--ignore`, with `ignore` under `[lint]` in `lucisv.toml`, or with `lucisv.lint.ignore` in your editor.
|
||||
|
||||
| Rule | Severity | Default | Fix | Purpose |
|
||||
|---|:---:|:---:|:---:|---|
|
||||
| [`always-comb`](#always-comb) | style | on | unsafe | Write `always_comb`, not `always @*` |
|
||||
| [`banned-declared-name-patterns`](#banned-declared-name-patterns) | style | off | — | Ban the names your project has decided against |
|
||||
| [`constraint-name-style`](#constraint-name-style) | style | on | — | Name constraints `lower_snake_case` ending `_c` |
|
||||
| [`explicit-begin`](#explicit-begin) | style | off | safe | Wrap every body in `begin ... end` |
|
||||
| [`forbid-consecutive-null-statements`](#forbid-consecutive-null-statements) | style | on | safe | Drop a `;` that follows a `;` |
|
||||
| [`generate-label`](#generate-label) | style | on | — | Label every generate block |
|
||||
| [`generate-label-prefix`](#generate-label-prefix) | style | on | — | Prefix that label `g_` or `gen_` |
|
||||
| [`interface-name-style`](#interface-name-style) | style | on | — | Name interfaces `lower_snake_case` ending `_if` |
|
||||
| [`line-length`](#line-length) | style | on | — | Keep lines within the configured width |
|
||||
| [`macro-name-style`](#macro-name-style) | style | on | — | Name macros `ALL_CAPS` |
|
||||
| [`one-module-per-file`](#one-module-per-file) | style | off | — | Declare one module per file |
|
||||
| [`package-filename`](#package-filename) | style | on | — | Match one-package files to package names |
|
||||
| [`parameter-type-name-style`](#parameter-type-name-style) | style | off | — | Name `type` parameters `lower_snake_case` ending `_t` |
|
||||
| [`port-name-suffix`](#port-name-suffix) | style | off | — | Say a port's direction in its name |
|
||||
| [`posix-eof`](#posix-eof) | style | on | safe | End the file with a newline |
|
||||
| [`signal-name-style`](#signal-name-style) | style | off | — | Name signals `lower_snake_case` |
|
||||
| [`typedef-enums`](#typedef-enums) | style | on | — | Name an `enum` type with a `typedef` |
|
||||
| [`typedef-structs-unions`](#typedef-structs-unions) | style | on | — | Name a `struct`/`union` type with a `typedef` |
|
||||
| [`always-comb-blocking`](#always-comb-blocking) | warning | on | — | Use `=` inside `always_comb` |
|
||||
| [`always-ff-non-blocking`](#always-ff-non-blocking) | warning | on | — | Use `<=` inside `always_ff` |
|
||||
| [`case-missing-default`](#case-missing-default) | warning | on | — | Give every case a default branch |
|
||||
@@ -195,3 +223,75 @@ Reports a `.name(…)` connection naming a port the instantiated module does not
|
||||
## void-cast
|
||||
|
||||
Reports `void'(…)` around something that is not a call, where there is no return value to discard — the missing call, or the cast left over from an edit. Verible's `void-cast` forbids a *named list* of calls instead, so the two do not overlap; the named-call form is wave 2's business. Only a cast standing as a statement is judged.
|
||||
|
||||
## always-comb
|
||||
|
||||
Reports `always @*` and `always @(*)`, which SystemVerilog spells `always_comb`. The keyword is checked by the tool — a second driver of the block's outputs becomes an error, and the inferred sensitivity list reaches into the functions the block calls. Verible enables its rule of the same name by default. The fix is offered but **unsafe**: `always_comb` runs once at time zero and `always @*` does not, so a testbench that samples before the first change can see a different value.
|
||||
|
||||
## banned-declared-name-patterns
|
||||
|
||||
Reports a declared name matching one of the patterns in the `patterns` option, which is empty by default — the rule is a place for a project to point at its own list (a deprecated prefix, a vendor's namespace, the `tmp` a review keeps catching). Every declared name is judged: modules, packages, types, parameters, signals, ports, instances, labels. A pattern must match the whole name.
|
||||
|
||||
## constraint-name-style
|
||||
|
||||
Reports a `constraint` whose name does not match `([a-z0-9]+_)+c` (the `pattern` option) — the shape Verible enables by default. A constraint's name is what a test turns off with `constraint_mode(0)`, so it is read far from its declaration.
|
||||
|
||||
## explicit-begin
|
||||
|
||||
Reports a body that is a single statement rather than a `begin ... end` block, for eleven constructs each with its own `*_enable` option (`if_enable`, `else_enable`, `always_ff_enable`, …), all on when the rule is. Off by default here as in Verible: the style is far from universal, and a codebase that did not start with it cannot adopt it one line at a time. An `else if` chain is never reported. The safe fix wraps the body; run the formatter afterwards to lay it out.
|
||||
|
||||
## forbid-consecutive-null-statements
|
||||
|
||||
Reports a null statement whose preceding token is a `;` — the `;;` an edit leaves behind, and the statement twin of `empty-item`. The empty header of `for (;;)` is not a statement and is never reported. The safe fix deletes the extra `;`.
|
||||
|
||||
## generate-label
|
||||
|
||||
Reports a generate `begin` with no `: label`. An unlabelled block still gets a name (`genblk3`), and that invented name is what appears in every hierarchical path — and it renumbers the moment a block is added above it. Silent in a file that does not fully parse: error recovery can rebind a procedural `begin` as a generate one, which on opentitan accounted for 177 of 180 findings before the guard was added.
|
||||
|
||||
## generate-label-prefix
|
||||
|
||||
Reports a generate label that starts with none of the `prefix` option's entries, `g_` and `gen_` by default. The prefix is what makes the generate levels of a hierarchical path visible. An empty list accepts every label while `generate-label` still requires there to be one.
|
||||
|
||||
## interface-name-style
|
||||
|
||||
Reports an `interface` whose name does not match `[a-z_0-9]+(_if)` (the `style_regex` option) — Verible's default pattern. Nothing in the syntax says an identifier is an interface rather than a module or a class; the suffix does.
|
||||
|
||||
## line-length
|
||||
|
||||
Reports a line wider than the limit — by default **the width the formatter is configured with for that file**, so the two halves of lucisv cannot disagree; the `length` option overrides it. The check is token-aware, as Verible's is: a line holding one unbreakable token (a long string, an `` `include`` path, a macro invocation) is left alone, because no wrapping could shorten it. There is no fix — where to break a line is what the formatter is for.
|
||||
|
||||
## macro-name-style
|
||||
|
||||
Reports a `` `define`` whose name does not match `[A-Z_0-9]+` (the `style_regex` option). A macro obeys no scope and can rewrite the code around its use, which is why every language that has them marks them by case. Only the definition is judged, never the uses.
|
||||
|
||||
## one-module-per-file
|
||||
|
||||
Reports every `module` after the first in a file. Off by default, as in Verible: plenty of real RTL keeps small helper modules beside the one the file is named for. An `interface`, a `program` and a `package` are not modules. Silent in a file that does not fully parse, where recovery can promote a nested declaration to file scope.
|
||||
|
||||
## package-filename
|
||||
|
||||
Reports a one-package file whose name matches neither the package (`foo.sv`) nor the package with a `_pkg` suffix (`foo_pkg.sv`), the two spellings the industry writes. The `allow-dash-for-underscore` option accepts `foo-pkg.sv` as well. Silent for stdin and for a file that does not fully parse; renaming a file is not the linter's business, so there is no fix.
|
||||
|
||||
## parameter-type-name-style
|
||||
|
||||
Reports a `type` parameter whose name does not match `[a-z][a-z_0-9]*_t` (the `style_regex` option). A type parameter is a type, and naming it `T` makes a declaration read like an expression. Off by default here as in Verible: `#(type T = int)` is near-universal in UVM code.
|
||||
|
||||
## port-name-suffix
|
||||
|
||||
Reports a port whose name does not end in the suffix for its direction — `_i`/`_ni` for an input, `_o`/`_no` for an output, `_io`/`_nio` for an `inout`, where the `n` marks active-low. The `suffixes` option is the accepted list; one of the six known suffixes is accepted only for its own direction, and anything else a project adds is accepted for any. Off by default: a codebase cannot adopt the convention one port at a time.
|
||||
|
||||
## posix-eof
|
||||
|
||||
Reports a file whose last line has no newline — formally, a file with no last line: `wc -l` counts short, and the next edit's diff shows the final line twice. The safe fix appends the newline. An empty file is left alone.
|
||||
|
||||
## signal-name-style
|
||||
|
||||
Reports a net, variable or port inside a module, interface or program whose name does not match `[a-z_0-9]+` (the `style_regex` option). Off by default here as in Verible: switching it on for an existing codebase reports thousands of findings on the first run, which is a project's decision. Class properties, `parameter`s and subroutine locals are other rules' business, or nobody's.
|
||||
|
||||
## typedef-enums
|
||||
|
||||
Reports a declaration whose type is an anonymous `enum`. The language gives no way to name such a type afterwards: a function cannot take it, a port cannot carry it, and two variables declared with the same member list are different types to the compiler.
|
||||
|
||||
## typedef-structs-unions
|
||||
|
||||
Reports a declaration whose type is an anonymous `struct` or `union`, for the reasons `typedef-enums` gives. The `allow_anonymous_nested` option (true by default here — Verible defaults it to false) exempts an aggregate written inside another aggregate's body — which is what auto-generated register packages are made of: on opentitan `hw/`, all 3 159 findings are nested structs inside a `typedef` in 57 `reggen`-generated files, and opentitan's own Verible config disables the rule with the comment "we allow nested struct definitions". One option, or one `ignore`, expresses the same choice here.
|
||||
Reference in new issue
Block a user