The ratchet
In a repository
Section titled “In a repository”A repository keeps its baseline at its root, beside ashlar.config.ts:
{ "no-comment": { "src/cart.ts": 2, "src/total.ts": 1 }}It holds three old comments: two in src/cart.ts and one in src/total.ts. On a branch, an agent adds
src/discount.ts, with a comment of its own:
$ pnpm exec ashlar checkAshlar checked 3 files in 0.1 s: 1 count rose.
no-comment in src/discount.ts: 1, up from 0 src/discount.ts:3:1 Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.The three old comments pass. The new one fails, because the baseline holds no comment for
src/discount.ts.
Why a ratchet
Section titled “Why a ratchet”Most repositories already break some rules. Fixing every break before turning a rule on would stop all other work, and leaving the rule off lets every file get worse.
The baseline holds what is there today, file by file and rule by rule. Old code stays as it is, and no file gets worse. Each fix lowers the baseline, and it never goes back up, the way a ratchet turns one way only.
Counts are held per file, so a fix in one file can't pay for a new break in another. The baseline is a file in the repository, so a review sees it shrink.
Take the baseline
Section titled “Take the baseline”The first check --shrink takes the baseline from the breaks there are:
$ pnpm exec ashlar check --shrinkAshlar checked 2 files in 0.1 s and took the baseline: 3 breaks in ashlar.baseline.json.$ pnpm exec ashlar checkAshlar checked 2 files in 0.1 s: no count rose.Commit ashlar.baseline.json. Without one, every count must stay at zero, and check says so.
What check holds
Section titled “What check holds”ashlar check runs the rules and reads the import graph, counts each file's breaks per rule, and fails when a
count rises above what the baseline holds for that file. A file the baseline doesn't name holds none. It exits
with 1 when a count rose, and 0 when none did.
Comments are held tighter. no-comment and no-disable let no new one in on the lines a branch changed, even
where the file's count stays within its baseline. Here the agent took out one old comment in src/cart.ts
and wrote a new one:
$ pnpm exec ashlar checkAshlar checked 2 files in 0.1 s: 1 count rose.
no-comment in src/cart.ts: 1 new one on lines changed since main. None may be added, even where others went. src/cart.ts:9:3 (1 other was there before) Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it."Since main" means since the branch left main, origin/main, master or origin/master, whichever is
closest. A file Git doesn't track yet counts as changed throughout.
Lower it
Section titled “Lower it”When a change fixes breaks, check notices the baseline holds more than the code has. Run check --shrink
and commit the baseline with the fix:
$ pnpm exec ashlar check --shrinkAshlar checked 2 files in 0.1 s: no count rose.The baseline now holds 2 breaks.--shrink only ever lowers each file's counts. A file that is gone drops out, and a file Git saw renamed
takes its counts to its new name. When nothing is left, the baseline file is removed.
Move a file
Section titled “Move a file”A file that moves arrives under its new name, while the baseline still holds its counts under the old one.
check fails on it, and says which move takes the counts along:
$ pnpm exec ashlar checkAshlar checked 2 files in 0.1 s: 1 count rose.src/money/total.ts moved from src/total.ts: `ashlar move src/total.ts src/money/total.ts` takes its counts with it.
no-comment in src/money/total.ts: 1, up from 0 src/money/total.ts:1:1 Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.$ pnpm exec ashlar move src/total.ts src/money/total.tssrc/total.ts → src/money/total.ts: 1 break moved.ashlar move takes a file or a whole folder. Each file keeps what it holds now, up to what the baseline held
for it, and a move that takes in new breaks is refused. See Move files.
Accept a rise
Section titled “Accept a rise”check --accept-rise takes each count that rose into the baseline, and says what it took in. It still lets
no new comment through on changed lines, so on the branch with src/discount.ts it takes the count in and
fails all the same:
$ pnpm exec ashlar check --accept-riseAshlar checked 3 files in 0.1 s: 1 count rose. no-comment rose to 1, up from 0, in src/discount.ts: taken in with --accept-rise.The baseline now holds 4 breaks.
no-comment in src/discount.ts: 1 new one on lines changed since main. None may be added, even where others went. src/discount.ts:3:1 Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.Keep --accept-rise for a rise a person agreed to. Ashlar's own pull requests never use it to make a check
pass.
Where the baseline lives
Section titled “Where the baseline lives”The baseline is ashlar.baseline.json beside the config, or the file the config's baseline key names. It
holds a count per rule per file, with paths from the config's folder.
pnpm exec ashlar snapshot prints the baseline's total for each rule, and pnpm exec ashlar check --json
prints each rule's count beside what the baseline holds. See JSON outputs.
Related
Section titled “Related”- Rules: what each count counts.
- Adopt Ashlar in an existing repository
- Move files
- CLI reference