Skip to content

Static analysis configuration


fmtコマンドによって実行される静的解析は、Ruffによって完全に裏付けられている(デフォルトで)。

Hatchは、ユーザ設定がextendできるdefault settingsを提供します。

Extending config

設定を定義するときは、extend-selectのように、extend-で始まるオプションを使用してください。たとえば、次のようになります。:

[tool.ruff.format]
preview = true
quote-style = "single"

[tool.ruff.lint]
preview = true
extend-select = ["C901"]

[tool.ruff.lint.extend-per-file-ignores]
"docs/.hooks/*" = ["INP001", "T201"]

[tool.ruff.lint.isort]
known-first-party = ["foo", "bar"]
[format]
preview = true
quote-style = "single"

[lint]
preview = true
extend-select = ["C901"]

[lint.extend-per-file-ignores]
"docs/.hooks/*" = ["INP001", "T201"]

[lint.isort]
known-first-party = ["foo", "bar"]

Note

persisting configでない場合は、Hatchが自動的に処理するため、明示的にデフォルトをextendする必要はありません。

Persistent config

デフォルトの構成をプロジェクトに保存する場合は、次のように明示的なパスを設定します。:

[tool.hatch.envs.hatch-static-analysis]
config-path = "ruff_defaults.toml"
[envs.hatch-static-analysis]
config-path = "ruff_defaults.toml"

次に、設定をデフォルトファイルの拡張と見なすようにRuffに指示します。:

[tool.ruff]
extend = "ruff_defaults.toml"
extend = "ruff_defaults.toml"

デフォルトを更新したい場合(Hatchのアップグレード時など)は、--syncフラグを指定してfmtコマンドを1回実行する必要があります。例:

hatch fmt --check --sync

Tip

これは、IDEなどの他のツールがデフォルト設定を使用できるようにするため、推奨されるアプローチです。

No config

Hatchがデフォルトの設定を使わず、完全に自分の設定に依存するようにしたい場合は、パスを何かに設定してから、Ruffの設定で「拡張」しないようにしてください。:

[tool.hatch.envs.hatch-static-analysis]
config-path = "none"
[envs.hatch-static-analysis]
config-path = "none"

Customize behavior

fmtコマンドで使用される環境の動作を完全に変更できます。詳細な例については、how-toを参照してください。

Dependencies

環境dependenciesを明示的に定義して、Ruffの特定のバージョンを固定します。:

[tool.hatch.envs.hatch-static-analysis]
dependencies = ["ruff==X.Y.Z"]
[envs.hatch-static-analysis]
dependencies = ["ruff==X.Y.Z"]

Scripts

実行されるデフォルトのコマンドを変更する場合は、scriptsを上書きできます。次の4つのスクリプトを定義する必要があります。:

[tool.hatch.envs.hatch-static-analysis.scripts]
format-check = "..."
format-fix = "..."
lint-check = "..."
lint-fix = "..."
[envs.hatch-static-analysis.scripts]
format-check = "..."
format-fix = "..."
lint-check = "..."
lint-fix = "..."

format-*スクリプトは--formatter/-fフラグに対応し、lint-*スクリプトは--linter/-lフラグに対応します。*-fixスクリプトはデフォルトで実行され、*-checkスクリプトは--checkフラグに対応します。

Reminder

静解析に別のツールを使用する場合は、必要なdependenciesを必ず更新してください。

Installer

既定では、UV is enabledです。この動作を無効にするには、次の手順を実行します。:

[tool.hatch.envs.hatch-static-analysis]
installer = "pip"
[envs.hatch-static-analysis]
installer = "pip"

Default settings

Non-rule settings

Per-file ignored rules

Selected rules

次のルールは、Ruffのバージョン0.4.5に基づいています。Pの付いたルールは、previewモードが有効な場合にのみ選択されます。

525選択された安定ルールと129選択されたプレビュールールがあります。

Selected rules

Unselected

175個の未選択ルールがあります。

Unselected rules