https://pantsbuild.org/ logo
h

high-energy-55500

07/20/2022, 3:05 PM
open question about what to do when multiple linters sometimes need to make sequential changes. e.g. we have
Copy code
def foo(arg: Union[str, list]):
formatting the file with our linters will allow all of them to pass except
pyupgrade
, which changes the line to
Copy code
def foo(arg: str | list):
unfortunately, we still need to run our formatters once more, since now we’ve got an unused
Copy code
from typing import Union
at the top of the file, which
autoflake
complains about. is there a better flow here that doesn’t require running our formatters twice or more times in a row? can we optimize this somehow so that some linters always run before other linters, so that in most cases they’d fix both issues in a single pass?
b

bitter-ability-32190

07/20/2022, 3:11 PM
IIRC the order they are listed in
pants.toml
is the order they run in
fmt
1
h

high-energy-55500

07/20/2022, 3:13 PM
do you know if anyone has looked into the optimal order to run formatters to reduce the likelihood of needing to do a rerun?
b

bitter-ability-32190

07/20/2022, 3:24 PM
FWIW We're looking into making a dedicated
fix
goal for non-style changes. In this case you'd run
fix
before
fmt
👍 1
h

high-energy-55500

07/20/2022, 5:37 PM
nice, so i think tools which would go under
fix
should be run first, followed by
fmt
. i’m thinking a good order would be
Copy code
pyupgrade
autoflake
docformatter
isort
black
2
h

happy-kitchen-89482

07/21/2022, 11:42 PM
There is probably a single fixed order that will work in practice, but in theory, we'd need to run tools repeatedly until the result converges, as nothing guarantees that a single fixed order exists
4 Views