Skip to content

[refurb] Make fix unsafe if it deletes comments (FURB110)#22768

Merged
ntBre merged 3 commits intoastral-sh:mainfrom
chirizxc:FURB110
Jan 22, 2026
Merged

[refurb] Make fix unsafe if it deletes comments (FURB110)#22768
ntBre merged 3 commits intoastral-sh:mainfrom
chirizxc:FURB110

Conversation

@chirizxc
Copy link
Contributor

Summary

Test Plan

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 20, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre added the fixes Related to suggested fixes for violations label Jan 21, 2026
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think the range check is too aggressive in some cases here. We should make sure comments are actually being removed before marking a fix unsafe.

17 | # Test for y.
18 | y
19 | )
note: This is an unsafe fix and may change runtime behavior
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check may be too aggressive in this case, if I'm reading the diff correctly. It looks like the contents of the parentheses aren't actually modified here, so the comment is preserved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x, y = 1, 2

z = (
    # 1
    x) if (  # 2
    x
) else (
    # Test for y.
    y
)

In examples like these, there will also be deletions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the right thing to do is in this case. The current rule may limit some cases, but at least there won't be any deletions in save fixes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guess you're right. I tried playing with this myself and couldn't find a way to avoid these cases without also making some comment deletions safe incorrectly.

…_operator.rs

Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I'll merge this once today's release is finished.

@ntBre ntBre merged commit 009bbb5 into astral-sh:main Jan 22, 2026
41 checks passed
@chirizxc chirizxc deleted the FURB110 branch January 23, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants