Skip to content

Customize static analysis behavior


fmtコマンドによって実行される静的解析をfully alterするには、hatch-static-analysisという名前の予約されたenvironmentを変更します。たとえば、デフォルトの動作をBlack,isortとbasicflake8の組み合わせに置き換える場合は、次のように定義できます。:

[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"

format-*スクリプトは--formatter/-fフラグに対応し、lint-*スクリプトは--linter/-lフラグに対応します。*-fixスクリプトはデフォルトで実行され、*-checkスクリプトは--checkフラグに対応します。この例に基づいて、さまざまなスクリプトが動作にどのように影響するかを次に示します。:

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 .