Respect Ruff rule code hierarchy in select/ignore lists#1527
Conversation
…nore_rules_in_glob - Add is_rule_covered_by() and reconcile_rules() helpers to rule.py - Modify select_rules() and ignore_rules() in base.py to use hierarchy - Modify ignore_rules_in_glob() in ruff.py to use hierarchy - Add comprehensive tests for helper functions and integration behavior Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/880731be-ca47-4857-9975-4db0116718e6
Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/880731be-ca47-4857-9975-4db0116718e6
…aclass Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/f83674c7-4186-41aa-a4e8-babef65b8bb6
There was a problem hiding this comment.
Pull request overview
This PR improves how Ruff-like rule code lists are managed by respecting prefix-based hierarchy (e.g., TC subsumes TC001, ALL subsumes everything), preventing redundant entries and replacing subsumed specific rules when broader rules are introduced.
Changes:
- Added rule hierarchy helpers in
_tool/rule.py(is_rule_covered_by,reconcile_rules, andRuleReconciliation). - Updated
_tool/base.py(select_rules,ignore_rules) to use reconciliation (including removing subsumed existing rules). - Updated Ruff per-file ignores handling to apply the same reconciliation logic, and added targeted tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/usethis/_tool/rule.py |
Introduces reusable hierarchy + reconciliation primitives for rule list updates. |
src/usethis/_tool/base.py |
Applies reconciliation to global select/ignore rule mutations (adds + removes). |
src/usethis/_tool/impl/base/ruff.py |
Applies reconciliation to Ruff per-file-ignores updates. |
tests/usethis/_tool/test_rule.py |
Adds unit tests for hierarchy detection and reconciliation behavior. |
tests/usethis/_tool/impl/base/test_ruff.py |
Adds integration-style tests validating Ruff config updates (select/ignore/per-file-ignores). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot there's a bug - you're assuming with the current logic that F101 is a subrule of F1 |
…dary Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/94e8b825-bb91-4ef3-9763-5f4a59375e86
Fixed in 794435e. The |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
is_rule_covered_by()andreconcile_rules()helpers in_tool/rule.pyRuleReconciliationfrozen dataclass (replaces tuple return)select_rules/ignore_rulesin_tool/base.pyto use reconciliationignore_rules_in_globin_tool/impl/base/ruff.pyto use reconciliationstartswithwas too crude — now requires a digit boundary after prefix match (e.g.FcoversF101but notFLY)Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.