diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..dc1e020 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,3 @@ +module.exports = { + "plugins": ["prettier-plugin-toml"], +}; diff --git a/flake.nix b/flake.nix index 1f8605e..1156772 100644 --- a/flake.nix +++ b/flake.nix @@ -25,18 +25,24 @@ in { - treefmt = stdenv.mkDerivation { - name = "treefmt-check"; - src = self; - nativeBuildInputs = devShells.default.nativeBuildInputs; - dontConfigure = true; + treefmt = + let + devShell = devShells.default; + in + stdenv.mkDerivation { + name = "treefmt-check"; + src = self; + nativeBuildInputs = devShell.nativeBuildInputs; + dontConfigure = true; - buildPhase = '' - env HOME=$(mktemp -d) treefmt --fail-on-change - ''; + inherit (devShell) NODE_PATH; - installPhase = "touch $out"; - }; + buildPhase = '' + env HOME=$(mktemp -d) treefmt --fail-on-change + ''; + + installPhase = "touch $out"; + }; build = mkVariant pkgs.nix; build-unstable = mkVariant pkgs.nixUnstable; diff --git a/shell.nix b/shell.nix index d920a6f..5c0cd0d 100644 --- a/shell.nix +++ b/shell.nix @@ -29,6 +29,7 @@ in pkgs.treefmt pkgs.llvmPackages.clang # clang-format pkgs.nixpkgs-fmt + pkgs.nodePackages.prettier (pkgs.python3.withPackages (ps: [ ps.pytest @@ -36,6 +37,8 @@ in ]; + NODE_PATH = "${pkgs.nodePackages.prettier-plugin-toml}/lib/node_modules"; + shellHook = lib.optionalString stdenv.isLinux '' export NIX_DEBUG_INFO_DIRS="${pkgs.curl.debug}/lib/debug:${nix.debug}/lib/debug''${NIX_DEBUG_INFO_DIRS:+:$NIX_DEBUG_INFO_DIRS}" ''; diff --git a/treefmt.toml b/treefmt.toml index aacc3bb..d1280df 100644 --- a/treefmt.toml +++ b/treefmt.toml @@ -1,8 +1,17 @@ [formatter."c++"] command = "clang-format" -options = [ "-i", "-style", "{BasedOnStyle: llvm, IndentWidth: 4, SortIncludes: false}" ] -includes = [ "*.c", "*.cpp", "*.cc", "*.h", "*.hpp" ] +options = [ + "-i", + "-style", + "{BasedOnStyle: llvm, IndentWidth: 4, SortIncludes: false}" +] +includes = ["*.c", "*.cpp", "*.cc", "*.h", "*.hpp"] [formatter.nix] command = "nixpkgs-fmt" includes = ["*.nix"] + +[formatter.toml] +command = "prettier" +options = ["--write"] +includes = ["*.toml"]