Skip to content

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
  • flake8 .
  • isort .
  • black .
hatch fmt src tests
  • flake8 src tests
  • isort src tests
  • black src tests
hatch fmt -f
  • isort .
  • black .
hatch fmt -l
  • flake8 .
hatch fmt --check
  • flake8 .
  • black --check --diff .
  • isort --check-only --diff .
hatch fmt --check -f
  • black --check --diff .
  • isort --check-only --diff .
hatch fmt --check -l
  • flake8 .