Repository navigation
fix(rules): length does not measure a table - #381
Merged
Merged
Conversation
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
enabled auto-merge (squash)
November 14, 2026 05:29
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
length(S010) no longer measures a table: a def whose body is onematchwith nothing under it butcasearms, each holding at most one statement, which opens no block.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.mdsets for a rule: the cheapest silencing edit must leave the code better.Found by hand-reading a sample of what
lengthreports 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:lengthreported 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.runcarried# noqa: S010 a table, an arm a check. It is a table by this definition, so the suppression is gone (noqareported 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
matchnested in amatch, and a longdoblock are all measured as before.arityanddepthare unchanged.depthwas sampled too (12 findings, 8 distinct defs): 7 are nesting a helper or amatchon two values at once would flatten, and one is not Bend 2 source. No change there.Laws
laws/SizeReportsOversizedDefs.bend:length_skips_table: length measures no lines of a tablelength_measures_other_def: of a def that is no table it measures the lines, as beforetable_needs_one_statement: a body of two statements or more is no tabletable_stops_at_other_arm: arms after one that is no arm of a table are not the arms of onetable_arm_holds_no_block: an arm holding a statement that opens a block is no arm of a tabletable_arm_holds_one_statement: an arm holding two statements or more is no arm of a tablesize_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:
lengthreports fewer defs. A project with a# noqa: S010on a table will seenoqa(S005) report that suppression as silencing nothing.Checks
bend PROOF.bend --check-onlyprintsALL PROOFS CHECK; self-lint is 0 errors (the 32 warnings main has);bolt fmt --checkis clean;nix flake checkpassed 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