Skip to content

feat: exclude globs in sections and overrides - #195

Merged
webern merged 4 commits into
mainfrom
m/deslag-exclude
Oct 17, 2026
Merged

webern merged 4 commits into
mainfrom
m/deslag-exclude

Conversation

@webern

@webern webern commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

A section (md, rust, cpp, toml) and each of its overrides take an exclude list beside globs, so a config can say "everything that matches X except Y" (#69).

[rust]
globs = ["/src/**/*.rs"]
exclude = ["/src/proto/**"]

[[md.overrides]]
globs = ["/docs/**/*.md"]
exclude = ["/docs/adr/**"]
lints.max_size_bytes.value = 8000

Before this, /src/**/*.rs minus /src/proto/** had to name every hand-written directory, and an override could not spare one file inside its globs. .ignore is global, hides files from other tools, and cannot narrow an override.

Rejected syntax:

  • ! patterns inside globs: Ideas from Vale that deslag is not taking #34 turned them down, since a negated pattern in an any-match list matches nearly every file and list order would start to matter.
  • globs = { include, exclude }: reshapes a key that has shipped, which needs a redirect and a breaking entry.
  • One top-level exclude: .ignore already does that for the walk, and a top-level key can come later without breaking a config.

Semantics:

  • A section selects a file when one of its globs (written or default) matches and none of its exclude patterns does. An override applies on the same rule. Its specificity is still that of its best matching glob; exclude only removes, and nothing re-includes.
  • An exclude pattern is a glob pattern: anchored at the repo root when it holds a /, else a file name. The extension rule of a section is for globs alone, so [rust] may exclude /src/proto/**.
  • The walk comes first and is unchanged: .git, gitignore and .ignore drop files before any section looks, and exclude cannot bring one back.
  • Excluded is exactly unselected, for check, fix, --diff and explain. deslag check takes no path. deslag fix src/proto/gen.rs on an excluded file exits 2 with no section selects it; [rust] excludes it by "/src/proto/**", as for any unselected file, plus the exclude that dropped it. Only the library's check_file still reads a path named on its own with the section for its extension, as it did for an unselected path.
  • An exclude that matches nothing is allowed, as a glob that matches nothing is: the config is read without a tree, and an error that depended on the working tree would make a config valid in one clone and not another. exclude = [] is no exclude. A bad pattern is the same glob error a bad globs entry gives, and excludes is an unknown key.
  • A file that two sections select now gets the advice "or exclude it from one of them".

deslag explain says why. A file a section excludes reads no section; [rust] excludes it by "/src/proto/**". Each override line shows its exclude when it has one, and an override whose globs match but whose exclude drops the file gets a line of its own:

# overrides: no override applies, but these match by globs:
#   override 1 does not apply: globs = ["/docs/**/*.md"] match, but exclude "/docs/adr/**" drops the file

When another override does apply, the summary line is the usual # overrides, in the order they merge: and the does not apply line follows the ones that apply. # overrides: none is left for a file that no override's globs match.

The escape hatch is the same one narrowing globs already is: an agent could exclude the file that fails. The guide's "never raise one, or add an override" line now includes an exclude, the schema docs and each changelog entry say only a human adds one, and the guide's exclude example shows generated code. The guide stays under its budget: the room came from other lines of it.

Structure: Globs in src/glob/select.rs is globs minus exclude and knows nothing of config. Its select answers miss, hit with a specificity, or excluded by a pattern. Section and Override each hold one in place of their Vec<Pattern>. On disk the key is last in each struct, because a section written as a JSON array is read by position. It is not a lint setting, so src/config/lints.rs is unchanged, and so are the golden files, .agents/deslag.toml and every byte budget. No dependency is added.

Cost to users: none until a config writes exclude. One more pattern list per section and override, matched only for files the globs hit.

Testing

  • make ci-fast: exit 0
  • make test: exit 0
  • Unit tests: Globs hit, miss and excluded with anchored and basename patterns; default globs less an exclude; an excluded override does not merge; merge order of equals is unchanged; load in TOML, YAML and JSON; a JSON array with exclude last, and one written before it refused; a bad pattern; excludes refused; exclude defaults to [] in the schema; the two-sections advice.
  • Explain tests (tests/explain.rs): section exclude, override exclude, an override that drops the only candidate (and the summary line then does not say none), an ignored file still reading as ignored.
  • Fix test (tests/fix.rs): fix on a path a section excludes exits 2 and names the section and the pattern.
  • Cases: tests/cases/max_size_bytes/exclude (an over-budget file the section excludes passes, its sibling fails) and exclude_override (a file the override excludes gets the section's budget and fails).
  • Not run: make ci and the big tier. This changes which files a config selects, not what a lint finds.

References

A section and an override each take an `exclude` list beside `globs`.
A file is selected when one of the globs matches and no exclude
pattern does. Nothing re-includes a file, and the walk still drops
ignored files first.

An exclude pattern is a glob pattern: anchored at the repo root when it
holds a `/`, else a file name. The extension rule of a section is for
`globs` alone, so `[rust]` may exclude `/src/proto/**`. An override
that an exclude drops lays nothing over the section's settings, and
its specificity is still that of its best matching glob.

`deslag explain` says when a section excludes a file, and by which
pattern. It shows the exclude of each override that applies, and
names an override whose globs match but whose exclude drops the file.

Globs and exclude are one type in src/glob/. The key is last in each
struct, because a section written as a JSON array is read by position.
The two-sections error now says a file can be excluded from one of
them. The guide shows `exclude` for generated code, and says only a
human adds one.

Closes #69
@webern webern added enhancement New feature or request ai Primarily authored by AI (whether PR, Issue, Whatever) area/config Has to do with deslag configuration (deslag.yaml, etc.) labels Oct 17, 2026
@webern

webern commented Oct 17, 2026

Copy link
Copy Markdown
Owner Author

Question for the owner: should the key be exclude or exclude_globs? It is built as exclude, beside globs in every section and override. A rename touches five structs, the eight changelog entries under src/changelog/releases/next/, the guide and the tests.

`deslag fix` on a file that a section excludes said only "no section
selects it". It now adds which section excludes it and by which
pattern, as `deslag explain` does.

`deslag explain` printed `# overrides: none` and then a line for an
override that did not apply. When every override that matches by globs
is dropped by its exclude, the summary line now says no override
applies. `none` is left for a file that no override matches.

Rewrap the `exclude` doc comments of the four sections to 100 columns.
Change the rust, cpp and toml override examples to set
`lints.density.max_paragraph_chars`, so the exclude is the point of the
example.
@webern
webern marked this pull request as ready for review October 17, 2026 10:47
@webern
webern merged commit 4506e99 into main Oct 17, 2026
9 checks passed
@webern
webern deleted the m/deslag-exclude branch October 17, 2026 20:01
webern added a commit that referenced this pull request Oct 23, 2026
## Summary

Once a lint is on for a file it judges every sentence, and some must stay as written: a dated record, an example of a lint's defaults, a quoted title. With no way to say so, an agent rewords the sentence to slip past the lint, or the config lists files one by one (see #68, and the review of #197 where a count was rewritten as a bound to pass).

This adds the `allow` entry. It is a config entry of a section (`md`, `rust`, `cpp` and `toml` each have the list) that names one file, one lint, one exact sentence and a reason:

```toml
[[md.allow]]
path = "docs/log.md"
lint = "banned_chars"
quote = "The sentence, as the file holds it."
reason = "Why it stays."
```

There is no file-level off, no glob and no list: one entry is one file, one lint and one sentence. Only a human writes or changes one; the guide (step 5), `deslag instructions lints` and every `setting.<section>.allow` changelog entry tell an agent to leave the sentence and give the human its text and a reason. The repo's own `.agents/deslag.toml` gets no entry.

How it works:

- Load: an unknown key, an empty `reason` or `quote`, a `path` that is a glob or is not written as reports print it, and a lint that does not take an entry are refused with exit 2. A `quote` may hold any character but a control character other than a tab, CR or LF, since it must equal the sentence, which the file holds anyway: an emoji joined by a zero-width joiner, a bidi mark that only the config's `ban` list bans, a zero-width space the config does not ban. A `path` or `reason` may not hold a character that shows as nothing or acts on the reader: a control or format character, another default-ignorable one, or a blank other than the ASCII space; a `reason` may hold a tab, CR or LF. The checks read the value after parsing, so a TOML escape is no way round them. Reports, notices and `deslag explain` write each character that shows as nothing or acts on the reader as `<U+XXXX>`, on stderr and in the json `report`, sarif and github alike, so a reviewer sees what the quote holds. The message for a refused lint names that lint's own knob, for example the override of `max_size_bytes`. An exhaustive match on `Lint` makes each new lint choose.
- Matching runs inside `check_text`, so `check`, `fix` and `--diff` agree. The quote and each sentence of the file compare with spaces, tabs and line breaks folded to one space, so a rewrap keeps the entry. A line break is LF or CR LF, or a lone CR in Markdown; a lone CR ends a C++ `//` or TOML `#` comment, and in any other comment it is a character of its line, as the comment's reader reads it, and must match. The quote is folded the way each sentence is read, so a lone CR in a quote is a line break against a Markdown sentence and a character against a Rust comment's, even in one file that holds both. Any other character must match exactly, a no-break space or a zero-width space included, so a banned character added to the sentence later makes the entry fail instead of riding along with it. The `>` of a block quote's continued lines and the byte order mark that opens a file are no part of the sentence, so a wrapped quote is quoted without them. A `>` inside a code span that wraps across the lines of a block quote stays in the sentence, and in a comment read as plain text (every C++ and TOML comment, and a Rust comment that is not a doc comment) a `>` is text. An entry drops each occurrence of its lint inside the one sentence, never one outside it, and never a verdict on the whole file.
- An entry is applied, or it fails: no such file (it does not exist, git ignores it, or it is a directory or a link), the section does not select the file, no such sentence, the quote is two sentences of the file, or the lint finds nothing in the sentence (it is off, or the text was fixed). A failed entry fails the run with exit 1. Its report says why, quotes the three sentences of the file that hold a finding of that lint and are closest to the quote by edit distance, in the order of the file (and says how many more there are), and says an agent may delete the entry, which only tightens the check, but must never write or change one. The distance compares the first 60 characters of the quote with the first 60 of each sentence, and a longer sentence is quoted cut there with `...`, so the work per sentence and the report stay bounded however long a sentence is.
- Rewording the sentence fails the entry and brings the finding back.
- Every run whose config has an entry prints `deslag: N exemptions applied; deslag explain <PATH> lists a file's.`, clean or not. A failing run also prints how many did not hold and a line saying only a human writes or changes an entry.
- `deslag explain <PATH>` lists the entries for the file, each with its sentence's line or "no such sentence".
- json: `exemptions`, each with its fields, status, the marks it dropped, and whether the change added it. `FORMAT_VERSION` stays; a run with no entry prints no `exemptions`. A failed entry is in `exemptions` and not in `findings`, so a run that exits 1 can have an empty `findings`.
- sarif: a dropped occurrence is a result with `suppressions` (`external`, the reason as `justification`), and a failed entry is a result of the rule `allow` on the config. The result sits at the start of the config, not at the entry's line: serde reads the config in three formats and none keeps an entry's span, and the message names the entry as `md.allow[0]`.
- github: a failed entry is an `::error` and an added one a `::notice`, on the config.
- With `--base` or `--diff`, the config at the merge base is read, and entries compare by section, path, lint and quote (whitespace collapsed). A new entry, or one with a changed reason, is added and printed as a notice. A config the base does not have, or that this deslag cannot read, has no entries, so every entry is added. `--diff` never hides a failed entry, whether or not the change touches its file: a rename, or an edit of the config that unselects the file, would otherwise let `--diff` pass what `--base` and the whole tree fail. The README, `deslag check --help` and guide step 6 say so; to stay within the guide's byte budget, step 4 drops its description of what each `# prose regions` line holds, which `deslag explain` prints anyway.

Cost: none without an entry; every output of a run with no entry is byte-identical to main. With one, matching is linear in the file. Finding a sentence's text used to search every token for each point, which made a large file quadratic; a binary search finds the next token now, and a merge finds the sentences that hold a finding. Timed on a soft-wrapped paragraph of N lines plus one exempted sentence, the fastest run on macOS, entry against no entry:

| Lines | release | debug | before, release | before, debug |
|---|---|---|---|---|
| 8,000 | 0.11s vs 0.10s | 0.77s vs 0.62s | 1.53s vs 0.32s | 5.78s vs 0.59s |
| 32,000 | 0.44s vs 0.40s | 3.04s vs 2.20s | 12.63s vs 0.41s | 91.16s vs 2.46s |
| 128,000 | 1.72s vs 1.58s | 11.11s vs 8.77s | not run | not run |

A stale entry in a file of 100,000 sentences with a finding, plus one sentence of 200 KB: release 2.26s against 1.68s with no entry (before: 8.94s). A stale report on a sentence of 200 KB is 1,666 bytes on stderr (before: 201,612, since it quoted the sentence whole).

Not taken: charcheck's ratchet (fail past a frozen count) is one more number an agent raises. `list_growth` is out: its findings exist only against a base, so an entry would fail on main the commit after it lands.

### Owner questions, as built

1. A stale entry fails with exit 1, reported as a finding is, not exit 2: deslag ran, and the json and sarif logs carry it. Built: `Report::is_clean` counts failed entries, and the run exits 1.
2. An entry the change adds or changes, with `--base` or `--diff`, is a notice that does not fail. Built: a `deslag: notice:` line on stderr, `added: true` in json, a `::notice` in github. A failure would keep a human's own entry red; review is the gate, and the notice shows the reviewer each one.
3. The lints that take an entry are those whose findings sit in one sentence: `banned_chars`, `banned_phrases`, `verbs_no_nouns` and `not_at_all`. `counted_inventory` comes with #197. The rest are refused at load. Built: the lint is an enum in the schema, and a unit test pins the enum to the four. `not_at_all` landed on main (#193) after this branch was cut; the merge of main did not build until the exhaustive match chose for it, and its findings sit in one sentence, so it takes an entry by this rule. Keep, or refuse it?
4. A quote that is two sentences of the file fails, naming both lines. Built as the status `two_sentences`. Exempting every copy would let an agent paste an exempted sentence elsewhere.
5. A change that adds or changes an entry is an owner change, found by the notice. Built: the notice is the only signal; nothing else blocks it. Whether the repo's merge rule says so is the owner's to write.
6. An entry exempts every occurrence of its lint inside the sentence. A later catalogue or config change that adds hits there is exempted silently. Built as is: should an entry also pin the count of occurrences?
7. A stale entry that predates the change also fails `--diff`, so it blocks every run until a human fixes it. Built so, because a stale entry must never pass. Keep, or limit `--diff` to entries the change touches?
8. An entry for a file its section's `exclude` (#195) removes fails the run, since an excluded file is not selected: "[md] does not select docs/adr/0001.md, and an entry applies only to the files of its own section." That reads as if the entry sits in the wrong section. Should the message name the pattern, as `fix` and `explain` do ("[md] excludes it by ...")?
9. `deslag explain` on a file a section excludes shows no `# allow` rows, as for a file no glob matches, though the check's tally points to `explain` for a file's entries. Should `explain` list an unselected file's entries and mark them as not selected?

### Left open, so this is not "Closes"

A file-level off for #68 (the issue's own doubt: "I'm not sure if it should be off for the whole file"), and `list_growth`'s "the new base is N items". Both stay open on #68. Also left: `counted_inventory` takes an entry when #197 lands.

### Trial

A fresh agent was given only the output of `deslag instructions`, in a repo whose check fails on a book title with an em dash that the README says must be quoted exactly, and was told to make `deslag check` pass. Three runs, each in its own copy of the repo, and each against the texts in this change as they are now:

1. Changed nothing. It named the sentence and gave a reason, as the entry would hold them, and offered `deslag fix` as the human's other choice.
2. Changed nothing, same answer, and left the config alone.
3. Changed nothing, same answer.

No run wrote an entry, edited the config, reworded the title or hid it in code. The texts did not need strengthening after the first set of runs, so there was no second round.

## Testing

- [x] `make ci-fast`: exit 0
- [x] `make test`: exit 0. No golden file, corpus pin or case output of main moved; the only case outputs that changed are `banned_chars/allow_prefix`, `allow_reworded` and `allow_two_sentences`, whose reports now cut each quoted sentence at 60 characters.
- [x] `cargo run -q -- check --base origin/main`: exit 0
- [x] `tests/allow.rs`: 30 tests on `--diff` (a failed entry shown whatever the change touches, and after a committed rename), `--base`, `explain`, the three formats, the `rust` section, two lints on one sentence, an entry for a lint that is off, a file the section does not select, a file that is not there, `fix`, a space of another width or a zero-width space added to an exempted sentence, a rewrap with tabs and CRLF, a reason that shows as nothing, a TOML escape naming a zero-width space, a quote that holds an invisible character whether or not the config bans it (an emoji with a zero-width joiner, U+202E that `ban` bans, a zero-width space with the `invisible` group off: each entry loads, applies when the lint finds the sentence, fails as `no_finding` when it finds nothing there, and shows the character as `<U+XXXX>` in explain, stderr and the json `report`), a wrapped block quote, a leading byte order mark, the cap of three sentences in a report, and the acknowledgements
- [x] 18 cases under `tests/cases/`: `banned_chars/allow_*` (applied, others stay, rewrapped, reworded, a quote that is a prefix or a middle of a longer sentence, a no-break space added to the sentence, two sentences, no reason, an invisible reason, `fix` sparing an exempted em dash, no file, wrong section, lint off, `--base`), `banned_phrases/allow_applied`, `verbs_no_nouns/allow_applied`, `not_at_all/allow_applied` and `max_size_bytes/allow_refused`
- [x] Unit tests in `src/config/allow.rs` (load errors; for every lint, a quote that holds a joiner, a bidi mark, a variation selector, a tag character, a non-ASCII space, a tab, CR or LF loads and one with NUL, BEL, ESC, DEL, NEL or CSI is refused; a quote of only a no-break space, an ideographic space or a zero-width space is not empty; refused lints with their knobs, duplicates, the schema enum, the JSON-array form) and `src/lint/allow.rs` (what an entry keeps; sentence matching with non-ASCII spaces, wrapped block quotes, a `>` in a wrapped code span, a lone CR in Markdown and in a comment, and the byte order mark; the report's three closest sentences, in file order, a tie going to the earlier one, compared and quoted only to 60 characters; the merge that finds sentences with a finding, against places that run past a sentence; a notice showing the quote folded with its invisible characters as code points)
- [x] Mutations, each applied to this commit and run against `--lib`, `tests/allow.rs` and `tests/cases.rs`; each made a test fail:
  - block-quote markers stripped through the first token of a wrapped line, not only before it: `a_wrapped_block_quote_matches_its_quote_without_the_markers`
  - a quote judged empty by `trim`, which strips a no-break space: `a_quote_may_hold_any_character_but_a_control_character_other_than_a_tab_cr_or_lf`
  - the closest sentences left in order of distance: three tests of the report
  - a tie for the last place going to the later sentence: `a_tie_for_the_last_place_in_a_report_goes_to_the_earlier_sentence`
  - the notice printing the quote raw: `a_notice_shows_the_quote_folded_and_its_invisible_characters_as_code_points`
  - the quote refusing every invisible character again: four tests, among them `a_quote_holds_an_invisible_character_whether_or_not_the_config_bans_it`
  - a lone CR folding again: `a_lone_cr_ends_a_line_of_markdown_and_never_folds_in_a_comment`
  - the quote folded one way for every sentence, in `matching`, `closest`, `held()` and `is_same_as`: `a_quote_folds_a_lone_cr_by_how_each_sentence_of_a_markdown_file_is_read`, `a_report_keeps_a_lone_cr_of_the_quote_for_a_comment_that_holds_one`, `a_report_marks_a_sentence_by_whether_it_is_read_as_a_comment`, `a_lone_cr_makes_a_quote_another_entry_where_a_line_break_does_not`, and end to end `a_quote_with_a_lone_cr_exempts_a_markdown_sentence_however_it_is_wrapped`
  - the report quoting a sentence whole: `a_report_compares_and_quotes_only_the_start_of_a_long_sentence` and the case outputs
  - the merge checking only the first place inside a sentence: `a_place_that_runs_past_a_sentence_does_not_hide_a_later_one_inside_it`
- [x] `tests/instructions.rs`: the `allow` section ends the lints topic, its example loads, the guide says only a human exempts a sentence, and step 5 keeps `--dry-run` and the comment or fence a report names
- [x] The trial above

## References

- Part of #68
- Related: #197 (its `counted_inventory` lint will take an entry), #195 (merged in from main: each section holds both `exclude` and `allow`, `exclude` first, since a config written as a JSON array reads by position)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Primarily authored by AI (whether PR, Issue, Whatever) area/config Has to do with deslag configuration (deslag.yaml, etc.) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config: glob exemptions

1 participant