Customize static analysis behavior¶
You can fully alter the static analysis performed by the fmt
command by modifing the reserved environment named hatch-static-analysis
. For example, you could define the following if you wanted to replace the default behavior with a mix of Black, isort and basic flake8:
[tool.hatch.envs.hatch-static-analysis]
dependencies = ["black", "flake8", "isort"]
[tool.hatch.envs.hatch-static-analysis.scripts]
format-check = [
"black --check --diff {args:.}",
"isort --check-only --diff {args:.}",
]
format-fix = [
"isort {args:.}",
"black {args:.}",
]
lint-check = "flake8 {args:.}"
lint-fix = "lint-check"
[envs.hatch-static-analysis]
dependencies = ["black", "flake8", "isort"]
[envs.hatch-static-analysis.scripts]
format-check = [
"black --check --diff {args:.}",
"isort --check-only --diff {args:.}",
]
format-fix = [
"isort {args:.}",
"black {args:.}",
]
lint-check = "flake8 {args:.}"
lint-fix = "lint-check"
The format-*
scripts correspond to the --formatter
/-f
flag while the lint-*
scripts correspond to the --linter
/-l
flag. The *-fix
scripts run by default while the *-check
scripts correspond to the --check
flag. Based on this example, the following shows how the various scripts influence behavior:
Command | Expanded scripts |
---|---|
hatch fmt |
|
hatch fmt src tests |
|
hatch fmt -f |
|
hatch fmt -l |
|
hatch fmt --check |
|
hatch fmt --check -f |
|
hatch fmt --check -l |
|