Skip to content

Commit a7f1c60

Browse files
committed
New upgrade command to autofix lint rules
ghstack-source-id: ec39278a75ea8af6f783503c46b37dd5260288f9 Pull Request resolved: #349
1 parent 9ea95ca commit a7f1c60

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

docs/guide/commands.rst

+13
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ Example:
109109
OK
110110
111111
112+
``upgrade``
113+
^^^^^^^^^^^
114+
115+
Upgrade lint rules or client code to the latest version of Fixit.
116+
Automatically applies fixes from all upgrade rules in :mod:`fixit.upgrade`.
117+
118+
Shortcut for ``fixit --rules fixit.upgrade fix --automatic <path>``
119+
120+
.. code:: console
121+
122+
$ fixit upgrade [PATH ...]
123+
124+
112125
``debug``
113126
^^^^^^^^^
114127

src/fixit/cli.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from .api import fixit_paths, print_result
1717
from .config import collect_rules, generate_config, parse_rule
18-
from .ftypes import Config, Options, Tags
18+
from .ftypes import Config, Options, QualifiedRule, Tags
1919
from .rule import LintRule
2020
from .testing import generate_lint_rule_test_cases
2121
from .util import capture
@@ -218,6 +218,21 @@ def test(ctx: click.Context, rules: Sequence[str]):
218218
ctx.exit(1)
219219

220220

221+
@main.command()
222+
@click.pass_context
223+
@click.argument("paths", nargs=-1, type=click.Path(path_type=Path))
224+
def upgrade(ctx: click.Context, paths: Sequence[Path]):
225+
"""
226+
upgrade lint rules and apply deprecation fixes
227+
228+
roughly equivalent to `fixit --rules fixit.upgrade fix --automatic`
229+
"""
230+
options: Options = ctx.obj
231+
options.rules = (QualifiedRule("fixit.upgrade"),)
232+
233+
ctx.invoke(fix, paths=paths, interactive=False)
234+
235+
221236
@main.command()
222237
@click.pass_context
223238
@click.argument("paths", nargs=-1, type=click.Path(exists=True, path_type=Path))

0 commit comments

Comments
 (0)