Add TOML formatter (prettier)

This commit is contained in:
adisbladis 2022-04-26 21:34:51 +12:00
parent fec10f2cfc
commit 2a26070ea4
4 changed files with 33 additions and 12 deletions

3
.prettierrc.js Normal file
View file

@ -0,0 +1,3 @@
module.exports = {
"plugins": ["prettier-plugin-toml"],
};

View file

@ -25,12 +25,18 @@
in in
{ {
treefmt = stdenv.mkDerivation { treefmt =
let
devShell = devShells.default;
in
stdenv.mkDerivation {
name = "treefmt-check"; name = "treefmt-check";
src = self; src = self;
nativeBuildInputs = devShells.default.nativeBuildInputs; nativeBuildInputs = devShell.nativeBuildInputs;
dontConfigure = true; dontConfigure = true;
inherit (devShell) NODE_PATH;
buildPhase = '' buildPhase = ''
env HOME=$(mktemp -d) treefmt --fail-on-change env HOME=$(mktemp -d) treefmt --fail-on-change
''; '';

View file

@ -29,6 +29,7 @@ in
pkgs.treefmt pkgs.treefmt
pkgs.llvmPackages.clang # clang-format pkgs.llvmPackages.clang # clang-format
pkgs.nixpkgs-fmt pkgs.nixpkgs-fmt
pkgs.nodePackages.prettier
(pkgs.python3.withPackages (ps: [ (pkgs.python3.withPackages (ps: [
ps.pytest ps.pytest
@ -36,6 +37,8 @@ in
]; ];
NODE_PATH = "${pkgs.nodePackages.prettier-plugin-toml}/lib/node_modules";
shellHook = lib.optionalString stdenv.isLinux '' 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}" export NIX_DEBUG_INFO_DIRS="${pkgs.curl.debug}/lib/debug:${nix.debug}/lib/debug''${NIX_DEBUG_INFO_DIRS:+:$NIX_DEBUG_INFO_DIRS}"
''; '';

View file

@ -1,8 +1,17 @@
[formatter."c++"] [formatter."c++"]
command = "clang-format" command = "clang-format"
options = [ "-i", "-style", "{BasedOnStyle: llvm, IndentWidth: 4, SortIncludes: false}" ] options = [
"-i",
"-style",
"{BasedOnStyle: llvm, IndentWidth: 4, SortIncludes: false}"
]
includes = ["*.c", "*.cpp", "*.cc", "*.h", "*.hpp"] includes = ["*.c", "*.cpp", "*.cc", "*.h", "*.hpp"]
[formatter.nix] [formatter.nix]
command = "nixpkgs-fmt" command = "nixpkgs-fmt"
includes = ["*.nix"] includes = ["*.nix"]
[formatter.toml]
command = "prettier"
options = ["--write"]
includes = ["*.toml"]