Repository navigation
feat: ban characters such as the em dash - #22
Merged
Merged
Conversation
Add the banned_chars lint. A file fails when its text outside code holds a banned character, and the report lists each one with its lines and what to write instead. The characters come in twelve groups that the config switches on and off. Ten are on by default: dashes, arrows, the ellipsis, bullets, math signs, check marks, the section sign, box drawing, unusual spaces and invisible characters. Curly quotes and emoji are off, because the corpus has them about as often in human files as in agent ones. The defaults flag 235 of 400 llm fixtures and 39 of 400 human ones, and a corpus test holds them to at least five to one. allow and ban adjust single characters. Code blocks and code spans are skipped, so a diagram may use box drawing in a fenced block. The file is read as written, so an HTML entity is not a banned character. Turn the lint on for this repo's AGENTS.md and skills, every group.
webern
commented
Sep 24, 2026
webern
left a comment
Owner
Author
There was a problem hiding this comment.
I think I want quotes on by default!
Turn the quotes group on by default. Emoji stay off. The defaults now flag 241 of 400 llm fixtures and 57 of 400 human ones, up from 235 and 39. The corpus test that holds the defaults to their evidence now asks for four to one, not five. The crate doc no longer names each lint; it points to the lint module.
webern
added a commit
that referenced
this pull request
Sep 24, 2026
## Human Summary
We'll see how well this works, but the agent did a nice job with it. I
want my Markdown files to breathe, and that's what we are going for
here.
## Summary
Adds the `density` lint. It fails a Markdown file that holds a wall of
text: a paragraph longer than `max_paragraph_chars` (default 600), or a
list item longer than `max_item_chars` (default 300). The report lists
each dense block with its line and length, and the advice tells the
agent to split paragraphs, cut, and use short lists where the text walks
through steps.
```toml
[md.lints.density] # the table alone turns it on
max_paragraph_chars = 600
max_item_chars = 300
```
Like every other lint, it is off until the config has a `density` table.
Each limit defaults on its own, an override sets only the limits it
names, a limit of 0 is a config error, and `message` replaces the advice
with `{path}`, `{max_paragraph_chars}` and `{max_item_chars}`.
### What is measured
A block is a paragraph, or the text of a tight list item. Its length is
the characters a reader sees: text, code spans, and one per line break.
Markup, link targets, HTML tags and image alt text are not counted, so a
paragraph full of links is not punished for its URLs. Headings, tables,
code blocks and frontmatter are not blocks. A paragraph inside a loose
list item is held to the item limit, because a long item is the same
problem whether or not it has a blank line inside it. A blank line ends
a paragraph; a line break does not, and the advice says so, since an
agent's first move is often to add line breaks.
### Why not the ratio in the issue
The issue asks for a ratio of non-whitespace to whitespace over the
whole file. I measured it on the 1200 corpus fixtures, bucketed by each
file's longest paragraph or item:
| Longest block (chars) | Files | Ratio p10 | p50 | p90 |
|---|---|---|---|---|
| 0-200 | 262 | 4.0 | 5.2 | 7.9 |
| 200-400 | 457 | 4.2 | 5.5 | 7.6 |
| 400-800 | 372 | 4.2 | 5.4 | 7.5 |
| 800+ | 109 | 4.0 | 5.6 | 9.0 |
The ratio barely moves between files of short paragraphs and files with
walls of text. Most whitespace is the single space between words, so the
ratio stays close to the average word length whatever the layout. A
limit per block measures what the issue is after and tells the agent
exactly which paragraph to fix.
### The defaults
The defaults are loose ceilings that most files pass. Under them, the
corpus fails:
| Corpus | Paragraph > 600 | Item > 300 | Either |
|---|---|---|---|
| human (400) | 25 | 31 | 53 |
| llm (400) | 31 | 69 | 84 |
| mixed (400) | 40 | 101 | 122 |
Long list items separate agent text from human text better than long
paragraphs do. Unlike `banned_chars`, this lint is not a detector; it is
a readability limit, and a repo that wants terse agents should tighten
it. This repo turns it on for AGENTS.md and the skills with 500 per
paragraph.
This PR is stacked on #22.
## Testing
- [x] `make ci`: exit 0
- [x] `tests/density.rs`: what a block is, what is counted, chars not
bytes, hidden blocks, list items, quotes and footnotes, the defaults at
and over the limits, one limit at a time, zero refused, override merge
- [x] `tests/cases/density/`: broken, clean, limits in an override,
custom message, zero limit
- [x] `tests/corpus.rs`: every block starts on a line of text, and the
binary reports exactly the blocks the library finds across the corpus
## References
- Closes #10
- Stacked on #22
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
Solves the em-dash problem.
Summary
Adds a fourth lint,
banned_chars. It fails a Markdown file whose text holds a character that agents write and people rarely do, such as the em dash, and says what to write instead.The table alone turns it on, with the default groups:
The characters come in twelve groups. Each group can be switched on or off in the config, and an override sets only the groups it names, so one file can allow arrows while the rest of the repo bans them:
dashes-arrows->,<-,=>ellipsis...bullets-mathx,>=,<=,!=checkssectionbox_drawing-,|,+spacesinvisiblequotes",'emojiallowandbanhandle single characters.allowbeatsban, andbanbeats the groups.The report lists each banned character once, with its lines and what to write instead:
What is checked:
—is not a banned character. is in 9 corpus files, mostly human ones, and I didn't want to flag a deliberate choice. The advice tells the agent not to dodge the check with entities.How the defaults were chosen
The issue asked for research, so I looked at the web and at our own corpus. The corpus has 400 files in each of three categories:
human/: files not touched since before 2022;llm/: every commit marked as an agent's;mixed/: files begun by a person and later edited by an agent.Share of files in each category holding a character of each group, outside code:
Together the default groups flag 241 of the 400
llm/files and 57 of the 400human/ones. A corpus test now holds that to at least four to one, so a change to the defaults that starts catching human writing fails.Why each group is on or off:
human/files and 6 morellm/ones, and takes the ratio from six to one to four to one. They are banned anyway, because the aim is plain characters in the files agents write, not telling authors apart. Wikipedia's "Signs of AI writing" page says ChatGPT and DeepSeek write them and Claude and Gemini typically don't.spacesandinvisibleare rare in the corpus. They are on because they have exact replacements, and they are the characters in the 2025 reports of ChatGPT o3, o4-mini and GPT-5 writing U+202F. Invisible characters also include Unicode tag characters, which can hide text in a file an agent reads. Zero-width joiners and bidi controls are left out, since other scripts need them.llm/files and nohuman/ones, so it is on.These go in the config, so a repo can switch any of them. This repo's own config turns on every group, emoji too, for AGENTS.md and the skills. They already pass.
README and the as-built doc are updated. The as-built doc was 624 bytes under its budget, so I cut the corpus section's list of sources and sidecar fields, which the sidecars and
collect.pyalready record.Testing
make ci: exit 0tests/chars.rs: 18 tests covering:checksand an emoji;allowandbanprecedence, and merging an override;Cases in
tests/cases/banned_chars/:broken: every default group, in every part of a file that is read;clean: diagrams in fences, code spans, entities, other scripts, and emoji, which are off by default;groups: an override switching groups for one file;allow_and_ban;custom_message;not_one_character, a config error.I checked every count and line in the
.stderrfiles by hand.tests/corpus.rs: three new tests.scanfinds in the corpus is on the line it reports.Mutation checks. When code blocks were no longer skipped, or
allowwas ignored, a unit test and a case failed each time.References