Repository navigation
feat: exempt one sentence from a lint with an allow entry - #199
Merged
Merged
Conversation
A dated record, a quoted title or an example of a lint's defaults must sometimes stay as written. With no way to say so, an agent rewords the sentence to slip past the check. An entry in a section's `allow` list names a file, a lint, the exact sentence and a reason. Only banned_chars, banned_phrases and verbs_no_nouns take one; the config refuses the rest at load, and names the knob each of them has. The sentence is matched with whitespace collapsed, so a rewrap keeps the entry. Matching runs in check_text, so check, fix and --diff agree. Only the occurrences of that lint inside the one sentence are dropped, and never a verdict on the whole file. An entry that stops holding fails the run with exit 1: no such file, the section does not select it, no such sentence, the quote is two sentences, or the lint finds nothing in it. Its report says why, and says that an agent may delete an entry but never write or change one. Each run prints how many entries applied. An entry the change adds, or whose reason it changes, is a notice with --base or --diff, found by comparing the config at the merge base. The notice does not fail the run, so that review is the gate. Also: explain lists a file's entries, json has `exemptions`, sarif marks a dropped occurrence as suppressed and reports a failed entry under the rule `allow`, and github prints an error or a notice on the config. The guide and `deslag instructions lints` tell an agent that only a human writes an entry. Part of #68.
5 tasks done
Fold only spaces, tabs and line breaks when a quote is compared with a sentence. Any other character, a no-break space included, must match, so a banned character added to an exempted sentence fails the entry instead of being dropped with it. Refuse control, format and other invisible characters in the path, the quote and the reason of an entry. The quote of a banned_chars entry may still name a character that lint bans, written as a TOML escape. Leave out a block quote's > and the byte order mark that opens a file when matching, so a wrapped quote and the first sentence of a file are quoted as they read. Never hide a failed entry in --diff. Quote the three sentences closest to the quote in a failed entry's report and count the rest. Say in the docs what check_file and the json findings hold, and that sarif cannot point at an entry's line. Credit unicode-safety-check and charcheck, and restore --dry-run and the comment or fence advice in the guide.
Finding the text of a sentence searched every token for each point, so one entry made a large file quadratic: 32,000 lines took 12.6s with an entry against 0.4s without. A binary search finds the next token now, and a merge finds the sentences that hold a finding. A stale report compares and quotes only the first 60 characters of each sentence, so a long sentence no longer makes the report as long as itself. A quote may now hold any character but a control character other than a tab, CR or LF, whatever the lint. It must equal the sentence, which the file holds anyway, so refusing a character only kept a human from exempting a sentence with an emoji joiner or a mark the config does not ban. The path and the reason still refuse every character that shows as nothing or acts on the reader. Reports, notices and explain write such a character as <U+XXXX> in every format. Say in the docs that a failed entry fails --diff wherever its file is, that only spaces, tabs and line breaks fold, and that a > inside a code span wrapped across block quote lines stays in the sentence. A lone CR in a comment is a character of its line, as the comment's reader reads it; in Markdown it ends the line.
main added the not_at_all lint. The match on Lint in the allow config has no wildcard, so the merge does not build until the new lint chooses. Its findings sit in one sentence, as those of verbs_no_nouns do, so it takes an entry by the rule the allow config states. The schema, the load error for an unknown lint, the field doc, the four allow changelog entries and the allow section of the lint instructions name it. A new case, not_at_all/allow_applied, shows an entry applied while another finding in the file stays.
The config says a line break in a quote is LF or CR LF, or a lone CR in Markdown, but the quote folded the same way for every document, so a lone CR in a quote never matched a Markdown sentence wrapped any other way. Fold the quote as each sentence is read. In Markdown a lone CR folds with spaces, tabs and line feeds. In a comment it stays a character, as before. Applying, the check for a missing sentence, the check for two sentences, the closest sentences in a report and `deslag explain` all match through the same fold.
# Conflicts: # src/config/cpp.rs # src/config/md.rs # src/config/rust.rs # src/config/toml.rs # src/explain/mod.rs # src/instructions/guide.md
The quote doc said a lone CR in a comment is a character of its line. It ends a C++ `//` or TOML `#` comment, so the doc now says so. Pin that a report folds the quote as each sentence is read, that a sentence is marked as a comment or not, that two quotes are told apart by a lone CR, and that a lone CR in a quote exempts a Markdown sentence through `deslag check`.
webern
marked this pull request as ready for review
October 17, 2026 21:59
Owner
Author
|
Questions for the owner before merge. Each is set out under "Owner questions, as built" in the description, with what is built.
Found while testing, and not changed here: in a Markdown file with lone-CR line endings, nothing after the first fenced code block is linted, because the parser does not close the fence. An entry for a sentence after such a fence fails as |
This was referenced Oct 25, 2026
webern
added a commit
that referenced
this pull request
Oct 31, 2026
## AI Summary An `allow` entry (#199) exempts one sentence from one lint, and it drops only that lint's findings. `deslag fix` takes its edits from the findings left over, so it still edited the quoted sentence for every other lint. Take a config that bans dashes and the phrase "in order to", with this entry: ```toml [[md.allow]] path = "README.md" lint = "banned_phrases" quote = "We did it in order to win — fast." reason = "A quoted line." ``` On main, `deslag fix` replaces the dash with `-`. The quote no longer matches, the entry fails as `no_such_sentence`, the phrase finding comes back, and the run exits 1 with a report saying only a human may write or change an entry. The agent cannot fix the file and cannot repair the entry. Now `fix` makes no edit inside a sentence that any `allow` entry for the file quotes, whatever the entry's lint. Each such place is listed under "deslag cannot fix these" with a reason that names the entry: ``` deslag cannot fix these in README.md: line 3: U+2014 em dash "—"; write `-` deslag.toml's md.allow[0] quotes this sentence, so an edit would stop the quote matching; do not edit it by hand either: the human changes the sentence and the entry together ``` The rest of the file is fixed as before. `check` is unchanged, so the dash stays a `banned_chars` finding for the human to decide on. The change is in `fix` (`src/fix/mod.rs`), not in how an entry applies, so an entry is what #199 built. A quote that two sentences equal holds both, since an edit to either changes how the entry comes out. A held place is any edit whose bytes reach into the sentence. Places a lint names no edit for keep the lint's own reason. No changelog entry: this is a bug fix. ## Testing - [x] `make ci-fast`: exit 0 - [x] `make test`: exit 0. No existing case output or golden file moved. - [x] New case `tests/cases/banned_chars/allow_fix_held`: the config and file above plus a second dash outside the quote. `fix` replaces that dash, leaves the quoted one with the reason above, the entry still applies, and the run exits 1 on the dash left. - [x] New unit test in `src/fix/mod.rs`: the held sentence is left and reported as held by `md.allow[0]`, the other dash is fixed, and a second run edits nothing. It fails when the held check is taken out. ## Question for the owner Today `check` reports the dash in the held sentence as an ordinary `banned_chars` finding, with the advice "Write it as listed, or reword", and the run exits 1 on it. The JSON and SARIF outputs carry nothing about the hold; only the text of `fix` says the sentence is held. Should `check` mark an occurrence inside a sentence that another lint's entry quotes as held, and should the JSON and SARIF outputs carry the hold? ## References - Progresses #68 - Related: #199
5 tasks done
webern
added a commit
that referenced
this pull request
Nov 29, 2026
…erride (#273) ## Human Summary This gives the user the ability to exempt a single lint case. ## Summary Issue #68 asked for two things. The first is a way to exempt one violation, keyed to its place and not to the whole file. The second is a way for a narrower override to turn off a lint that a broader override turned on. Much of the first already exists. `[[<section>.allow]]` entries (#199, #251) exempt one sentence, they require a reason, a tally of them prints on every run, and a stale entry fails the check. `list_growth`, the lint behind #67, was removed in #207, so there was no list count to rebase. What was still missing: - `density` could not be exempted. An `allow` entry for `density` now quotes one whole paragraph or list item, folded the same way a sentence quote is. Any edit to that block makes the entry stale, and the block is judged again. So a paragraph that grows has to be re-exempted by a human, and an entry does not last forever. A failed entry reports `no_such_block`, `two_blocks` or `no_finding`. `deslag fix` leaves a quoted block as it is. A `line` on a `density` entry is refused. - An override can now say `off = ["<lint>", ...]`. This sets each named lint back to unset for the files the override matches. A later override that sets the lint's table turns it back on, with only the settings that table sets. Loading the config (exit 2) refuses an unknown lint, a lint named twice, a lint the same override both turns off and sets, and an `off` for a lint that no table in the section turns on. `deslag explain` shows `# <lint>: off, by override N`. The field is marked `since = "next"` with a default of `[]`, so it needs no schema version bump. Exemptions stay in the config, with no in-file marker. That keeps to the existing rule that there is one way to exempt a finding. `guide.md` and `lints/allow.md` no longer say that an override cannot turn a lint off, or that an entry only exempts a sentence. They keep the rule that an agent proposes an entry or an `off` and a human writes it. The summary line, the SARIF rule text and the docs for entries now say "text" rather than "sentence", since an entry can name a paragraph. `.agents/deslag.toml` is unchanged. The #67 workaround was already removed along with `list_growth`. ## Testing - [x] `make ci-fast`: exit 0, including `check-deslag` on the repo itself - [x] `make test-tools`: exit 0 - [x] New `density` cases: `override_off`, `allow_applied`, `allow_fails` (covering `no_such_block` and `no_finding`), `allow_rust` and `allow_fix_held` - [x] Unit tests for the `off` load errors, the merge order and `two_blocks`, plus a new `deslag explain` test - [x] Expected outputs regenerated with `make fix-test-output`, and the diff checked. Existing `density` cases changed only by the added advice sentence and the sentence-to-text wording. ## References - Closes #68 - Related: #67, #199, #207, #251
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.
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
allowentry. It is a config entry of a section (md,rust,cppandtomleach have the list) that names one file, one lint, one exact sentence and a reason: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 lintsand everysetting.<section>.allowchangelog entry tell an agent to leave the sentence and give the human its text and a reason. The repo's own.agents/deslag.tomlgets no entry.How it works:
reasonorquote, apaththat 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. Aquotemay 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'sbanlist bans, a zero-width space the config does not ban. Apathorreasonmay 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; areasonmay hold a tab, CR or LF. The checks read the value after parsing, so a TOML escape is no way round them. Reports, notices anddeslag explainwrite each character that shows as nothing or acts on the reader as<U+XXXX>, on stderr and in the jsonreport, 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 ofmax_size_bytes. An exhaustive match onLintmakes each new lint choose.check_text, socheck,fixand--diffagree. 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...., so the work per sentence and the report stay bounded however long a sentence is.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".exemptions, each with its fields, status, the marks it dropped, and whether the change added it.FORMAT_VERSIONstays; a run with no entry prints noexemptions. A failed entry is inexemptionsand not infindings, so a run that exits 1 can have an emptyfindings.suppressions(external, the reason asjustification), and a failed entry is a result of the ruleallowon 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 asmd.allow[0].::errorand an added one a::notice, on the config.--baseor--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.--diffnever 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--diffpass what--baseand the whole tree fail. The README,deslag check --helpand guide step 6 say so; to stay within the guide's byte budget, step 4 drops its description of what each# prose regionsline holds, whichdeslag explainprints 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:
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_growthis out: its findings exist only against a base, so an entry would fail on main the commit after it lands.Owner questions, as built
Report::is_cleancounts failed entries, and the run exits 1.--baseor--diff, is a notice that does not fail. Built: adeslag: notice:line on stderr,added: truein json, a::noticein github. A failure would keep a human's own entry red; review is the gate, and the notice shows the reviewer each one.banned_chars,banned_phrases,verbs_no_nounsandnot_at_all.counted_inventorycomes with feat: add the counted_inventory lint for counts of things #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_alllanded on main (feat: lint negations padded with "at all" #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?two_sentences. Exempting every copy would let an agent paste an exempted sentence elsewhere.--diff, so it blocks every run until a human fixes it. Built so, because a stale entry must never pass. Keep, or limit--diffto entries the change touches?exclude(feat: exclude globs in sections and overrides #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, asfixandexplaindo ("[md] excludes it by ...")?deslag explainon a file a section excludes shows no# allowrows, as for a file no glob matches, though the check's tally points toexplainfor a file's entries. Shouldexplainlist 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_inventorytakes 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 makedeslag checkpass. Three runs, each in its own copy of the repo, and each against the texts in this change as they are now:deslag fixas the human's other choice.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
make ci-fast: exit 0make test: exit 0. No golden file, corpus pin or case output of main moved; the only case outputs that changed arebanned_chars/allow_prefix,allow_rewordedandallow_two_sentences, whose reports now cut each quoted sentence at 60 characters.cargo run -q -- check --base origin/main: exit 0tests/allow.rs: 30 tests on--diff(a failed entry shown whatever the change touches, and after a committed rename),--base,explain, the three formats, therustsection, 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 thatbanbans, a zero-width space with theinvisiblegroup off: each entry loads, applies when the lint finds the sentence, fails asno_findingwhen it finds nothing there, and shows the character as<U+XXXX>in explain, stderr and the jsonreport), a wrapped block quote, a leading byte order mark, the cap of three sentences in a report, and the acknowledgementstests/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,fixsparing an exempted em dash, no file, wrong section, lint off,--base),banned_phrases/allow_applied,verbs_no_nouns/allow_applied,not_at_all/allow_appliedandmax_size_bytes/allow_refusedsrc/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) andsrc/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)--lib,tests/allow.rsandtests/cases.rs; each made a test fail:a_wrapped_block_quote_matches_its_quote_without_the_markerstrim, which strips a no-break space:a_quote_may_hold_any_character_but_a_control_character_other_than_a_tab_cr_or_lfa_tie_for_the_last_place_in_a_report_goes_to_the_earlier_sentencea_notice_shows_the_quote_folded_and_its_invisible_characters_as_code_pointsa_quote_holds_an_invisible_character_whether_or_not_the_config_bans_ita_lone_cr_ends_a_line_of_markdown_and_never_folds_in_a_commentmatching,closest,held()andis_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 enda_quote_with_a_lone_cr_exempts_a_markdown_sentence_however_it_is_wrappeda_report_compares_and_quotes_only_the_start_of_a_long_sentenceand the case outputsa_place_that_runs_past_a_sentence_does_not_hide_a_later_one_inside_ittests/instructions.rs: theallowsection ends the lints topic, its example loads, the guide says only a human exempts a sentence, and step 5 keeps--dry-runand the comment or fence a report namesReferences
counted_inventorylint will take an entry), feat: exclude globs in sections and overrides #195 (merged in from main: each section holds bothexcludeandallow,excludefirst, since a config written as a JSON array reads by position)