Skip to content

Commit

Permalink
config: filter enable/disable all in pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
GiraffeReversed committed Nov 9, 2024
1 parent b557578 commit 1a9ed96
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
25 changes: 25 additions & 0 deletions edulint/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,29 @@ def get_last_value(self, option: Option, use_default: bool) -> Optional[UnionT]:
def _to_immutable(val: UnionT) -> ImmutableT:
return val if not isinstance(val, list) else tuple(val)

@staticmethod
def _resolve_enable_disable_all(pylint_args: List[str]) -> List[str]:
result = []
all_set, enable = False, False
for arg in reversed(pylint_args):
arg = arg.lower()
if arg == "--enable=noop":
pass
elif arg in ("--disable=all", "--enable=all"):
if all_set:
continue
all_set = True
enable = arg == "--enable=all"
elif all_set and (
(arg.startswith("--disable") and enable)
or (arg.startswith("--enable") and not enable)
):
continue
result.append(arg)

result.reverse()
return result

def to_immutable(
self, option_sets: OptionSets = {}, log_unknown_groups: bool = True
) -> "ImmutableConfig":
Expand All @@ -159,6 +182,8 @@ def to_immutable(
for arg in combined:
if arg is None:
continue
if arg.option == Option.PYLINT:
arg = ProcessedArg(Option.PYLINT, self._resolve_enable_disable_all(arg.val))
ordered_args[int(arg.option)] = arg

enablers_from_option_sets = {}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
lazy_problem().set_code("E303").set_line(22),
],
),
(
"z202817-zkouska.py",
[Arg(Option.PYLINT, "--enable=all"), Arg(Option.PYLINT, "--disable=all")],
[]
),
(
"z202817-zkouska.py",
[Arg(Option.CONFIG_FILE, "empty"), Arg(Option.PYLINT, "--enable=all")],
[lazy_problem().set_source(Linter.PYLINT) for _ in range(33)]
)
],
)
def test_lint_basic(filename: str, args: List[Arg], expected_output: List[Problem]) -> None:
Expand Down
12 changes: 2 additions & 10 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,11 @@ def remote_empty_config_url() -> str:


def prepare_config(filename: str, args: List[UnprocessedArg], from_empty: bool) -> Config:
config_args = Config("test", args)
args_config = config_args.get_last_value(Option.CONFIG_FILE, use_default=False)
config_path = (
args_config
if args_config is not None
else "empty"
if from_empty
else config_args.get_last_value(Option.CONFIG_FILE, use_default=True)
)
if from_empty:
args = [UnprocessedArg(Option.CONFIG_FILE, "empty")] + args
config = get_config_one(
filename,
[f"{arg.option.to_name()}={arg.val}" if arg.val is not None else arg.option.to_name() for arg in args]
+ [f"config-file={config_path}"]
)
assert config is not None
return config
Expand Down

0 comments on commit 1a9ed96

Please sign in to comment.