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

Account for selector specificity when merging extend_unsafe_fixes and override extend_safe_fixes #8444

Merged

Conversation

lukaspiatkowski
Copy link
Contributor

Summary

Prior to this change extend_unsafe_fixes took precedence over extend_safe_fixes selectors, so any conflicts were resolved in favour of extend_unsafe_fixes. Thanks to that ruff were conservatively assuming that if configs conlict the fix corresponding to selected rule will be treated as unsafe.

After this change we take into account Specificity of the selectors. For conflicts between selectors of the same Specificity we will treat the corresponding fixes as unsafe. But if the conflicting selectors are of different specificity the more specific one will win.

Test Plan

Tests were added for the FixSafetyTable struct. The check_extend_unsafe_fixes_conflict_with_extend_safe_fixes_by_specificity integration test was added to test conflicting rules of different specificity.

Fixes #8404

Copy link
Member

@zanieb zanieb 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 for contributing! I have some questions about simplifying the implementation but otherwise this looks great.

crates/ruff_linter/src/settings/mod.rs Outdated Show resolved Hide resolved
crates/ruff_linter/src/linter.rs Outdated Show resolved Hide resolved
crates/ruff_linter/src/settings/fix_safety_table.rs Outdated Show resolved Hide resolved
crates/ruff_linter/src/settings/fix_safety_table.rs Outdated Show resolved Hide resolved
@zanieb zanieb changed the title Change extend_unsafe_fixes to override extend_safe_fixes per Specificity Account for selector specificity when merging extend_unsafe_fixes and override extend_safe_fixes Nov 2, 2023
@zanieb zanieb added the configuration Related to settings and configuration label Nov 2, 2023
Copy link
Contributor

github-actions bot commented Nov 2, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@astral-sh astral-sh deleted a comment from github-actions bot Nov 2, 2023
@lukaspiatkowski
Copy link
Contributor Author

I was going to ask if there is a chance this will make it to the next release, but I see the release happened yesterday :) is this good to go as is @zanieb?

@zanieb
Copy link
Member

zanieb commented Nov 7, 2023

Sorry for the delay this one got lost!

@lukaspiatkowski
Copy link
Contributor Author

LGTM

@zanieb zanieb merged commit 03303a9 into astral-sh:main Nov 7, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Related to settings and configuration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage of extend-unsafe-fixes = ["ALL"] option
2 participants