Repository navigation
test: pin a case for every lint - #37
Merged
Merged
Conversation
max_size_bytes and max_emphasis had no directory under tests/cases, so a change to their reports could go unnoticed. Add a clean case, a failing case and a case with a custom message for each. Add a test that fails when a lint in the config schema has no directory of cases, when a directory is not named after a lint, or when none of a lint's cases fails. The lints come from the schema, so a new lint is held to this with no edit to the test. Each message says how to fix it, including make fix-test-output. In fix mode the test skips the last check, since the case runner is writing the .stderr files at the same time. The as-built doc says what the test requires. To keep the doc from growing, drop the lists of checks and packaged files from its Build section; the Makefile and Cargo.toml hold them.
9 tasks done
webern
added a commit
that referenced
this pull request
Sep 26, 2026
## Human Summary
Seems like a pretty good feature that could go a long way toward solving
pet peeves.
## Summary
Adds `banned_phrases`, a lint that fails a Markdown file whose prose
holds a phrase the config lists. `ban` maps each phrase to the advice
its report shows, and `allow` exempts a longer phrase that holds a
banned one. deslag ships no phrases: with nothing in `ban`, the lint
checks nothing. `.agents/deslag.toml` is unchanged.
This config and report are the `broken` case in
`tests/cases/banned_phrases/`:
```toml
[md.lints.banned_phrases.ban]
"it's worth noting" = ""
"delve into" = "say what you found instead"
"in today's fast-paced world" = ""
"leverage" = "write `use`"
```
```
ERROR: deslag detected banned phrases!
README.md has 6 banned phrases.
This repo keeps these phrases out of its Markdown. Do what the advice with each one says, or reword the sentence; it often reads better with the phrase simply gone.
Do not hide a phrase in a code span or HTML, and do not change the config to get past this check. Only a human can tell you to do that, and I am a linter, not a human.
The phrases, and what to do about each:
line 1: "Delve Into"; say what you found instead
line 3: "In today's fast-paced world"; delete it
line 3: "It's worth noting"; delete it
line 4: "it's worth noting"; delete it
line 6: "leverage"; write `use`
line 11: "Leverage"; write `use`
deslag: 1 of 1 Markdown files with banned phrases.
```
The second match on line 3 runs onto line 4, and the one on line 4 is
written `**it's worth** noting`.
### How it matches
There are no regular expressions. A new `Token::split` in
`src/document/tokens.rs` splits a phrase with the same code that splits
a stretch of prose, so the config and the document agree on what a word
is. The phrase then matches the same tokens in one block, compared by
`Token::folded`: lower case, with a curly apostrophe made straight.
Whitespace, line breaks and formatting between tokens don't count. A
code span, HTML, an image, a URL or a footnote reference is a token no
phrase can hold, so it breaks a match. Phrases are indexed by their
first token, so each token of a file costs one lookup.
### Choices the issue left open
- **A phrase is plain text, not Markdown.** `Token::split` runs the
tokenizer on the raw string instead of parsing it with
`Document::markdown`. So `#` or `*` in a phrase stays a token instead of
turning into a heading or emphasis, and the phrase is compared with what
the file renders: `AT&T rocks` in a file matches `AT&T rocks` in the
config.
- **Symbols match like words and marks.** The issue names word, number
and punctuation tokens. Without symbols (`+`, `>`, emoji), `C++ rules`
would pass validation and never match.
- **"No words" means no word and no number**, so `110%` is a valid
phrase.
- **Overlap is leftmost, then longest.** Scanning left to right, the
first match wins, and of matches that start at one token, the longest.
With `worth noting` and `noting that` banned, "Worth noting that"
reports `Worth noting` only.
- **`allow` is applied before overlap is settled.** A match inside an
allowed match is discarded first, so an allowed phrase hides only what
lies inside it. With `worth noting` and `noting that` banned and `well
worth noting` allowed, "well worth noting that" reports `noting that`.
- **A phrase in both `ban` and `allow` is an error within one table
only**, because `invalid()` runs per table. That lets an override allow
a phrase the section bans, and after the merge `allow` wins; the `allow`
case pins this. The check compares folded tokens, so `It's worth noting`
and `it's worth NOTING` count as one phrase.
- **An override replaces `ban` and `allow` whole**, as with
`banned_chars`.
- **The quote** is each matched token as written, with a space where
whitespace parts two of them and the markup between them left out.
Quoting the raw byte range gave `"it's** worth noting"`, and `"It's
worth > noting"` inside a block quote.
- **The advice is printed as written**, and an empty one prints `delete
it`. It is advice, not a replacement, so the report does not put it in a
`write ...` the way `banned_chars` does.
- **The guide's example config** turns the lint on with an empty table,
because its test requires every lint. The bullet tells the agent to ask
the human which phrases to ban.
### Corpus numbers
These are 22 phrases widely cited as LLM tells, run through the library
over `tests/corpus/{human,llm,mixed}` by a throwaway test that is not
committed:
`delve into`, `delves into`, `it's worth noting`, `it is worth noting`,
`it's important to note`, `in today's fast-paced world`, `in the realm
of`, `a testament to`, `tapestry`, `navigate the complexities`, `plays a
crucial role`, `seamlessly`, `harness the power of`, `unlock the power
of`, `game-changer`, `cutting-edge`, `ever-evolving`, `in conclusion`,
`embark on`, `let's dive in`, `deep dive`, `whether you're`
| label | files | flagged | rate | matches |
|---|---|---|---|---|
| human | 400 | 1 | 0.25% | 1 |
| llm | 400 | 5 | 1.25% | 7 |
| mixed | 400 | 13 | 3.25% | 20 |
The list barely fires on any label, so it does not separate them in any
useful way. Only 7 of the 22 phrases matched at all, mostly `seamlessly`
(7 files) and `whether you're` (5 files, one of them human). 19 flagged
files out of 1,200 is too few to tell the labels apart. The chatbot
phrases people cite are rare in the Markdown that agents write in
repositories.
For comparison, 12 single words that are also often cited
(`comprehensive`, `robust`, `seamless`, `leverage`, `crucial`,
`essential`, `ensure`, `enhance`, `streamline`, `utilize`, `powerful`,
`effortlessly`) flag human 55 (13.8%), llm 67 (16.8%) and mixed 142
(35.5%). They fire far more but hardly separate human from llm: `ensure`
alone flags 33 human files and 34 llm ones. `comprehensive` (4 / 14 / 25
files) and `leverage` (2 / 9 / 14) lean llm. Under both lists mixed
files are flagged most, and I did not correct for file length. None of
this makes a case for shipping a default list.
### Also in this PR
Fixes found while checking the README, in three commits of their own:
- **The README holds only what stays true.** It listed the lints,
spelled out each one's rules and quoted corpus counts, so it went stale
with every lint PR; one count was already wrong (the density defaults
fail 92 of the 400 agent-written files, not 84). It now says what deslag
is, how to install, set up and run it, and the config's general shape,
and points to `deslag instructions config-schema`, `deslag
instructions`, `deslag explain` and the as-built doc for the details.
This is also why the PR adds no README section for `banned_phrases`.
- **Install.** `cargo install deslag` fails: the crate is not on
crates.io. The README installs from a checkout, and the setup guide
tells the agent to ask the human how CI should install deslag instead of
writing `cargo install deslag --locked`. `deslag --help` and the crate
description said deslag only checks the byte budget; they now describe
the linter.
- **`deslag explain` on a file check skips.** `check` never reads a
git-ignored file or one inside `.git`, but `explain` printed its
settings as if `check` used them. It now prints `# ignored: yes, so
deslag check never reads it` and stops, as it does for a file `[md]`
does not select.
- **`every_lint_has_a_failing_case`** counted any case with a non-empty
`.stderr` file, so a case where deslag cannot run (exit 2) passed for a
case where the lint fails a file. It now counts only cases that exit 1.
## Testing
- [x] `make ci`: exit 0
- [x] `tests/phrases.rs`: case, curly apostrophes, soft and hard line
breaks, formatting, code spans, HTML, images, URLs, footnotes, two
blocks, blocks that are not read, `allow`, overlap, merging, each
validation error, and `Token::split` agreeing with `Document::markdown`
on sample text
- [x] `tests/cases/banned_phrases/`: `clean`, `broken`, `allow` (with an
override that allows a phrase the section bans), `custom_message`, and
`ban_and_allow` (an invalid config)
- [x] `deslag instructions config-schema` shows `BannedPhrases`
- [x] A throwaway corpus probe, not committed: every run of three prose
tokens in the corpus's prose blocks (319,722 of them), joined into a
phrase, split back into the same tokens and was found by the lint. No
tokenizer bug turned up.
- [x] `tests/explain.rs`: a file under a git-ignored directory, and one
inside `.git`, each say `# ignored: yes` and nothing more; without the
fix they print full settings
- [x] `tests/cases.rs`: a case with a `.exit` file holding 2 does not
count as failing a file; with the old rule it did
- [x] The README's example config, run with `deslag check` and `deslag
explain` in a scratch repo, and `cargo install --locked --path .` into a
scratch directory
- [x] `docs/design/deslag.asbuilt.md` is 16,379 bytes of its 16,384,
from 16,363 on `main`
## Notes
- The as-built doc's intro and its config paragraph now give examples
instead of listing every lint and every invalid setting, so a new lint
doesn't have to extend them.
- Rebased after #37 to #40 merged. `ban_and_allow` is a config error, so
it has a `.exit` file holding `2`, as #39 asks of such cases.
`BannedPhrases` derives `Serialize` like the other lints, so `deslag
explain` (#40) shows it, and explain's pinned output gains a `#
banned_phrases: off` line.
## References
- Closes #32
- Related to #34, which ruled out regular expressions over raw text;
this matches tokens
- Related to #39 and #40
- Related to #16, #18 (the README)
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.
Human Summary
An idea from Vale; ensure each lint is covered by a test.
Summary
Each directory under
tests/cases/<lint>/is a small repo, and the.stderrfile beside each case pins exactly whatdeslag checkprints there. Two lints,max_size_bytesandmax_emphasis, had no directory, so a change to their reports went unnoticed unless another test happened to check that part of the text.This adds a clean case, a failing case and a case with a custom
messagefor each of them. It also adds a test totests/cases.rs,every_lint_has_a_failing_case, that fails when:tests/cases/;.stderrfile in a lint's directory is empty, so the lint is never seen to fire. This is the part that matches Vale'stest --coverage.The lints come from
deslag::config::schema(), as the keys ofdefinitions.MdLints.properties, so a new lint is held to this with no edit to the test. Each failure names the lint and says what to do, includingmake fix-test-output. The check is its own test function, so the case runner is untouched.In fix mode (
make fix-test-output) the test skips the "fails at least once" check, because the runner is writing the.stderrfiles in a parallel thread. Without that, the firstmake fix-test-outputfor a new lint would fail on the files it was about to write.The as-built doc now says what the test requires. To pay for that sentence, its Build section drops the list of checks
make checkruns and the list of files Cargo packages; the Makefile andCargo.tomlhold both. The doc ends 20 bytes smaller than onmain.The new cases show no wrong report. The emphasis percentages check out by hand (169 of 337 characters is 50.148%, printed rounded up as 50.15%), and the size report matches the wording in
docs/design/deslag.desired.md.Testing
make ci: exit 0tests/cases/max_size_bytes/out of the tree. The new test failed with: "max_size_bytes has no cases. Add tests/cases/max_size_bytes/ and, in it, a directory for each case: a small repo, config included, like those of the other lints. Write at least a clean case, a failing case and a case with a custom message. Then runmake fix-test-outputto write each case's .stderr file, and read them." Restored it.tests/cases/typo_lint/: the test failed, naming it and listing the lints.max_emphasis.stderrfiles: the test failed with "max_emphasis has no failing case".max_emphasis.stderrfiles and ranmake fix-test-output: it passed and wrote them back byte-identical.References