-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule E703, W293
fails to fix file
#4404
Comments
Feel free to assign this to me, I can take a look! |
Hmm, I can't seem to replicate this. I copied the Markdown file from the description and ran |
Me neither -- gonna close for now... |
I added reproduction file. Looks that pasting code to github changes some bytes, so proably I should always provide example file
|
Hmm. Even with the new file, it seems to work properly...
|
have still problem(W293 is not enabled by default)
not have any problems |
Sorry for the delay - work has been insane and have had to step back from the project for a bit. Just now getting to this. I think I've isolated the problem. Basically, running
I tested permutations of the various errors; it looks like the problem isn't with
So I think what's happening is that the interaction between I think what may (more a note to myself than anything) be happening is that |
Relatedly, @charliermarsh I wonder if we should look into our error reporting to see why the correct pair wasn't outputted. From what I can tell, in this case we only output what rules we've already fixed, so |
Looks like the actual content of the file ends up being: 'if True:\n'
' x = 1; \\\n'
' ' I was able to replicate the issue by attempting to run (in a separate file): if True:
x = 1; \ Note the missing newline after the I think that's the root cause of the issue here - stripping the blank line strips all whitespace, leaving the last It also seems like the issue only throws on Just posting my updates here for future reference - sorry if that's bad form or if that's supposed to go in the PR or something. Regardless, I'll take a look at why the AST rules fail with Wondering if this is related to #4828 E: Actually, this may only be related to |
This is very likely related to/duplicated by #4828. |
@charliermarsh Would actually like your thoughts on this, since it may require some deeper fixes. I've been hacking around to see what's going on. Basically, we take the initial file (note that the last line is 3 spaces): if True:
x = 1; \
We then, according to the fix of I was originally looking at including I then realized that the issue is due to the way that we perform autofixes. We fix a line, then loop over the new AST and attempt to re-parse it. This second parse introduces the error due to the RCA above. The issue here is that the fix actually spans fixing the two lines simultaneously (e.g., removing I'd like your input on how to fix this. It seems like we have two options:
If you have a cleaner solution in mind, or can offer any advice, that'd be much appreciated. Thanks! |
## 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`.
Merge match arms in `StringParser.parse_formatted_value`
Ruff f5be3d8
Command -
ruff --fix
with config with all rules enabledFile
shows error
EDIT - file - aa.py.zip
The text was updated successfully, but these errors were encountered: