-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix corner case involving terminal backslash after fixing
W293
(#5172)
## Summary Fixes #4404. Consider this file: ```python if True: x = 1; \ <space><space><space> ``` The current implementation of W293 removes the 3 spaces on line 2. This fix changes the file to: ```python if True: x = 1; \ ``` A file can't end in a `\`, according to Python's [lexical analysis](https://docs.python.org/3/reference/lexical_analysis.html), so subsequent iterations of the autofixer fail (the AST-based ones specifically, since they depend on a valid syntax tree and get re-parsed). This patch examines the line before the line checked in `W293`. If its first non-whitespace character is a `\`, the patch will extend the diagnostic's fix range to all whitespace up until the previous line's *second* non-whitespace character; that is, it deletes all spaces and potential `\`s up until the next non-whitespace character on the previous line. ## Test Plan Ran `cargo run -p ruff_cli -- ~/Downloads/aa.py --fix --select W293,D100 --no-cache` against the above file. This resulted in: ``` /Users/evan/Downloads/aa.py:1:1: D100 Missing docstring in public module Found 2 errors (1 fixed, 1 remaining). ``` The file's contents, after the fix: ```python if True: x = 1;<space> ``` The `\` was removed, leaving the terminal space. The space should be handled by `Rule::TrailingWhitespace`, not `BlankLineWithWhitespace`.
- Loading branch information
1 parent
64bd955
commit 62aa77d
Showing
4 changed files
with
24 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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