-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
When W291 (trailing-whitespace) is enabled, ruff warns about trailing whitespace in multiline strings.
When --fix is passed, ruff modifies the multiline string. This could result in a behavior change of the python code.
Repro:
# repro.py
string = """
this line has trailing whitespace
"""$ ruff repro.py --isolated --select W291
repro.py:3:34: W291 [*] Trailing whitespace
Found 1 error.
[*] 1 potentially fixable with the --fix option.
$ ruff repro.py --isolated --select W291 --fix # This modifies the multiline string!
Found 1 error (1 fixed, 0 remaining).
$ ruff --version
ruff 0.0.278
I noticed that the implementation trailing_whitespace categorizes the --fix action as Fix::safe_edit. I feel that modifying a multiline string is not safe; it can change the behavior of my python code. The doc for Applicability::Safe say:
/// The fix is safe and can always be applied.
/// The fix is definitely what the user intended, or it maintains the exact meaning of the code.
I feel that this does not apply to W291 as implemented.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working