From c73c3442ef8efc1156f55a6de47f9b90fae7f9ca Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Thu, 20 Jun 2024 17:51:04 -0700 Subject: [PATCH] Update [ghstack-poisoned] --- src/fixit/config.py | 14 ++++++++++++-- src/fixit/tests/config.py | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/fixit/config.py b/src/fixit/config.py index af1b7e60..29c64012 100644 --- a/src/fixit/config.py +++ b/src/fixit/config.py @@ -207,6 +207,7 @@ def collect_rules( """ all_rules: Set[Type[LintRule]] = set() + named_enables: Set[Type[LintRule]] = set() if debug_reasons is not None: disabled_rules = debug_reasons else: @@ -222,10 +223,19 @@ def collect_rules( stack.enter_context(append_sys_path(path)) for qualified_rule in config.enable: - all_rules |= set(find_rules(qualified_rule)) + rules = set(find_rules(qualified_rule)) + if qualified_rule.name: + named_enables |= rules + all_rules |= rules for qualified_rule in config.disable: - disabled_rules.update({r: "disabled" for r in find_rules(qualified_rule)}) + disabled_rules.update( + { + r: "disabled" + for r in find_rules(qualified_rule) + if r not in named_enables + } + ) all_rules -= set(disabled_rules) if config.tags: diff --git a/src/fixit/tests/config.py b/src/fixit/tests/config.py index c741375a..35fcdeaa 100644 --- a/src/fixit/tests/config.py +++ b/src/fixit/tests/config.py @@ -476,6 +476,24 @@ def collect_types(cfg: Config) -> List[Type[LintRule]]: ) self.assertListEqual([UseClsInClassmethod], rules) + with self.subTest("disable builtins"): + rules = collect_types( + Config( + disable=[QualifiedRule("fixit.rules")], + python_version=None, + ) + ) + self.assertListEqual([], rules) + + with self.subTest("override broad opt-out"): + rules = collect_types( + Config( + disable=[QualifiedRule("fixit.rules")], + enable=[QualifiedRule("fixit.rules", "UseClsInClassmethod")], + ) + ) + self.assertListEqual([UseClsInClassmethod], rules) + with self.subTest("version match"): rules = collect_types( Config(