Merged
Conversation
…wn, without loading entire file into memory.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the fix_trailing_whitespace.rs module to improve handling of trailing whitespace, particularly for Markdown files where two trailing spaces indicate a line break. The refactor resolves a clap parsing issue with custom character sets and optimizes the file processing logic.
Key changes:
- Introduced a custom
Charstype to work around clap's inability to parse--chars=" \t"correctly - Rewrote the file processing logic to use async I/O with temporary files and only write back when changes occur
- Added comprehensive test coverage for various scenarios including CRLF handling, Unicode characters, and edge cases
…refligit into upgrade_fix_trailing_whitespace
fix_trailing_whitespace
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.
Closes #294
Closes #223
This PR refactors
fix_trailing_whitespace.rs, improves the handling of trailing whitespace, especially for Markdown files where exactly two trailing spaces at the end of a line indicate a line break. Related to #294.Main changes
Charstype to encapsulate a custom list of characters to trim, resolving an issue whereclapcannot correctly parse--chars= \tintoVec<char>.fix_filefunction logic:About
Charstype encapsulation andclapparsing issueWhen using
clapto parse command-line arguments, directly parsing a parameter like--chars=" \t"into aVec<char>runs into issues because:clapsplits arguments by whitespace by default, causing strings containing spaces and tabs to be misparsed or treated as a single element.--chars=" \t"may not correctly convert into a character vector containing space and tab characters.To solve this, we implemented a custom
Charstype with theFromStrtrait:Charswraps aVec<char>internally and manually converts the input string into a vector of characters.This workaround bypasses
clap's default parsing limitations and enables flexible handling of user-defined trim character sets.Trailing two-space preservation rules and reference
This behavior is consistent with the original implementation in the open-source project pre-commit. For example: