No slash command · from nix-tasuke
treefmt-nix and nix fmt guide. Unified formatting and linting with treefmt. Use when configuring or running nix fmt, treefmt, or adding formatters/linters to a Nix project.
Ships in nix-tasuke. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
treefmtはプロジェクト内の複数言語ファイルを一コマンドで並列フォーマットするツールです。 treefmt-nixはNixモジュールシステムでtreefmtを設定・管理するラッパーです。
nix fmtコマンドはflakeのformatter出力を呼び出します。
treefmt-nixを組み込むとnix fmtの実体がtreefmtになり、
設定されたすべてのプログラムが実行されます。
FlakeはGitで追跡されているファイルのみを対象とするため、
新規ファイルがある場合は事前にgit ls-files --others --exclude-standard -z | git add --intent-to-add --pathspec-from-file=- --pathspec-file-nulを実行してください。
未追跡ファイルがなく空の入力でもエラーにはなりません。
nix fmtやtreefmtという名前から「フォーマッタだけ」と誤解されがちですが、
treefmt-nixのprogramsにはリンターやチェッカーが多数含まれています。
フォーマッタの例:
nixfmtprettierrustfmtshfmtリンターの例:
actionlintdeadnixhlintshellcheckstatixその他:
typos(スペルチェック)zizmor(GitHub Actionsセキュリティ)treefmtのフォーマッタ仕様は「ファイルパスのリストを受け取り、変更があればファイルに書き戻す」というものです。 リンターはファイルを変更しませんが、エラー時に非ゼロ終了するためtreefmtがエラーとして検出します。
flake-partsを使う場合の例です。
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{
flake-parts,
treefmt-nix,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
treefmt-nix.flakeModule
];
systems = [
"aarch64-linux"
"x86_64-linux"
];
perSystem = { pkgs, ... }: {
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
prettier.enable = true;
shellcheck.enable = true;
shfmt.enable = true;
};
};
};
};
}
nix fmtで全プログラムが実行されます。
treefmtの設定モジュールを使ってカスタム引数を渡すこともできます。
しかしなるべくflake.nixに書くのではなく、 そのツール自体が標準的に使う設定ファイルなどに設定を書き込んでください。
そうするとそのツールをnix fmt経由以外で使うときも同じ設定が適用されるため一貫性が保たれます。
引数しか設定方法がないツールの場合などは仕方がないのでflake.nixに書いても構いません。
| プログラム | 種類 | 説明 |
|---|---|---|
deadnix | リンター | 未使用コードの検出 |
nixfmt | フォーマッタ | 公式のNixフォーマッタ |
statix | リンター | アンチパターンの検出と自動修正 |
| プログラム | 種類 | 説明 |
|---|---|---|
shellcheck | リンター | シェルスクリプトの静的解析 |
shfmt | フォーマッタ | シェルスクリプトのフォーマット |
| プログラム | 種類 | 説明 |
|---|---|---|
prettier | フォーマッタ | JS/TS/CSS/HTML/JSON/Markdown/YAML等 |
| プログラム | 種類 | 説明 |
|---|---|---|
cabal-gild | フォーマッタ | Cabalファイルの整理 |
fourmolu | フォーマッタ | Haskellフォーマッタ |
hlint | リンター | Haskellのリファクタリング提案 |
| プログラム | 種類 | 説明 |
|---|---|---|
actionlint | リンター | GitHub Actions YAMLの検証 |
clang-format | フォーマッタ | C/C++のフォーマット |
gofmt | フォーマッタ | Goのフォーマット |
ruff-check | リンター | Pythonのリント |
ruff-format | フォーマッタ | Pythonのフォーマット |
rustfmt | フォーマッタ | Rustのフォーマット |
taplo | フォーマッタ | TOMLのフォーマット |
typos | チェッカー | ソースコード中のスペルチェック |
yamlfmt | フォーマッタ | YAMLのフォーマット |
zizmor | リンター | GitHub Actionsのセキュリティチェック |
上記は一部で、100以上のプログラムが定義されています。 全リストはtreefmt-nixのprogramsディレクトリを参照してください。
programsに定義されていないツールはsettings.formatterに直接定義できます。
treefmt.config = {
settings.formatter = {
editorconfig-checker = {
command = pkgs.editorconfig-checker;
includes = [ "*" ];
};
};
};
settings.formatter.<name>のフィールド:
| フィールド | 型 | 説明 |
|---|---|---|
command | string/path/derivation | 実行コマンド(必須) |
options | list of string | コマンド引数 |
includes | list of string | 対象ファイルのglobパターン(必須) |
excludes | list of string | 除外ファイルのglobパターン |
priority | int | 実行順序(値が小さいほど先、デフォルト0) |
globパターンはgobwas/globライブラリで処理され、
ツリールートからの相対パスに対してマッチします。
*はパス区切り/を含む任意の文字列にマッチするため、*.rsだけでリポジトリ全体の.rsファイルに再帰的にマッチします。
src/*.rsのようなディレクトリを含むパターンも機能し、src/以下の全.rsファイルに再帰的にマッチします。
**も使えますが*と実質同じ動作です。
settings.global.excludesを使うと全フォーマッタ共通でファイルを除外できます。
global excludesは各フォーマッタのincludes/excludesより先に処理されます。
treefmtのフォーマッタ仕様を満たす必要があります。
CLIが<command> [options] [...<files>]の形式で、変更があればファイルに書き戻し、エラー時は非ゼロ終了です。
仕様を満たさないツールはシェルスクリプトでラップしてください。
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
6 skills in this plugin
/naming-conventionNix naming conventions for files, variables, packages, and NixOS options based on nixpkgs official coding standards. Use when writing or reviewing Nix code./nix-commandNix CLI command guidelines. Use new unified CLI (nix subcommand) instead of legacy commands (nix-build, nix-env, nix-shell, etc.). Use when running or suggesting Nix commands./nix-fast-buildnix-fast-build command reference. Parallel Nix evaluation and build tool using nix-eval-jobs. Use when running or configuring nix-fast-build.npx claudepluginhub ncaq/konoka --plugin nix-tasuke