Customize static analysis behavior¶
You can fully alter the static analysis performed by the check code and check fmt commands by modifying the reserved environments named hatch-check-code and hatch-check-fmt.
For example, you could define the following if you wanted to replace the default linting behavior with flake8 and the default formatting with a mix of Black and isort:
[tool.hatch.envs.hatch-check-code]
dependencies = ["flake8"]
[tool.hatch.envs.hatch-check-code.scripts]
lint-check = "flake8 {args:.}"
lint-fix = "lint-check"
[tool.hatch.envs.hatch-check-fmt]
dependencies = ["black", "isort"]
[tool.hatch.envs.hatch-check-fmt.scripts]
format-check = [
"black --check --diff {args:.}",
"isort --check-only --diff {args:.}",
]
format-fix = [
"isort {args:.}",
"black {args:.}",
]
[envs.hatch-check-code]
dependencies = ["flake8"]
[envs.hatch-check-code.scripts]
lint-check = "flake8 {args:.}"
lint-fix = "lint-check"
[envs.hatch-check-fmt]
dependencies = ["black", "isort"]
[envs.hatch-check-fmt.scripts]
format-check = [
"black --check --diff {args:.}",
"isort --check-only --diff {args:.}",
]
format-fix = [
"isort {args:.}",
"black {args:.}",
]
The lint-* scripts are used by hatch check code while the format-* scripts are used by hatch check fmt. The *-fix scripts run when --fix is passed, while the *-check scripts run by default. Based on this example, the following shows how the various scripts influence behavior:
| Command | Expanded scripts |
|---|---|
hatch check code |
|
hatch check code --fix |
|
hatch check code src tests |
|
hatch check fmt |
|
hatch check fmt --fix |
|
hatch check fmt --fix src tests |
|
Note
If you choose to use different tools for static analysis, be sure to update the required dependencies.