CLAUDE.md: the file and function size rule — 300–600 production lines per file, split at 800, a reason above 1 200
ci / checks (push) Successful in 56s
ci / corpus (push) Successful in 25s

Set by the owner on 2026-09-02. Measured at the same time: thirteen
files over 800 production lines and eight over 1 200, led by
parser.rs (8 786), format.rs (5 444), ast.rs (3 313) and server.rs
(2 559 + 6 293 test) - the same files every feature lane collides in.
Decomposition is planned as TODO section 28: pure moves, public paths
kept by re-export, byte-identical output proven by the corpus and
opentitan gates.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-09-02 15:18:18 -07:00
1 parent c2f107444c
commit f3af34980a
1 file changed
+32
+32
View File
@@ -29,6 +29,38 @@ doing anything.
- Match the style of the surrounding code (comment density, naming,
module layout).
## File and function size
Files and functions are sized for a human reader, not a compiler.
- **Target 300–600 production lines per file.** At 800, consider
splitting. Above 1,200, an explicit reason not to split goes in the
feature README. Test lines do not count, but a `#[cfg(test)]` block
that dwarfs its file moves to its own module or `tests/` file.
- **Functions: 10–50 lines.** Investigate anything over 80; anything
over 150 needs a reason in a comment (a dispatch table over an enum
is the usual one).
- Looser for declarative tables, generated code, snapshots and
repetitive tests. Complexity matters more than the count: 800 lines
of grammar productions read more easily than 250 lines of state.
- **The real test is one sentence.** A human should be able to say what
a file is responsible for in one sentence and predict which parts a
change touches. Several "and" clauses mean the file wants to be
several modules.
- A split is a **pure move**: public paths stay the same (re-export from
the old `mod`), behaviour and output stay byte-identical, the test
count does not drop. Measured, not asserted — the corpus and
opentitan byte-identity gates are the proof.
Measured 2026-09-02 (production lines): `vlog_parser/src/parser.rs`
8 786, `vlog_formatter/src/format.rs` 5 444, `vlog_parser/src/ast.rs`
3 313, `lucisv_server/src/server.rs` 2 559 (+6 300 test),
`vlog_semantic/src/bind.rs` 2 378, `vlog_semantic/src/workspace.rs`
1 975, `vlog_refactor/src/ports.rs` 1 778,
`lucisv_server/src/completion.rs` 1 716 — thirteen files over 800.
These are decomposition work (TODO §28), and every one of them is where
feature lanes collide, which is the other reason to split them.
## Rust standards
- `cargo fmt` clean, `cargo clippy --all-targets` clean (no `#[allow]`