Repository navigation
fix: report a non-utf-8 file from fix only when it would edit it, and name a line once - #230
Merged
Merged
Conversation
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
marked this pull request as ready for review
October 31, 2026 08:21
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.
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 fixprinted "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 likehello \xff worldwith nothing in it to fix.deslag checkreads 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. Nowfixreads 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 thecheckthatfixruns afterwards reports what the lints find, as it does today. A finding that no edit exists for, such as a banned phrase, does not makefixreport the file.Second, an
allowentry whose quote matched two sentences on the same line reported "holds the quote as 2 sentences, on lines 1, 1", anddeslag explainlisted the entry at "lines 1, 1". The fix is inon_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_charsandfixdeduplicated their lines before calling it, and no longer do. The fix sits there rather than only insrc/lint/allow.rsso thatexplaingets it too.Two new cases under
tests/cases/banned_chars/:fix_not_utf8: a file with a bad byte and a banned phrase.fixsays it fixed nothing, andcheckreports 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
fixwould replace still pass unchanged, so that report stays.Testing
make ci-fast: exit 0make test: exit 0References