feat(mojibake): new rule MD083 for mojibake detection - #753
Conversation
|
Thanks for this, the detection genuinely works. I built the branch and ran it over a deliberately mojibaked corpus and it caught every case, including the mixed Before it can land I need the false positives closed. Clean prose in Portuguese, Spanish, German, Greek, Russian, Danish and Icelandic is untouched, and so are symbols, maths, box drawing and typographic punctuation, so this is narrow rather than pervasive. Three things:
There is a structural reason for 1 and 2. These patterns come from ftfy's Also: One process note: no CI has run yet, since fork PRs need workflow approval. I'll approve a run once the above is addressed. |
|
@rvben 👍🏻 Thanks for the feedback, all very valid points.
|
|
Thanks, fast turnaround. Approved CI and verified against a build. Letter enumerations and the config ( CI is red on two new-rule bookkeeping items:
Two false positives still open:
Once 1-3 land and you've decided on 4, I'll merge. Happy to push the two bookkeeping fixes myself if you'd rather focus on the regex. |
|
Mojibake inside an inline code span is now exempt when ignore_code_blocks is set, matching how fenced and indented code blocks are already skipped. A backtick span holds a literal or already-encoded snippet, so a finding there is a false positive. Detection in prose is unaffected, including when a code span shares the line, and multi-line spans are handled via the document-absolute byte offset of each match. Also brings the branch to a green build: - update rule-count guards for the new rule (77 total, MD083 in the opt-in freeze set, 53 configurable) - satisfy clippy (is_empty, char pattern, NFC-normalized test literal) and rustfmt
|
Thanks for this, @guillp. MD083 is a genuinely useful addition and the character-class detection approach is clean. I've merged it and finished the last review item (exempting inline code spans) directly on the branch so it didn't need another round-trip. Mojibake inside a backtick span is now skipped when This ships in v0.2.42. Thanks again for the contribution! |
MD083 is a new opt-in rule (disabled by default) that detects mojibake: text corrupted by decoding UTF-8 as Windows-1252 or ISO-8859-1. Detection uses a regex built from named Unicode character classes and is detection-only (no autofix). Findings inside code are skipped by default via ignore-code-blocks, covering fenced blocks, indented blocks, and inline code spans. Co-authored-by: Ruben J. Jongejan <ruben.jongejan@gmail.com>
What
Add a rule for mojibake detection, as discussed in #687
I made the rule opt-in, but it is probably worth enabling it by default. You decide @rvben :)