Skip to content

[refurb] Add fix safety section to FURB122 - #18842

Merged
dylwil3 merged 2 commits into
astral-sh:mainfrom
MeGaGiGaGon:patch-4
Jun 23, 2025
Merged

dylwil3 merged 2 commits into
astral-sh:mainfrom
MeGaGiGaGon:patch-4

Conversation

@MeGaGiGaGon

Copy link
Copy Markdown
Contributor

Summary

Part of #15584

This adds a Fix safety section to for-loop-writes (FURB122).

The fix/lint was introduced in #10630
No reasoning is given on the unsafety in the PR/code.
The unsafety is determined here:

let applicability = if checker.comment_ranges().intersects(for_stmt.range) {
Applicability::Unsafe
} else {
Applicability::Safe
};

Unsafe fix demonstration:
playground

with open("issue.txt", "w") as f:
    for i in range(10):
        # will be deleted
        f.write(str(i))

Test Plan

@MeGaGiGaGon MeGaGiGaGon mentioned this pull request Jun 20, 2025
21 of 71 tasks
@github-actions

github-actions Bot commented Jun 21, 2025 •

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser
MichaReiser requested a review from dylwil3 June 21, 2025 15:38

@dylwil3 dylwil3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

Comment thread crates/ruff_linter/src/rules/refurb/rules/for_loop_writes.rs Outdated
@dylwil3
dylwil3 enabled auto-merge (squash) June 23, 2025 13:18
@dylwil3
dylwil3 merged commit 861dff1 into astral-sh:main Jun 23, 2025
@dylwil3 dylwil3 added the documentation Improvements or additions to public-facing documentation label Jun 23, 2025
@MeGaGiGaGon
MeGaGiGaGon deleted the patch-4 branch June 23, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to public-facing documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants