[ruff] Fix for RUF102 should delete entire comment#23380
Conversation
Prevents generating invalid syntax for noqa comments with trailing text Fixes #23349
|
|
I'm not sure about this... could we delete just the At the very least it feels like the fix should be unsafe in this case? (sort of surprised it isn't always unsafe, to be honest) |
|
FWIW, this matches the behavior of the RUF100 fix when all codes are unused, which also deletes the entire comment. |
|
Also worth noting that currently this fix is only relevant if the user has RUF100 disabled, because otherwise that rule would also flag this line and offer a fix to remove the entire comment: RUF100: RUF102: |
|
Somehow the situation of RUF102 feels slightly different than that of RUF100. In RUF100, we're pretty confident it's one of our rules being suppressed, and we helpfully see it's not doing anything. In this case we think we've identified some wrong code, but it may be serving some purpose unknown to us. But I am happy to be overruled! Maybe we should separately put something like this https://docs.astral.sh/ruff/rules/unused-noqa/#conflict-with-other-linters in the docs for RUF102 as well? (can be a separate PR) |
Take a look at my examples above. RUF100 will fire for a noqa with an "unknown" code, and suggest to fix it by removing the code and/or comment. This is a behavior overlap with RUF102, to be clear. |
|
Hmm... well that seems weird. Should we remove that behavior from RUF100? Sorry this discussion keeps sprawling in scope. |
|
Also considered that this matches the behavior for how the new range suppressions fix RUF100/102/103 errors, where they also assume anything up to |
ntBre
left a comment
There was a problem hiding this comment.
Thanks! This makes sense to me, and it's nice to reuse delete_comment and clean up some of the whitespace issues in the previous fix. Should we add a test case specifically for the syntax error?
We may want to open follow-up issues for some of the other discussion here, but I think this is fine to land to resolve the syntax error.
Prevents generating invalid syntax for noqa comments with trailing text
Fixes #23349