Skip to content

fix: report a non-utf-8 file from fix only when it would edit it, and name a line once - #230

Merged
webern merged 2 commits into
m/deslag-fixallowfrom
m/deslag-reportfix
Oct 31, 2026
Merged

webern merged 2 commits into
m/deslag-fixallowfrom
m/deslag-reportfix

Conversation

@webern

@webern webern commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

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

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

References

fix said "deslag did not fix" about every file that is not valid UTF-8,
on every run, even when there was nothing in it to fix. check reads such
a file with each bad byte as one `$` and says nothing about the bytes.

fix now reads the file the same way and works out its edits without
writing them. It reports the file only when it would make an edit there.
Else it skips the file, as it skips a UTF-8 file with nothing to fix, and
check reports what the lints find.

The case fix_not_utf8 holds a bad byte and a banned phrase, which fix has
no edit for.
An allow entry whose quote matches two sentences on one line reported
"holds the quote as 2 sentences, on lines 1, 1", and deslag explain
listed it at "lines 1, 1".

on_lines now names a line once, however many times it is given, so the
report 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 need to.

The case allow_two_sentences_one_line holds the quote twice on one line.
@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:21
@webern
webern merged commit 40524da into main Oct 31, 2026
6 checks passed
@webern
webern deleted the m/deslag-reportfix branch October 31, 2026 08:22
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