Skip to content

Commit

Permalink
Allow using --import option with Autoflake (Cherry-pick of #16192) (#…
Browse files Browse the repository at this point in the history
…16275)

The linter is currently hardcoded to do "--remove-all-unused-imports", which
unfortunately does not work for all repos since imports can have side effects.
With this removed a user can still provide the argument if they desire it, but
it is possible to run without it.

[ci skip-build-wheels]
[ci skip-rust]

Co-authored-by: Tom Dimiduk <tom@dimiduk.net>
  • Loading branch information
Eric-Arellano and tdimiduk authored Jul 22, 2022
1 parent a69b8f0 commit ebf92eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/python/pants/backend/python/lint/autoflake/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
8 changes: 7 additions & 1 deletion src/python/pants/backend/python/lint/autoflake/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ 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",
# This argument was previously hardcoded. Moved it a default argument
# to allow it to be overridden while maintaining the existing api.
# See: https://github.com/pantsbuild/pants/issues/16193
default=["--remove-all-unused-imports"],
)
export = ExportToolOption()


Expand Down
4 changes: 3 additions & 1 deletion src/python/pants/option/option_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def __new__(
cls,
flag_name: str,
*,
default: _MaybeDynamicT[list[_ListMemberT]] = [],
default: _MaybeDynamicT[list[_ListMemberT]] | None = [],
help: _HelpT,
# Additional bells/whistles
register_if: _RegisterIfFuncT | None = None,
Expand Down Expand Up @@ -784,6 +784,7 @@ def __new__(
# instead of having to provide "--[scope]-args='--arg1 --arg2'".
passthrough: bool | None = None,
flag_name: str = "--args",
default: _MaybeDynamicT[list[_ListMemberT]] | None = None,
):
if extra_help:
extra_help = "\n\n" + extra_help
Expand All @@ -798,6 +799,7 @@ def __new__(
"""
)
),
default=default, # type: ignore[arg-type]
)
if passthrough is not None:
instance._extra_kwargs["passthrough"] = passthrough
Expand Down

0 comments on commit ebf92eb

Please sign in to comment.