From f9f10b7bbadf531ddbb9d65e50878f534323017e Mon Sep 17 00:00:00 2001 From: Thomas Dimiduk Date: Fri, 15 Jul 2022 14:35:40 -0400 Subject: [PATCH] Remove hardcoded argument from autoflake linter Move "--remove-all-unused-imports" to a default argument rather than a hardcoded portion of the command for autoflake. This allows a user to override if the'd prefer a more conservative run of autoflake. --- src/python/pants/backend/python/lint/autoflake/rules.py | 1 - src/python/pants/backend/python/lint/autoflake/subsystem.py | 5 ++++- src/python/pants/option/option_types.py | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/python/pants/backend/python/lint/autoflake/rules.py b/src/python/pants/backend/python/lint/autoflake/rules.py index b7f08226d21..555d0bd13a0 100644 --- a/src/python/pants/backend/python/lint/autoflake/rules.py +++ b/src/python/pants/backend/python/lint/autoflake/rules.py @@ -47,7 +47,6 @@ async def autoflake_fmt(request: AutoflakeRequest, autoflake: Autoflake) -> FmtR autoflake_pex, argv=( "--in-place", - "--remove-all-unused-imports", *autoflake.args, *request.snapshot.files, ), diff --git a/src/python/pants/backend/python/lint/autoflake/subsystem.py b/src/python/pants/backend/python/lint/autoflake/subsystem.py index 88927791e92..81a065c6502 100644 --- a/src/python/pants/backend/python/lint/autoflake/subsystem.py +++ b/src/python/pants/backend/python/lint/autoflake/subsystem.py @@ -33,7 +33,10 @@ class Autoflake(PythonToolBase): default_lockfile_url = git_url(default_lockfile_path) skip = SkipOption("fmt", "lint") - args = ArgsListOption(example="--target-version=py37 --quiet") + args = ArgsListOption( + example="--remove-all-unused-imports --target-version=py37 --quiet", + default=["--remove-all-unused-imports"], + ) export = ExportToolOption() diff --git a/src/python/pants/option/option_types.py b/src/python/pants/option/option_types.py index a5e790adbd2..cd3cdac0210 100644 --- a/src/python/pants/option/option_types.py +++ b/src/python/pants/option/option_types.py @@ -789,6 +789,7 @@ def __new__( # This should be set when callers can alternatively use "--" followed by the arguments, # instead of having to provide "--[scope]-args='--arg1 --arg2'". passthrough: bool | None = None, + default: list[str] | None = None, ): if extra_help: extra_help = "\n\n" + extra_help