Skip to content

fix: leave a sentence an allow entry quotes alone in fix - #225

Merged
webern merged 2 commits into
mainfrom
m/deslag-fixallow
Oct 31, 2026
Merged

webern merged 2 commits into
mainfrom
m/deslag-fixallow

Conversation

@webern

@webern webern commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

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:

[[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

  • make ci-fast: exit 0
  • make test: exit 0. No existing case output or golden file moved.
  • 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.
  • 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

An allow entry drops only its own lint's findings, so fix still
edited the sentence for the other lints. With an entry that exempts
"in order to" in a sentence that also holds an em dash, fix replaced
the dash, the quote stopped matching, the entry failed and the phrase
finding came back. The report then told the agent that only a human
may touch the entry, and the agent could neither fix the file nor
repair the entry.

Fix now makes no edit inside a sentence that any entry for the file
quotes, for any lint, and reports each such place as unfixed with a
reason that names the entry. Check is unchanged.
The reason told the agent to fix the other findings, which fix had
already done, and said the entry exempts the sentence, which is not
so when the entry has failed. It now names the config and the entry,
says the quote would stop matching, and says not to edit the sentence
by hand either.

The unit test drops an assert on the text of a value it built, and
checks the held reason on the second run too.
@webern webern added bug Something isn't working ai Primarily authored by AI (whether PR, Issue, Whatever) area/lint Deals with the linting algorithms themselves, how they work. labels Oct 30, 2026
@webern
webern added this pull request to stack #231 October 30, 2026 09:55
@webern
webern marked this pull request as ready for review October 31, 2026 08:19
@webern
webern merged commit 49d21db into main Oct 31, 2026
6 checks passed
@webern
webern deleted the m/deslag-fixallow branch October 31, 2026 08:22
webern added a commit that referenced this pull request Oct 31, 2026
… name a line once (#230)

## AI Summary

This is stacked on #225, the fix that leaves quoted sentences alone,
which edits the same code in `src/fix/mod.rs`. It fixes two reports that
said more than they should.

First, `deslag fix` printed "deslag did not fix bin.md: it is not valid
UTF-8, ..." about every file that is not valid UTF-8, on every run, even
a file like `hello \xff world` with nothing in it to fix. `deslag check`
reads such a file with each bad byte replaced by one `$`
(`src/lint/mod.rs`, `decode`), lints it like any other file, and says
nothing about its encoding. Now `fix` reads the file the same way and
works out its edits without writing any. It reports the file as not
UTF-8 only when it would make an edit there. Otherwise it skips the
file, the way it skips a UTF-8 file with nothing to fix, and the `check`
that `fix` runs afterwards reports what the lints find, as it does
today. A finding that no edit exists for, such as a banned phrase, does
not make `fix` report the file.

Second, an `allow` entry whose quote matched two sentences on the same
line reported "holds the quote as 2 sentences, on lines 1, 1", and
`deslag explain` listed the entry at "lines 1, 1". The fix is in
`on_lines` (`src/lint/mod.rs`), which every report uses to name lines:
it now names a line once, however often it is given. The report now says
"2 sentences, on line 1"; the count still comes from the sentences.
`banned_chars` and `fix` deduplicated their lines before calling it, and
no longer do. The fix sits there rather than only in `src/lint/allow.rs`
so that `explain` gets it too.

Two new cases under `tests/cases/banned_chars/`:

- `fix_not_utf8`: a file with a bad byte and a banned phrase. `fix` says
it fixed nothing, and `check` reports the phrase.
- `allow_two_sentences_one_line`: an entry whose quote is twice on one
line.

Each case fails with its source change reverted. The existing tests
where a non-UTF-8 file holds a dash `fix` would replace still pass
unchanged, so that report stays.

## Testing

- [x] `make ci-fast`: exit 0
- [x] `make test`: exit 0
- [x] Both reports reproduced by hand in a scratch repo before the
change, and gone after it

## References

- Stacked on #225
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/lint Deals with the linting algorithms themselves, how they work. bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant