Skip to content

feat: ban characters such as the em dash - #22

Merged
webern merged 2 commits into
mainfrom
m/banned-chars
Sep 24, 2026
Merged

webern merged 2 commits into
mainfrom
m/banned-chars

Conversation

@webern

@webern webern commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

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:

[md.lints.banned_chars]
groups = { emoji = true, arrows = false }     # switch groups on or off
allow = ["×"]                            # never banned
ban = { "®" = "(R)", "™" = "" }     # banned too; "" means delete it

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:

Group Characters Write instead Default
dashes em dash, en dash, minus sign, other dashes - on
arrows arrows ->, <-, => on
ellipsis the ellipsis ... on
bullets bullets, the middle dot, geometric shapes - on
math multiplication and comparison signs x, >=, <=, != on
checks check marks and crosses yes, no on
section the section sign section on
box_drawing box-drawing characters, block elements -, |, + on
spaces the no-break space, other unusual spaces a space on
invisible zero-width space, soft hyphen, tag characters nothing on
quotes curly quotes and apostrophes ", ' on
emoji emoji nothing off

allow and ban handle single characters. allow beats ban, and ban beats the groups.

The report lists each banned character once, with its lines and what to write instead:

README.md has 20 banned characters.

<advice: write the plain equivalent or reword; code is not checked; do not use entities or change the config>

The characters, and what to write instead:
  lines 2, 6, 9: U+2014 em dash "—"; write `-`
  line 4: U+2192 rightwards arrow "→"; write `->`
  line 9: U+200B zero width space; delete it

What is checked:

  • Code blocks, fenced or indented, and code spans are skipped, as the issue asks, so a diagram in a fenced block can use box drawing and arrows.
  • Frontmatter, headings, tables, link text and HTML are checked.
  • The file is read as written, so an HTML entity such as &mdash; is not a banned character. &nbsp; 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:

Group human llm mixed
dashes 24 206 117
arrows 1 95 35
math 0 31 9
checks 7 22 13
ellipsis 3 21 9
bullets 1 19 14
section 0 16 2
quotes 29 10 39
emoji 33 37 72
spaces 4 1 4
invisible 1 0 0
box drawing 0 0 0

Together the default groups flag 241 of the 400 llm/ files and 57 of the 400 human/ 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:

  • Curly quotes are on. In our corpus they are more common in human files than in agent files, because word processors and phones produce them: turning them on flags 18 more human/ files and 6 more llm/ 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.
  • Emoji are off because they don't separate the two sets. Check marks and crosses, which do separate them, have their own group that is on.
  • spaces and invisible are 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.
  • The section sign was not in the issue. It is in 16 llm/ files and no human/ ones, so it is on.
  • Box drawing is on because the issue lists it. It never appears outside code in the corpus, so it costs nothing.

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.py already record.

Testing

  • make ci: exit 0

  • tests/chars.rs: 18 tests covering:

    • what is read and what is skipped: code, entities, a byte order mark, other scripts;
    • the defaults, and switching groups on and off;
    • a check mark that is both in checks and an emoji;
    • allow and ban precedence, and merging an override;
    • config validation;
    • the tables themselves: every group is named by its config key, every rule can be reached, and every replacement is ASCII.
  • 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 .stderr files by hand.

  • tests/corpus.rs: three new tests.

    • Every character scan finds in the corpus is on the line it reports.
    • The binary reports exactly the files and counts the library does.
    • The defaults flag llm text at least four times as often as human text.
  • Mutation checks. When code blocks were no longer skipped, or allow was ignored, a unit test and a case failed each time.

References

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 webern added enhancement New feature or request area/lint Deals with the linting algorithms themselves, how they work. labels Sep 24, 2026
@webern webern mentioned this pull request Sep 24, 2026
4 tasks done
@webern
webern added this pull request to stack #24 September 24, 2026 15:01

@webern webern left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
webern merged commit c5eb882 into main Sep 24, 2026
2 checks passed
@webern
webern deleted the m/banned-chars branch September 24, 2026 17:39
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/lint Deals with the linting algorithms themselves, how they work. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support banning of em-dash and other common LLM characters.

1 participant