TODO section 24, coverage_gaps M7 via topo 2.9-6 and 2.9-4. unused-signal, undriven-net and multiply-driven shipped off because a per-file analysis cannot see a signal read or driven from another file's hierarchy. The index now carries a per-file identifier census - FileFacts::words, FACTS_FORMAT 12 -> 13, one harvest lifted from the server's completion candidates and now feeding them back from the store instead of re-lexing every file at startup (scan -28 percent) - and the linter gains a MentionOracle: unused-signal and undriven-net say nothing when the name is mentioned in any other indexed file, the false-negative-safe direction; multiply-driven shares the gate but never reads it. The three are on wherever an oracle exists (the editor always, the CLI when it walks a project) and off for a single file or stdin. With them, the missing off switch: [lint] select/ignore in lucisv.toml with CLI flags winning key by key, and lucisv.lint.select/ignore in the editor. QA's finding, reworked: the census dropped macro invocations whole, so a signal named only inside `uvm_info(..., dut.sig) was not silenced; the harvest now splits macro, directive and attribute words, skipping double-quoted runs so a "%d" cannot silence a signal named d project-wide, with workspace-defined macro names filtered out of the completion table at the reader. Store +16.9 percent corpus / +15.0 percent opentitan, measured. Corpus unused-signal 52 -> 44 and undriven-net 3 -> 0 with every silencing hand-checked, nothing added; opentitan - lint-clean under its own tools - 14 findings, all classified true against the whole repo. Also: the docs-site rules page gains the empty-item row it lacked. docs/features/semantic-lints-on/README.md. Co-Authored-By: Claude Fable 5 <[email protected]>
613 lines
34 KiB
Markdown
613 lines
34 KiB
Markdown
# linter-core
|
||
|
||
## Goal
|
||
|
||
Give lucisv a linter — the `vlog_linter` crate and the `lucisv check` subcommand —
|
||
built ruff-style from day one (a rule registry over a shared parse, violations
|
||
that may carry fixes classified *safe* or *unsafe*, `--select`/`--ignore`, JSON
|
||
output) with Verible's rule ergonomics (stable kebab-case names, a style-guide
|
||
rationale per rule, inline waivers). This round ships the engine, seven seed
|
||
rules and the CLI wiring; the rules deliberately stay **syntactic**, per
|
||
TODO.md §7, because semantic rules wait on `vlog_semantic`. The formatter is
|
||
untouched: a bare `lucisv <paths>` behaves exactly as it did before subcommands
|
||
existed.
|
||
|
||
## Assumptions
|
||
|
||
- **Tolerant parse, partial results.** `LintContext` parses with
|
||
`parse_source_tolerant`, so a file the formatter would refuse is still
|
||
linted. Unparsable regions become `Error` leaves that no AST rule matches —
|
||
findings from a broken file are a subset of what a fixed file would report,
|
||
never a superset. Text/token rules are unaffected.
|
||
- **A lex error leaves no tokens.** The lexer is all-or-nothing, so an
|
||
unterminated block comment means no waivers are seen in that file (they live
|
||
on tokens). Text rules still run. This is rare enough not to warrant a
|
||
tolerant lexer.
|
||
- **Waivers key on the line a diagnostic points at**, not on the whole extent
|
||
of a multi-line construct. Waiving a `case-missing-default` therefore goes on
|
||
the `case` line.
|
||
- **`case-missing-default` flags `unique`/`priority` case statements too.** The
|
||
qualifier is a promise to the tools, not a branch. Documented rather than
|
||
configurable; a waiver is the escape hatch.
|
||
- **`always-comb-blocking` only looks at `always_comb`**, not at `always @*`,
|
||
and `always-ff-non-blocking` only at `always_ff`. The SystemVerilog keywords
|
||
declare intent; `always @(posedge clk)` does not.
|
||
- **Whitespace inside a string literal is data.** `no-tabs` and
|
||
`no-trailing-whitespace` neither report nor rewrite a range that touches a
|
||
`TokenKind::String` span.
|
||
- **A tab expands to the run's indent width** (`--indent`, or the `indent` key
|
||
of the governing `lucisv.toml`, default 2) — one tab, one indent level.
|
||
- **`module-filename` speaks only for a file with exactly one top-level
|
||
module**, and never without a file name (stdin without `--stdin-filename`).
|
||
- **Verible waivers naming rules lucisv does not have are ignored, not
|
||
reported.** See Work log 2026-08-19 — this came out of the corpus baseline.
|
||
- **`// verilog_format: off` regions are reported but never auto-fixed.**
|
||
See "Fences" below; the linter reads fenced ranges through
|
||
`vlog_formatter::fence`, so what counts as fenced is the formatter's answer,
|
||
widened by a conservative line scan for files that do not parse.
|
||
|
||
## Handshakes
|
||
|
||
**Consumed**
|
||
|
||
- `vlog_parser`: `parse_source_tolerant`, `tokenize`, `LineIndex`, `TextRange`,
|
||
`ast::*`, `token::{Token, Comment, TokenKind}`. The linter reads the AST and
|
||
the token stream and mutates neither. It relies on: node/`Meta` spans being
|
||
code extents (`docs/features/spans/README.md`), name spans matching the text
|
||
(`name-spans`), comments being reachable from tokens as leading/trailing
|
||
trivia, and `Error` leaves being opaque (`error-recovery`).
|
||
- `vlog_formatter::Config`: only `indent_width`, and only as the tab-expansion
|
||
width. The linter does not format.
|
||
- `vlog_formatter::fence` (`collect`, `fence_of`, `Fence`, `Region` and its
|
||
fields) — read by `crates/lucisv/src/lint.rs` to keep `--fix` out of fenced
|
||
regions. All of it was **already `pub`**, so no visibility change was needed
|
||
in `vlog_formatter`; nothing in that crate was modified. If `fence::collect`
|
||
ever narrows its region for the formatter's own reasons, `--fix` narrows
|
||
with it — that coupling is deliberate: one answer to "what is fenced", not
|
||
two. Note the linter passes a **tolerant** tree to `collect`, which handles
|
||
`Error` leaves without panicking (verified live, and by the fences QA round).
|
||
- `crates/lucisv`: the walk, `--exclude`, `.gitignore` and config discovery are
|
||
reused unchanged — `check` is handed the same `(path, Config)` job list
|
||
`format` builds, and the same worker pool.
|
||
|
||
**Promised**
|
||
|
||
- `vlog_linter`'s public API is `Rule`, `LintContext`, `Violation`, `Fix`,
|
||
`Applicability`, `Fixed`, `run`, `lint`, `apply_fixes`, `all_rules`,
|
||
`default_rules`, `rule_by_name`, `select_rules`, `UNUSED_WAIVER`. Rule
|
||
*names* are the stable part: they appear in waivers in user source, so a
|
||
rename is a breaking change to other people's files.
|
||
`LintContext` grew two methods in the `semantic-lints` round —
|
||
`semantics()` (the file's symbol table, analyzed on first use) and
|
||
`with_semantics()` (a caller lending its own) — both additive;
|
||
`from_parse`'s signature did not change.
|
||
`semantic-lints-on` (2026-09-02) added `MentionOracle`,
|
||
`LintContext::{with_oracle, mentioned_elsewhere, has_oracle}`,
|
||
`ParsedSource::tokens()`, `Rule::needs_workspace()`, `workspace_rules()` and
|
||
a re-export of `vlog_semantic::words`. `default_rules()` kept its signature
|
||
and its meaning (the set for a run that cannot see other files);
|
||
**`select_rules` gained a third parameter**, `workspace: bool`, the round's
|
||
one breaking change.
|
||
- `run(source, path, enabled)` never panics on any input and never writes
|
||
anything; `LintContext::new` never fails.
|
||
- Findings come back sorted by `(span.start, span.end, rule)`.
|
||
- The exit-code contract of `lucisv check` mirrors the frozen formatter one:
|
||
0 clean, 1 violations remain, 2 error.
|
||
|
||
**Requested of others (not done here)**
|
||
|
||
- *config-discovery's owner*: a `lint = [...]` / `[lint]` section in
|
||
`lucisv.toml` (selected rules, per-rule settings) is out of scope this round —
|
||
rule selection is CLI-only (`--select` / `--ignore`). When that key lands,
|
||
`Options::select`/`ignore` should gain the same "CLI flag > config file"
|
||
precedence the formatter settings have, and `select_rules` already takes the
|
||
two lists it would feed.
|
||
**Half-delivered 2026-09-02 by `semantic-lints-on`**: `[lint] select` /
|
||
`ignore` in `lucisv.toml` (per file, CLI-over-config key by key, exactly the
|
||
ladder predicted here), plus `lucisv.lint.select` / `lucisv.lint.ignore`
|
||
settings so the language server has a selection surface at all. Per-rule
|
||
settings (`[lint.<rule>]`) are still open, and the parser now names them in
|
||
its error rather than ignoring them.
|
||
- *whoever unifies the pipelines*: `check` re-parses. TODO §4's "one parse, two
|
||
tools" is **not** done; `check` and `format` each call the parser. Nothing in
|
||
this crate's API prevents sharing a parse later — `LintContext` is the only
|
||
thing that would need to accept a pre-built tree.
|
||
~~is **not** done~~ **Delivered by one-parse (round 19):
|
||
`LintContext::from_parse` accepts pre-built products, `ParsedSource::parse`
|
||
is the parse-once bundle, and both `lucisv check` and the server lint from
|
||
one parse — see `docs/features/one-parse/README.md`.**
|
||
|
||
## Status / TODO
|
||
|
||
- [x] Crate `crates/vlog_linter` (deps: `vlog_parser` + std only).
|
||
- [x] `Rule` trait: `name` / `summary` / `doc` / `check(&LintContext)`.
|
||
- [x] `LintContext`: source, tokens, tolerant AST, `LineIndex`,
|
||
`Option<PathBuf>`, tab width, string-literal spans.
|
||
- [x] `Violation { rule, message, span, fix: Option<Fix> }`,
|
||
`Fix { edits, applicability }`, `Applicability::{Safe, Unsafe}`.
|
||
- [x] `apply_fixes` — left-to-right, overlapping fixes skipped, all-or-nothing
|
||
per fix.
|
||
- [x] Registry: `all_rules`, `default_rules`, `rule_by_name`, `select_rules`.
|
||
- [x] Inline waivers: `waive`, `waive-start`/`waive-stop`, `lucisv:` and
|
||
`verilog_lint:` spellings.
|
||
- [x] `unused-waiver` pseudo-rule (unused, unknown-rule, malformed,
|
||
unmatched `waive-stop`), itself waivable and ignorable.
|
||
- [x] Seed rules: `no-tabs`, `no-trailing-whitespace`, `case-missing-default`,
|
||
`always-ff-non-blocking`, `always-comb-blocking`,
|
||
`explicit-parameter-storage-type`, `module-filename`.
|
||
- [x] `lucisv check` wiring, `lucisv format` alias, backward-compatible bare
|
||
invocation.
|
||
- [x] `--output-format json`, `--select`, `--ignore`, `--fix`,
|
||
`--unsafe-fixes` (plumbed; no unsafe fix exists yet).
|
||
- [x] Inline-marker rule tests + CLI integration tests + corpus baseline.
|
||
- [x] `--fix` never edits bytes inside a `// verilog_format: off` region
|
||
(QA finding, 2026-08-19).
|
||
- [ ] External waiver files (`waive --rule=X --line=N --location=glob`) — out
|
||
of scope this round; needs a file format, a discovery rule and a
|
||
precedence story against inline waivers.
|
||
- [ ] `lint` config key in `lucisv.toml` — handshake above.
|
||
- [x] One parse shared by `check` and `format` — handshake above.
|
||
**Delivered by one-parse (round 19)** for the linter's consumers;
|
||
`format` keeps its own strict parse by design.
|
||
- [ ] Naming rules by regex, `--generate_markdown` rule reference, `--explain`
|
||
(`Rule::doc` exists so these can be generated, but nothing generates
|
||
them yet).
|
||
|
||
## Rules and the corpus baseline
|
||
|
||
Run over the 860-file corpus (`corpus/`: ibex, opentitan, picorv32,
|
||
common_cells), read-only, 0.09 s wall on 10 cores:
|
||
|
||
| Rule | Fix | Violations | Files |
|
||
|---|---|---|---|
|
||
| `no-tabs` | Safe | 7527 | 45 |
|
||
| `explicit-parameter-storage-type` | — | 107 | 51 |
|
||
| `no-trailing-whitespace` | Safe | 85 | 7 |
|
||
| `case-missing-default` | — | 66 | 22 |
|
||
| `module-filename` | — | 17 | 17 |
|
||
| `always-ff-non-blocking` | — | 4 | 1 |
|
||
| `always-comb-blocking` | — | 0 | 0 |
|
||
| `unused-waiver` | — | 0 | 0 |
|
||
| **total** | | **7806** | **93** |
|
||
|
||
Honest reading of that table:
|
||
|
||
- `no-tabs` dominates exactly as expected, and it is concentrated, not spread:
|
||
2590 of the 7527 are one file (`picorv32/picorv32.v`), and 45 of 860 files
|
||
account for all of them. `--fix` clears the whole category.
|
||
- `always-comb-blocking` scoring zero is not suspicious — `<=` in an
|
||
`always_comb` is a real bug, and this corpus is good code.
|
||
- `unused-waiver` scored **14 before** the Verible-spelling decision below and
|
||
0 after; every one was `// verilog_lint: waive macro-name-style` in ibex's
|
||
vendored lowRISC code.
|
||
- No file errored: the tolerant parse means even the 40 % of the corpus lucisv
|
||
cannot fully parse still gets linted for what it can see. That is also the
|
||
caveat — AST-rule counts above are a **lower bound**.
|
||
|
||
**Rules added since.** The table above is this round's eight; `lint-rules-2`
|
||
added five naming/SV-ness rules and `semantic-lints` three more. The default
|
||
run's total moved to **7932 over 106 files** with the naming rules. The three
|
||
semantic rules shipped off and, since `semantic-lints-on` (2026-09-02), are
|
||
**on wherever the run can see the project**:
|
||
|
||
| Rule | Default | Fix | Violations (`--select`, v0.29.0) | Default run, 2026-09-02 |
|
||
|---|---|---|---|---|
|
||
| `unused-signal` | on (project) | — | 52 in 10 files | 44 in 7 files |
|
||
| `undriven-net` | on (project) | — | 3 in 2 files | 0 |
|
||
| `multiply-driven` | on (project) | — | 0 | 0 |
|
||
|
||
"on (project)" is `Rule::needs_workspace()`: the rule runs on a plain
|
||
`lucisv check` over more than one file, or in the language server, and stays
|
||
off for a single file or a stdin buffer. All three read the symbol table
|
||
rather than the syntax tree; the two that can be wrong about a cross-file use
|
||
also consult a `MentionOracle` and say nothing about a name any other file
|
||
writes down, which is what took the default-run corpus total from 55 to 44
|
||
without adding a single finding. The per-finding judgement is in
|
||
`docs/features/semantic-lints/README.md`; the census, the flip and the
|
||
before/after numbers are in `docs/features/semantic-lints-on/README.md`. The
|
||
whole-corpus default run is now **7976 over 110 files**.
|
||
|
||
## Waiver semantics as implemented
|
||
|
||
```systemverilog
|
||
wire a; // lucisv: waive no-tabs suppresses that rule on this line
|
||
// lucisv: waive no-tabs alone on its line: suppresses the NEXT line
|
||
// lucisv: waive-start no-tabs ... from this line
|
||
// lucisv: waive-stop no-tabs ... through this one, both included
|
||
```
|
||
|
||
- `verilog_lint:` is accepted everywhere `lucisv:` is.
|
||
- Exactly one rule name per waiver; anything else is `unused-waiver:
|
||
malformed`. A comment that does not start with one of the two prefixes plus
|
||
a `waive*` keyword is an ordinary comment (`// lucisv: off` stays a format
|
||
fence).
|
||
- Ranges nest per rule; the innermost open `waive-start` for a rule is what a
|
||
`waive-stop` closes. An unclosed `waive-start` runs to the end of the file
|
||
(the format fences' rule). A `waive-stop` with nothing open is reported.
|
||
- A waiver whose rule this run did not enable is silent — with `--select
|
||
no-tabs`, waivers for other rules are not "unused", they simply had no
|
||
chance to fire.
|
||
- A `verilog_lint:` waiver naming a rule lucisv does not implement is ignored
|
||
silently; the same waiver written `lucisv:` is reported as naming an unknown
|
||
rule. A codebase annotated for Verible is lintable by lucisv without editing
|
||
it first, while typos in lucisv's own waivers still surface.
|
||
- `unused-waiver` findings can themselves be waived, and the derivation loops
|
||
until the used-set stops growing so waiving one does not leave the waiver
|
||
that did it reported as unused.
|
||
- **External waiver files are not implemented.**
|
||
|
||
## Fences: reported, never auto-fixed
|
||
|
||
A `// verilog_format: off` / `// lucisv: off` region is emitted by the formatter
|
||
as the exact source bytes it was written with — hand-aligned tables are the
|
||
reason the fence exists. `lucisv check` therefore **reports** violations inside a
|
||
fenced region (a finding is information, and `--select`/`--ignore`/waivers are
|
||
the ways to silence one) but **never fixes** them: `--fix` drops any fix whose
|
||
edits intersect a fenced range, leaving those violations reported and the exit
|
||
code at 1. "Off" means hands-off for both tools, not just the formatter.
|
||
|
||
Fenced ranges come from two sources, unioned:
|
||
|
||
1. `vlog_formatter::fence::collect` — the formatter's own item-scoped answer,
|
||
authoritative wherever the tree is good. The protected range is the whole
|
||
`Region::start .. Region::end` the formatter would emit verbatim, the fence
|
||
line's own indentation included.
|
||
2. A line scan using `fence::fence_of` (the same grammar), pairing each `off`
|
||
with the next `on` or the end of the file. This is the backstop for the
|
||
files only the linter sees: error recovery can swallow the item structure a
|
||
region hangs on, and `collect` then reports nothing at all — measured, not
|
||
assumed. It can protect slightly more than the formatter emits verbatim,
|
||
and would be fooled by a fence spelled inside a block comment; both err
|
||
toward declining a fix, which is the harmless direction.
|
||
|
||
An insertion (an empty edit range) inside a region is blocked too, so nothing
|
||
can be spliced in. A fix is all-or-nothing, so one edit landing inside a fence
|
||
blocks that whole fix — never half of it.
|
||
|
||
## Fix model
|
||
|
||
ruff's, verbatim in spirit:
|
||
|
||
- `Fix { edits: Vec<(TextRange, String)>, applicability: Safe | Unsafe }`.
|
||
Safe = cannot change what the code means (whitespace); Unsafe = may.
|
||
- `--fix` applies Safe fixes; `--unsafe-fixes` (with `--fix`) widens to both.
|
||
**No rule ships an Unsafe fix yet** — the flag is plumbed and tested so the
|
||
first one does not have to touch the CLI. `always-*-blocking` are the
|
||
obvious candidates and were deliberately left fixless: swapping `=` for `<=`
|
||
changes the circuit.
|
||
- A fix is all-or-nothing; its edits are applied together or not at all.
|
||
- Within one pass, a fix overlapping one already applied is skipped rather
|
||
than merged, so a pass can never garble text. `lucisv check --fix` therefore
|
||
loops (fix → re-lint) until nothing changes, capped at 10 rounds. The
|
||
everyday case needing two rounds is a line ending in a tab: `no-tabs` and
|
||
`no-trailing-whitespace` both want those bytes.
|
||
- A fix inside a `// verilog_format: off` region is never applied — see
|
||
Fences above.
|
||
- Fixed output re-lints clean for the fixed rules — asserted in
|
||
`crates/vlog_linter/src/lib.rs` (`fixing_leaves_the_file_clean_for_the_fixed_rules`)
|
||
and end to end in `crates/lucisv/tests/cli.rs`
|
||
(`check_fix_rewrites_the_file_and_the_result_relints_clean`).
|
||
|
||
## CLI surface
|
||
|
||
```
|
||
lucisv check [OPTIONS] <file|dir>... lint
|
||
lucisv format [OPTIONS] <file|dir>... format (alias for the bare invocation)
|
||
lucisv [OPTIONS] <file|dir>... format — unchanged
|
||
```
|
||
|
||
The subcommand word is read **only as the first argument**. Everything else is
|
||
inputs and flags exactly as before, so `lucisv --check rtl/` is still the
|
||
formatter's check mode. A file named `check` can be formatted as
|
||
`lucisv format check`.
|
||
|
||
`check`-only flags: `--select RULES`, `--ignore RULES` (comma-separated,
|
||
repeatable), `--output-format text|json`, `--fix`, `--unsafe-fixes`. Using one
|
||
of them without `check` is an error, as is `--check`/`--diff`/`--stdout` with
|
||
it. `--indent`, `--exclude`, `--threads`, `--no-config`, `--no-gitignore`,
|
||
`--stdin-filename` and `-` work for both.
|
||
|
||
Text output is Verible's line, sorted by file then position:
|
||
|
||
```
|
||
rtl/bar.sv:2:1: tab character; indent with spaces [no-tabs]
|
||
```
|
||
|
||
JSON is one array on stdout (errors stay on stderr, so the array is always
|
||
parsable), each element:
|
||
|
||
```json
|
||
{"filename":"rtl/bar.sv","rule":"no-tabs","message":"...",
|
||
"location":{"line":2,"column":1},"end_location":{"line":2,"column":2},
|
||
"range":{"start":11,"end":12},
|
||
"fix":{"applicability":"safe","edits":[{"start":11,"end":12,"content":" "}]}}
|
||
```
|
||
|
||
`fix` is `null` when the rule offers none. Serialization is hand-rolled (~30
|
||
lines): the shape is three fields deep, and no serialization crate is a
|
||
dependency of this crate or of `lucisv`.
|
||
|
||
Exit codes: **0** clean (or everything fixed), **1** violations remain, **2**
|
||
error (bad arguments, unknown rule, unreadable file). An error outranks
|
||
violations, as in the formatter.
|
||
|
||
## Work log
|
||
|
||
### 2026-08-19 — dev
|
||
|
||
- Created `crates/vlog_linter` (files first, workspace member after — the
|
||
ordering that bit a previous round) with `vlog_parser` + std only. Added
|
||
`crates/vlog_linter` to the root `members` list additively, leaving the
|
||
concurrent `lucisv_server` entries and workspace deps untouched.
|
||
- Modules: `violation` (Violation/Fix/Applicability/apply_fixes), `context`
|
||
(LintContext), `visit` (item/statement walks), `registry` (Rule trait +
|
||
tables + selection), `waiver`, `rules/` (one file per rule).
|
||
- **Design decisions**
|
||
- `all_rules()` returns `Vec<&'static dyn Rule>` over unit structs. Boring,
|
||
no macro, no inventory crate; the cost is one `Vec` allocation per call.
|
||
- `unused-waiver` is a **registry entry with an empty `check`** rather than
|
||
a special case outside the rule set. That way `--select`/`--ignore`,
|
||
waivers and the rule reference all treat it like any other rule; the
|
||
findings come from the waiver engine.
|
||
- One `no-tabs` finding per *line*, not per tab, with the fix covering every
|
||
tab on that line — otherwise a tab-indented file reports thousands of
|
||
identical diagnostics (picorv32.v alone would have been far noisier).
|
||
- The tab-expansion width is `Config::indent_width`, so `--indent 4` fixes
|
||
tabs to four spaces. This is the only thing the linter takes from the
|
||
formatter's config.
|
||
- Rules skip ranges touching a string literal. Rewriting a tab inside
|
||
`"a\tb"` would change data, which no "safe" fix may do.
|
||
- `apply_fixes` skips overlapping fixes instead of trying to merge them, and
|
||
the CLI loops. Simpler to reason about and provably non-garbling.
|
||
- **Corpus finding that changed a decision.** The first baseline reported 14
|
||
`unused-waiver` violations, all of them `// verilog_lint: waive
|
||
macro-name-style` in vendored lowRISC code — i.e. correct Verible waivers
|
||
for a rule lucisv has not implemented. Reporting those punishes exactly the
|
||
codebases the `verilog_lint:` spelling exists to welcome. Changed so that an
|
||
unknown rule name is reported only for the `lucisv:` spelling; a
|
||
`verilog_lint:` waiver for a rule lucisv lacks is ignored. Corpus
|
||
`unused-waiver` count went 14 → 0, and a typo'd `// lucisv: waive` is still
|
||
caught. Tested by `a_verible_waiver_for_a_rule_lucisv_does_not_have_is_ignored`.
|
||
- CLI: `args.rs` gained `Command`/`OutputFormat`, the five check-only flags and
|
||
a scope check that rejects a flag used with the wrong tool; the subcommand is
|
||
only read as the first argument, which is what keeps every old command line
|
||
meaning what it did. New `crates/lucisv/src/lint.rs` holds the check driver
|
||
and reuses `gather`, `build_pool` and `catch_panic` from `main.rs`.
|
||
- Tests: 71 unit + 30 inline-marker integration tests in `vlog_linter`;
|
||
16 new CLI tests in `crates/lucisv/tests/cli.rs` (exit codes, JSON shape,
|
||
`--fix` round trip in a temp dir, waivers, stdin, walk reuse, and four
|
||
backward-compatibility tests including a byte-for-byte comparison of
|
||
`lucisv --check` against `lucisv format --check`).
|
||
- Gates: `cargo test -p vlog_linter` 71+30+1 green, `cargo test -p lucisv` 46
|
||
green, `cargo clippy -p vlog_linter -p lucisv --all-targets` silent,
|
||
`cargo fmt --all --check` clean. The workspace has three failing tests and
|
||
one clippy warning in `crates/lucisv_server`, which belongs to another agent's
|
||
concurrent round and does not depend on this crate.
|
||
- TODO.md §4: checked the rule trait/registry item, the diagnostic-format +
|
||
JSON item, the fix-applicability item, the waiver item (with the external
|
||
waiver files caveat spelled out) and the seed-rules item. Left "one parse,
|
||
two tools", naming rules and `--generate_markdown` unchecked.
|
||
|
||
### 2026-08-19 — dev (QA follow-up)
|
||
|
||
- **QA should-fix: `--fix` rewrote bytes inside `// lucisv: off` fences.** Fixed
|
||
per the lead's ruling: violations inside a fenced region are still reported,
|
||
but no fix that touches those bytes is applied. Implemented in
|
||
`crates/lucisv/src/lint.rs` (`fixable_outside_fences` / `touches_fence`), not
|
||
in `vlog_linter` — `lucisv` already depends on `vlog_formatter`, and doing it
|
||
here keeps the linter crate's dependency list at `vlog_parser` + std, which
|
||
is the property QA verified with `cargo tree`.
|
||
- **No visibility change was needed.** `fence::{collect, fence_of, Fence,
|
||
Region}` and `Region`'s fields are already `pub`; `crates/vlog_formatter`
|
||
was not modified at all. The lead's authorization went unused.
|
||
- **Verified the tolerant-parse question rather than assuming it.**
|
||
`fence::collect` takes the tolerant tree without panicking, as expected —
|
||
but on a file with a parse error *before* the fence, error recovery swallows
|
||
the item structure the region hangs on and `collect` returns **no region**,
|
||
so the first implementation still rewrote fenced bytes in exactly the files
|
||
only the linter sees. Added a second source: a line scan built on
|
||
`fence::fence_of` (the formatter's own grammar, so the fence spelling is not
|
||
duplicated), pairing `off` with the next `on` or EOF. The two are unioned;
|
||
the scan can protect marginally more than the formatter emits verbatim,
|
||
which only ever declines a fix.
|
||
- The protected range is `Region::start..Region::end` — the whole byte range
|
||
the formatter emits verbatim, not `region_at`'s `fence..end` — so the fence
|
||
line's own indentation is protected too. Empty (insertion) edit ranges are
|
||
treated as covering the byte they precede, so nothing can be spliced in.
|
||
- Tests: the QA repro as a CLI test
|
||
(`check_reports_inside_a_fence_but_never_fixes_there`: fenced line
|
||
byte-identical including tab and trailing run, unfenced line still fixed,
|
||
exit 1, and the two surviving findings both point into the fence),
|
||
`a_fence_holds_even_in_a_file_that_does_not_parse` (which also re-asserts
|
||
the formatter still exits 2 on it), plus six unit tests in `lint.rs`
|
||
covering the boundary cases the lead asked for — first byte inside, last
|
||
byte inside, adjacent-outside at both ends, straddling either edge,
|
||
insertions, multi-edit fixes, unclosed fences and non-fence comments.
|
||
- Corpus baseline re-run after the change: **7806 violations over 93 files**,
|
||
per-rule counts byte-identical to the table above (the corpus contains no
|
||
fences, so the filter is a no-op there — confirmed, not assumed).
|
||
- Gates after the change: `cargo test -p vlog_linter` 71+30+1,
|
||
`cargo test -p lucisv` 58 unit + 48 CLI, workspace green, clippy silent, fmt
|
||
clean.
|
||
|
||
## QA log
|
||
|
||
### 2026-08-19 — QA
|
||
|
||
Verified every claim in this README against the code, the gates, and a
|
||
live corpus run. All PASS unless noted; one should-fix finding below.
|
||
|
||
**Gates.** `cargo tree -p vlog_linter`: only `vlog_parser` (+ std),
|
||
matching the dependency claim. `cargo fmt --all --check` clean.
|
||
`cargo clippy -p vlog_linter -p lucisv --all-targets` silent on a forced
|
||
rebuild (touched `lib.rs` first to rule out a stale cache). No `unsafe`,
|
||
no `#[allow]`, and every `.unwrap()`/`.expect()` in the crate is inside a
|
||
`#[cfg(test)]` module (checked `crates/vlog_linter/src/**` and
|
||
`crates/lucisv/src/lint.rs` by hand) — CLAUDE.md's Rust standards hold.
|
||
`cargo test -p vlog_linter`: 71 unit + 30 integration + 1 doctest, green.
|
||
`cargo test -p lucisv`: 46 green. Counts match the work log exactly.
|
||
|
||
**Corpus baseline.** Release build, `lucisv check corpus/ --output-format
|
||
json`: **7806** violations over **93** files, byte-identical across
|
||
repeated runs and across `--threads 1` vs the default pool (fully
|
||
deterministic). Per-rule breakdown parsed from the JSON matches the
|
||
table exactly: no-tabs 7527/45, explicit-parameter-storage-type 107/51,
|
||
no-trailing-whitespace 85/7, case-missing-default 66/22,
|
||
module-filename 17/17, always-ff-non-blocking 4/1,
|
||
always-comb-blocking 0/0, unused-waiver 0/0. Wall time on this machine
|
||
was ~0.26s (vs. the documented 0.09s/10-cores) — different hardware, not
|
||
a discrepancy; determinism and counts are what matter and both check out.
|
||
|
||
**Rule attacks (crafted probes, not just the corpus).** All PASS:
|
||
- `no-tabs`: a tab inside a string is neither reported nor fixed; a tab
|
||
inside a *comment* is still reported (README only exempts string
|
||
literals — code and doc agree).
|
||
- `case-missing-default`: fires on plain `case`, `casez`, `priority
|
||
case`; silent when a `default` exists (including `unique case`); fires
|
||
on generate `case`; a `casez` nested inside an `always_comb` inside a
|
||
generate `begin` block is reached and flagged correctly.
|
||
- `always-ff-non-blocking` / `always-comb-blocking`: correctly flag a
|
||
blocking/non-blocking assignment 3 `begin` levels deep; a `for`-loop
|
||
header's `i++`/init is not mistaken for a flagged assignment, while a
|
||
real assignment inside the loop body is still caught; reached through
|
||
nested `generate if` blocks.
|
||
- `explicit-parameter-storage-type`: `parameter type T = int` and a
|
||
packed-dims-only `parameter [7:0] A` are both handled as documented
|
||
(the former clean, the latter flagged).
|
||
- `module-filename`: silent on a two-module file, silent on stdin with
|
||
no `--stdin-filename`, and a case-mismatch (`Foo.sv` vs `module foo`)
|
||
is flagged — reasonable default, not previously spelled out in the
|
||
README but not a bug.
|
||
- An all-garbage file (no valid tokens/syntax) and a file with an
|
||
unterminated block comment (lex failure) both lint without panicking;
|
||
the garbage file still catches a stray tab via the text rule.
|
||
|
||
**Waiver attacks.** All PASS, including the trickier ones:
|
||
- Two nested `waive-start no-tabs` followed by two `waive-stop no-tabs`:
|
||
the first stop closes the *inner* range, the second closes the outer
|
||
one, and a line covered only by the outer range (between the two
|
||
stops) stays suppressed — matches "innermost open start is what a
|
||
stop closes."
|
||
- `waive-stop` with no matching start → reported, message contains "no
|
||
matching".
|
||
- A waiver for a rule dropped by `--ignore` is silent (0 findings, exit
|
||
0) — confirmed with `--ignore no-tabs --select no-tabs,unused-waiver`.
|
||
- `verilog_lint: waive <rule lucisv lacks>` → silent; the same spelled
|
||
`lucisv:` → reported unknown-rule. Both confirmed live via the CLI, not
|
||
just the unit tests.
|
||
- `unused-waiver` waiving itself → no findings at all (fixed-point
|
||
derivation works). `--select unused-waiver` alone still catches an
|
||
unknown-rule waiver with no other rules running.
|
||
|
||
**Fix engine.** All PASS:
|
||
- A line with a tab that is also trailing whitespace (`\twire a;\t\n`)
|
||
needs the documented two rounds; `--fix` converges and the result
|
||
relints clean for `no-tabs`/`no-trailing-whitespace`.
|
||
- `--fix` on a file that also has an unfixable violation
|
||
(`module-filename`) fixes what it can, leaves the rest reported, exits
|
||
1.
|
||
- `check --fix --check` is rejected (`--check is not valid for
|
||
\`lucisv check\``), confirming `--check` stays a formatter-only flag.
|
||
- A second `--fix` run on an already-fixed-as-far-as-possible file is a
|
||
no-op for fixing (0 additional applied) and exit code reflects only
|
||
the remaining unfixable violation.
|
||
- No rule in `crates/vlog_linter/src/rules/*.rs` calls
|
||
`Fix::unsafe_fix`/uses `Applicability::Unsafe` — confirmed by grep —
|
||
so `--unsafe-fixes` changing nothing today is accurate, not just
|
||
claimed.
|
||
|
||
**Should-fix finding — `--fix` does not respect `// lucisv: off` fences.**
|
||
`crates/lucisv/src/lint.rs` (`run_rules`/`fix_source`) builds a
|
||
`LintContext` straight from the raw source and never consults
|
||
`fence.rs`; `crate::vlog_linter` has no notion of fences at all (its
|
||
`Cargo.toml` doesn't even depend on `vlog_formatter` beyond the
|
||
`Config::indent_width` handshake noted in this README). Repro: a file
|
||
with `// lucisv: off` around a tab-and-trailing-whitespace line — `lucisv
|
||
check` reports `no-tabs` and `no-trailing-whitespace` *inside* the
|
||
fenced region, and `lucisv check --fix` rewrites it, while `lucisv format`
|
||
(the formatter) leaves the same region byte-for-byte untouched by
|
||
design. This does not corrupt code (the rewrite is a Safe,
|
||
meaning-preserving one) and does not break any hard invariant, but it
|
||
violates the fence's whole premise — a user who wrote `// lucisv: off`
|
||
expecting hands-off code gets it silently edited by `check --fix`. Not
|
||
mentioned anywhere in this README (the one `// lucisv: off` reference,
|
||
lines 162–163, only says the waiver *parser* treats it as an ordinary
|
||
comment, which is correct and unrelated to this). Recommend either (a)
|
||
`LintContext`/the fix/report path skip fenced ranges, matching the
|
||
formatter's contract, or (b) if the fenceless behavior is intentional,
|
||
document it explicitly in Assumptions and the CLI surface section so
|
||
users aren't surprised. Left unfixed by me — this is a design decision,
|
||
not a typo, and out of my QA-log-only write scope.
|
||
|
||
**JSON.** Valid per `python3 -c json.load` on every run above, including
|
||
a path with non-ASCII characters, embedded double quotes, and a space
|
||
in a directory name — round-tripped correctly. Empty-array case (`[]`)
|
||
confirmed on a clean file, exit 0.
|
||
|
||
**Backward compatibility.** Built the pre-round binary from a `git
|
||
worktree` at HEAD (`1ac9746`, before this round's uncommitted changes)
|
||
and compared `lucisv --check` over the full corpus against the new
|
||
binary: stdout byte-identical, stderr byte-identical (including the
|
||
same 359 parse-error lines and the same "488 files would be
|
||
reformatted, 13 files left unchanged, 359 files failed to format"
|
||
summary), same exit code (2). Also reconfirmed live that `lucisv --check`
|
||
and `lucisv format --check` are byte-identical on the new binary. The
|
||
linter changes did not perturb the formatter at all, as the README
|
||
promises.
|
||
|
||
**CLAUDE.md / TODO.md honesty.** `git diff HEAD -- TODO.md` shows §4's
|
||
sub-items checked/unchecked exactly as the work log claims: rule
|
||
trait/registry, diagnostic format, fix-applicability and the inline-
|
||
waiver sub-item are checked; the external-waiver-files sub-item, the
|
||
wire/reg-mixup sub-item, and "one parse, two tools" are left unchecked
|
||
with explanatory `→` notes rather than silently marked done. Top-level
|
||
`README.md`'s new Linting section matches this feature README's
|
||
behavior exactly, including the `--unsafe-fixes` "changes nothing yet"
|
||
caveat and the external-waiver-files gap. No files outside
|
||
`crates/vlog_linter`, the CLI wiring named in the task, and this QA log
|
||
were touched.
|
||
|
||
**Verdict.** No BLOCKING findings — no rule false-positive/negative on
|
||
any of the attacked shapes, no `--fix` corruption, no backward-compat
|
||
break. One should-fix finding (fences vs. `--fix`, above).
|
||
|
||
## Review
|
||
|
||
**2026-08-19 — lead. Verdict: accepted after one directed fix; commits
|
||
jointly with lucisv-server (round 11). `lucisv check` completes the ruff
|
||
analog.**
|
||
|
||
Points reviewed and accepted:
|
||
|
||
1. **The Verible-waiver asymmetry** is the round's best judgment call:
|
||
`verilog_lint:` waivers naming rules lucisv lacks are ignored, not
|
||
reported, because punishing them punishes exactly the vendored
|
||
codebases the compatibility spelling exists to welcome — while
|
||
typo'd `lucisv:` waivers still get caught. A design decision changed
|
||
by corpus evidence, recorded with the evidence.
|
||
2. **The fix engine's conservatism** (Safe/Unsafe from day one,
|
||
overlaps skipped not merged, fix→re-lint loop with a cap,
|
||
`always-*-blocking` deliberately fixless because swapping `=`/`<=`
|
||
changes the circuit) is the right posture for a tool whose sibling
|
||
formatter promises never to corrupt.
|
||
3. **The fence ruling** (violations reported inside `// lucisv: off`,
|
||
fixes never applied there) was implemented better than directed:
|
||
the dev discovered that `fence::collect` yields no regions on files
|
||
with a parse error before the fence — exactly the tolerant-parse
|
||
population only the linter sees — and built a union of the
|
||
authoritative tree regions and a scan backstop sharing the
|
||
formatter's own `fence_of` grammar, so the spelling can't drift.
|
||
Erring toward protecting more than the formatter emits verbatim
|
||
only ever declines a fix. Verified by the boundary test matrix and
|
||
a live lead probe (fenced bytes byte-identical, unfenced fix
|
||
applied, exit 1).
|
||
4. Backward compatibility proven at the byte level against a HEAD
|
||
worktree binary, and the corpus baseline (7806/93) reproduced
|
||
deterministically before and after the fence fix.
|
||
|
||
Honest remainders stay on TODO §4: external waiver files, naming
|
||
rules, markdown rule docs, wire/reg mixup (needs a SystemVerilog-ness
|
||
decision), and one-parse-two-tools (check re-parses today; only
|
||
LintContext changes when unified). The LSP server should surface lint
|
||
diagnostics in a future round — filed there as a natural follow-up.
|