Skip to content

fix(rules): length does not measure a table - #381

Merged
ngngardner merged 1 commit into
mainfrom
fix/length-table
Nov 14, 2026
Merged

ngngardner merged 1 commit into
mainfrom
fix/length-table

Conversation

@ngngardner

Copy link
Copy Markdown
Contributor

What

length (S010) no longer measures a table: a def whose body is one match with nothing under it but case arms, each holding at most one statement, which opens no block.

def glyph(c: U32) -> String:
  match c:
    case 65:
      ";N2R EG"
    case 66:
      ";N039>B? BHMQN"
    ...

Why

A table's length is how many cases there are. It has no step to move into a helper, which is what the finding asks for, so the one edit that silenced the rule was to cut the table in two at some line. That helps no reader, and it fails the honest-fix test src/README.md sets for a rule: the cheapest silencing edit must leave the code better.

Found by hand-reading a sample of what length reports in public code: of 8 defs read, 3 were tables (a lookup by constructor, a decoder per type code, a glyph per character). Counted over 82 public repos: length reported 116 defs in 31 repos, and 22 of them were tables. It now reports 94 in 28. Five of the 22 were read by hand after the change; all are dispatch or lookup tables.

bolt's own on.run carried # noqa: S010 a table, an arm a check. It is a table by this definition, so the suppression is gone (noqa reported it as silencing nothing).

What is still measured

A second statement in the body, a second statement in an arm, or a block in an arm makes a def no table. So a state machine whose arms bind and then call, a match nested in a match, and a long do block are all measured as before. arity and depth are unchanged.

depth was sampled too (12 findings, 8 distinct defs): 7 are nesting a helper or a match on two values at once would flatten, and one is not Bend 2 source. No change there.

Laws

laws/SizeReportsOversizedDefs.bend:

law kind
length_skips_table: length measures no lines of a table direct
length_measures_other_def: of a def that is no table it measures the lines, as before frame
table_needs_one_statement: a body of two statements or more is no table direct
table_stops_at_other_arm: arms after one that is no arm of a table are not the arms of one direct
table_arm_holds_no_block: an arm holding a statement that opens a block is no arm of a table direct
table_arm_holds_one_statement: an arm holding two statements or more is no arm of a table direct

size_counts (one finding per def over the limit, none for any other) holds as stated, since it is stated over the measure. No new trusted assumption. Still not proved, as before: that no comment or string changes a finding of these rules.

Behavior change

Yes: length reports fewer defs. A project with a # noqa: S010 on a table will see noqa (S005) report that suppression as silencing nothing.

Checks

bend PROOF.bend --check-only prints ALL PROOFS CHECK; self-lint is 0 errors (the 32 warnings main has); bolt fmt --check is clean; nix flake check passed before the rebase onto the formatter change, and proofs, lint and format check were run again after it.

🤖 Generated with Claude Code

https://claude.ai/code/session_0186KEnvWA9baj8X228HW9RU

A def whose body is one `match` with nothing under it but `case` arms,
each holding at most one statement, which opens no block, is a table: an
opcode dispatch, a glyph for each character. Its length is how many cases
there are. It has no step to move into a helper, so the one edit that
silenced `length` was to cut the table in two at some line, which helps
no reader; that fails the honest-fix test src/README.md sets for a rule.

`length` now measures no lines of a table. A second statement in the
body, a second statement in an arm, or a block in an arm makes a def no
table, and it is measured as before. `arity` and `depth` are unchanged.

Found by reading a sample of what `length` reports in public code: of 8
defs read, 3 were tables. Over the 82 public repos `length` reported 116
defs in 31; 22 of them were tables, and it now reports 94 in 28. bolt's
own `on.run`, which carried a `# noqa: S010 a table, an arm a check`, no
longer needs it.

laws/SizeReportsOversizedDefs.bend: `length_skips_table`,
`length_measures_other_def`, `table_needs_one_statement`,
`table_stops_at_other_arm`, `table_arm_holds_no_block` and
`table_arm_holds_one_statement` are new. `size_counts` holds as stated,
since it is stated over the measure.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186KEnvWA9baj8X228HW9RU
@ngngardner
ngngardner enabled auto-merge (squash) November 14, 2026 05:29
@ngngardner
ngngardner merged commit 5cd135e into main Nov 14, 2026
4 checks passed
@ngngardner
ngngardner deleted the fix/length-table branch November 14, 2026 05:34
ngngardner added a commit that referenced this pull request Nov 16, 2026
A def whose body is one `[..]` list of data and nothing else is a table,
as a `match` of one-statement arms is since #381: a generated list of
records, such as ezhttp's src/entities.bend `table` (the HTML Standard's
2231 named character references, 2234 lines). Its length is how many rows
there are, and the one edit that silenced `length` was to cut the list in
two at some line, which helps no reader.

Data is numbers, strings, chars, commas, capitalized and dotted names and
`[..]` and `{..}` groups of them. A plain lowercase name (a variable or a
call's head), an operator, a keyword, a `(..)` group, a token after the
list's `]` or a line under it makes the def no table, and it is measured
as before.

laws/SizeReportsOversizedDefs.bend: `table_takes_data_list`,
`table_list_needs_data`, `table_list_holds_nothing_under`,
`table_list_is_whole_statement`, `data_reads_token`, `data_reads_group`
and `data_rejects_statement` are new; the prose names the new table.
`length_skips_table` and `length_measures_other_def` hold as stated.

Co-authored-by: noah-emp <182041600+noah-emp@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants