Skip to content
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

[refurb] Preserve comments (FURB171) #15521

Closed
wants to merge 2 commits into from

Conversation

InSyncWithFoo
Copy link
Contributor

Summary

Resolves #10063.

Test Plan

cargo nextest run and cargo insta test.

Copy link
Contributor

github-actions bot commented Jan 16, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

let iterable_start_to_item_start = TextRange::new(iterable.start(), item_range.start());
let item_end_to_iterable_end = TextRange::new(item_range.end(), iterable.end());

tokens
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if we should add more token based fixes. They add a fair amount of complexity.

Copy link
Contributor Author

@InSyncWithFoo InSyncWithFoo Jan 16, 2025

Choose a reason for hiding this comment

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

I'm unaware of a better solution (how else can I collect the comments from a range?). What do you suggest?

Copy link
Member

Choose a reason for hiding this comment

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

I haven't looked at the fix in detail but my general preference is to accept the removal of comments and instead mark the fix as unsafe if it removes a comment.

Copy link
Contributor Author

@InSyncWithFoo InSyncWithFoo Jan 16, 2025

Choose a reason for hiding this comment

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

This wouldn't be resolving #10063, then. Might as well close it.

Copy link
Member

Choose a reason for hiding this comment

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

There's some discussion around comment handling in fixes here: #9790

Copy link
Member

Choose a reason for hiding this comment

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

That's fair, although there's a reference to the discussion #9790 that wasn't resolved back then.

I'm still leaning towards making the fix as unsafe if there's a comment over implementing all this token handling. While impressive, it's just a lot of complexity, especially if we add it to every rule.

@MichaReiser MichaReiser added the fixes Related to suggested fixes for violations label Jan 17, 2025
@dylwil3
Copy link
Collaborator

dylwil3 commented Jan 30, 2025

I'm still leaning towards making the fix as unsafe if there's a comment over implementing all this token handling. While impressive, it's just a lot of complexity, especially if we add it to every rule.

I agree with this take. I think eventually we should develop a more holistic approach to handling comments, and for now prefer to mark as unsafe (unless the comment handling is very straightforward).

Gonna close this for now, but thank you for the implementation! Maybe it can inspire the future, general approach to comment handling!

@dylwil3 dylwil3 closed this Jan 30, 2025
@InSyncWithFoo InSyncWithFoo deleted the FURB171 branch January 30, 2025 17:20
dylwil3 pushed a commit that referenced this pull request Jan 30, 2025
## Summary

Resolves #10063 and follow-up to #15521.

The fix is now marked as unsafe if there are any comments within its
range. Tests are adapted from that of #15521.

## Test Plan

`cargo nextest run` and `cargo insta test`.
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.

FURB171: Auto-fix deletes comments
4 participants