Customize static analysis behavior¶静的解析の挙動をカスタマイズ¶
You can fully alter the static analysis performed by the fmt command by modifying 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:予約された環境であるhatch-static-analysisを変更することで、fmtコマンドによって実行される静的解析を完全に変更できます。たとえば、デフォルトの挙動をBlack、isort、および基本的な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:format-*スクリプトは--formatter/-fフラグに対応し、lint-*スクリプトは--linter/-lフラグに対応します。*-fixスクリプトはデフォルトで実行され、*-checkスクリプトは--checkフラグに対応します。この例に基づいて、さまざまなスクリプトが挙動にどのように影響するかを示します:
| Commandコマンド | Expanded scripts拡張スクリプト |
|---|---|
hatch fmthatch fmt |
|
hatch fmt src testshatch fmt src tests |
|
hatch fmt -fhatch fmt -f |
|
hatch fmt -lhatch fmt -l |
|
hatch fmt --checkhatch fmt --check |
|
hatch fmt --check -fhatch fmt --check -f |
|
hatch fmt --check -lhatch fmt --check -l |
|