Closed yury-fedotov closed 1 week ago
I'm unsure -- I think the current behavior is intentional. But either seems reasonable.
I think deleting the entire comment is fine, for as long as it doesn't delete anything coming after another #
:
- return data # noqa: RET504 # fmt:skip
+ return data # fmt: skip
I agree!
I think this is all here if anyone is interested in a good issue: https://github.com/astral-sh/ruff/blob/940df67823dc5237f95d36a94ef3a74dc4bd36fb/crates/ruff_linter/src/fix/edits.rs#L65
Is there a standard or a strong feeling here on preserving trailing whitespace following 'Preserved' comments? Meaning:
can: x = 1 # noqa # type: ignore
and: x = 1 # noqa # type: ignore
both resolve to: x = 1 # type: ignore
?
or is there a conceivable edge case where that matters?
At any rate, I believe I've mostly got this but will spend some time tomorrow getting the testing framework and everything set up, should work regardless of the above, just changes the logic a bit to save those characters if we want 'em.
It should be fine to remove trailing whitespace but just a note that any other comments shouldn't be deleted (https://github.com/astral-sh/ruff/issues/12251#issuecomment-2226110486).
this was... much better than I expected the first pass to go, will have a PR on this once I figure out what's going on with these, but I'll take 4/2057 as a start!
@jeremeybingham Can you open the PR? I can help you debug these test failures.
will try asap, yes - have "fixed" my way into various fun new failure modes, and am now trying to consolidate the working bits of all that into something that compiles.
I think it applies to all error codes, but let me give an example where I encountered that.
Consider:
Which is a violation of
RET504
- unnecessary assignment.I needed to perform the assignment and
return data
, notreturn do_some_transformations()
, so added anoqa: RET504
with explanation of why I want to bypass the rule:Then I disabled
RET504
inruff
config completely, and thisnoqa
became unused. Here is whereRUF100
comes into play, as it complains on unused error codes, and provides a fix.The fix was:
While I believe it should have been:
As it's probably quite safe to assume that entire content of the comment
noqa
is part of is explaining why a rule should by bypassed.RUF100
ruff check --fix
0.5.1
.