formwork-arm-census

command
v0.17.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

embedded.go — the fourth way a rule ARM can be written so that it cannot fail: a `required-pattern` whose pattern is a SUBSTRING of a longer identifier that already appears in its own scope.

#11934. `defaulttemplates-formula-validate-item-branch` pinned the literal `it\.Formula` over formula_validate.go. Two branches below, the kit walk reads `kit.Formula` — and `it.Formula` is a substring of `kit.Formula`. Deleting the ENTIRE root-item branch, which is the #8812 regression the arm is named for, left it green off the kit branch's own text.

The verdict is DEMONSTRATED, not inferred from the pattern's spelling. For each arm the census reads the lines its own scope and preprocessing produce, removes every occurrence that stands as its OWN token, and asks whether the file still satisfies the arm. If it does, what is holding the arm up is text belonging to some other construct, and deleting the thing the rule is about changes nothing.

Two conditions, and the second is what keeps honest arms out. The arm must have at least one token-aligned witness — that is the construct it is actually about — AND a match must survive its deletion. A pattern with no aligned witness at all is a deliberate substring spelling (`Repo` meaning `UserRepo`, `OrderRepo`), and deleting those identifiers DOES fail it, so it is not in this class and is never flagged.

formwork-arm-census — two ways a rule ARM can be written so that it cannot fail, both invisible to every instrument the repo already runs.

Usage: go run -C tools/formwork-arm-census . --check=tautology|multi-witness <repo-root>

Product enforcement is formwork type:command (.formwork/rules/arm-shape-ratchets.yaml) with origin on this file. Exit 0 = no offenders, 1 = offenders listed, 2 = usage/env error.

NO ALLOWLIST, NO REGISTER, NO DECLARED EXCEPTION. Both checks fail on every violation in the corpus today, not just on the next one. A ceiling set at the current offender count, a file enumerating today's offenders, or a `# <rule>-ok:` comment would each be the same move: the class stays in the tree and the gate reports green. The cure is to fix the arm.

--check=tautology — the required pattern that requires nothing

`required-pattern` with `pattern: '.'` is a gate on the file having a line. shell-unit-tests-exist was exactly that over scripts/lib/file-size-caps.test.sh: every one of its fifty assertions about the file-size cap resolver (the #8629/#8630 scar) could be deleted, the file replaced with `#!/usr/bin/env bash` + `exit 0`, and the arm stayed green — as did its sibling shell-unit-tests, which only required ci.yml to NAME the script. CI then ran the gutted script, got exit 0, and reported the lane green. The pair was jointly inert (#12182).

No instrument saw it. `formwork lint` checks that the scope matches a file, and it did. The vacuity census's class-2 probes ask whether the evidence is a comment or the rule's own detector; `.` matches the code plane, so it is neither. `formwork test` replayed a fire fixture holding an EMPTY file, which the arm does fail — but emptying the file also empties the scope, so the only state the fixture proved was the one state that cannot occur in a tree where the file exists at all.

The verdict is empirical, not a blocklist of spellings: a pattern is tautological when it matches every line of an arbitrary-line probe corpus (tautology.go). `.`, `.*`, `[\s\S]*`, `(?s).*`, `[^]`, `.{0,}` and `[a-z]*` are one rule written seven ways, and enumerating six of them just names the seventh.

--check=multi-witness — the last-witness gate

An existence obligation — `required-pattern mode: exists`, or `pattern-count op: at-least` — passes as long as ONE witness survives. With one or two witnesses in the tree that is a real gate: delete the line and it fires. With dozens it is a gate against the class being deleted ENTIRELY, which is not a regression anyone was going to commit, while the regression its own cure names sails through. Three measured on develop@708fe7a0aa:

withtenantorg-adopted             74 witnesses. Cure: "convert a
                                  worker-pipeline writer to call
                                  db.WithTenantOrg (audit-2 BE-ARCH-1)".
                                  Revert 73 of the 74 production call sites
                                  to db.WithAdmin — the RLS-bypass
                                  regression the rule is NAMED for — and it
                                  passed.
schema-contract-boundary          54 witnesses, 18 of them in _test.go
                                  files. Cure asks for "at least one scan/
                                  helper" importing the generated protos;
                                  strip every non-test import and hand-roll
                                  DTOs, and it stayed green off a test file.
schema-snapshot-has-btree-indexes 517 witnesses, all CREATE INDEX lines.
                                  Cure: the snapshot "must remain the
                                  canonical index inventory"; drop 516 and
                                  one surviving index still read as
                                  canonical.

The cure is a counted ratchet: `pattern-count op: at-least` with n at the measured count, so the FIRST witness lost is the one that fires. The detector prints the n to write.

Why an external tool

The engine's scanner skips `.formwork/` outright (formwork's internal/scan/scan.go), so no declarative rule can read the rule corpus — a `required-pattern` scoped at `.formwork/rules/**` matches zero files and passes vacuously forever, which is the exact defect this file exists to catch. Same reason formwork-rules-not-vacuous, exists-rule-cure-not-universal and count-relation-arm-is-anchored all shell out to a census.

narrowable.go — the third way a rule ARM can be written so that it cannot fail: a `required-pattern` whose pattern is a PREFIX of its own narrowing.

#11934. `defaulttemplates-formula-validate-walks-sections-items` pinned the literal `range spec\.Sections` over formula_validate.go. That literal is a prefix of every legal way to reduce the collection: `range spec.Sections` still matches `range spec.Sections[:1]`. Measured on develop — narrowing all four loops in that file to their first member compiled, left the package's own tests green, and left the arm and its two siblings reporting OK, while formula validation for every section, item, option and kit after the first silently stopped running.

The verdict is DEMONSTRATED, not inferred from the pattern's spelling. For each arm the census reads the lines its own scope and preprocessing actually produce, finds the ones where the pattern's match ENDS inside a traversal's source expression — `range <expr>` in Go, `for (… in <expr>)` in Dart — and re-runs the pattern against that same line with the expression narrowed. An arm is flagged only when a concrete, legal, silent narrowing of a line in its own scope leaves it green, and the report prints that line.

Why the match END and not merely "the pattern mentions range". A pattern like `WithTenantOrg\(` can match a line that happens to contain a loop head without pinning the loop at all; narrowing that loop cannot be laid at the arm's door. A pattern whose match STOPS inside the traversed expression is the one that has staked its verdict on that expression and left the continuation unbounded — the arm still matches whatever is appended to it. A pattern that reaches its own terminator (`\)`, `\s*\{`, `\s`) is spared by construction, because the narrowing displaces that terminator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL