forked from tangled.org/core
Monorepo for Tangled

add treefmt config and docs

Since Zed can't easily use our wrapped Prettier (see previous commit),
and we're now using three formatters, let's just add one command to
format all of our code correctly.

Signed-off-by: Winter <winter@winter.cafe>

Changed files
+37 -19
docs
-13
.prettierignore
··· 1 - flake.lock 2 - 3 - # for now, we don't want these formatted, but let's consider it in the future? 4 - *.json 5 - *.md 6 - *.yml 7 - *.yaml 8 - *.jsonc 9 - *.json 10 - 11 - # causes Go template plugin errors: https://github.com/NiklasPor/prettier-plugin-go-template/issues/120 12 - appview/pages/templates/layouts/repobase.html 13 - appview/pages/templates/repo/tags.html
+6
docs/contributing.md
··· 55 55 - Avoid noisy commit messages like "wip" or "final fix"—rewrite history 56 56 before submitting if necessary. 57 57 58 + ## code formatting 59 + 60 + We use a variety of tools to format our code, and multiplex them with 61 + [`treefmt`](https://treefmt.com): all you need to do to format your changes 62 + is run `nix run .#fmt` (or just `treefmt` if you're in the devshell). 63 + 58 64 ## proposals for bigger changes 59 65 60 66 Small fixes like typos, minor bugs, or trivial refactors can be
+31 -6
flake.nix
··· 107 107 pkgsCross-gnu64-pkgsStatic-knot-unwrapped = crossPackages.knot-unwrapped; 108 108 pkgsCross-gnu64-pkgsStatic-spindle = crossPackages.spindle; 109 109 110 - prettier-wrapper = pkgs.runCommandLocal "prettier-wrapper" {nativeBuildInputs = [pkgs.makeWrapper];} '' 111 - mkdir -p "$out/bin" 112 - makeWrapper ${pkgs.prettier}/bin/prettier "$out/bin/prettier" --add-flags "--plugin=${pkgs.prettier-plugin-go-template}/lib/node_modules/prettier-plugin-go-template/lib/index.js" 113 - ''; 110 + treefmt-wrapper = pkgs.treefmt.withConfig { 111 + settings.formatter = { 112 + alejandra = { 113 + command = pkgs.lib.getExe pkgs.alejandra; 114 + includes = ["*.nix"]; 115 + }; 116 + 117 + gofmt = { 118 + command = pkgs.lib.getExe' pkgs.go "gofmt"; 119 + options = ["-w"]; 120 + includes = ["*.go"]; 121 + }; 122 + 123 + prettier = let 124 + wrapper = pkgs.runCommandLocal "prettier-wrapper" {nativeBuildInputs = [pkgs.makeWrapper];} '' 125 + makeWrapper ${pkgs.prettier}/bin/prettier "$out" --add-flags "--plugin=${pkgs.prettier-plugin-go-template}/lib/node_modules/prettier-plugin-go-template/lib/index.js" 126 + ''; 127 + in { 128 + command = wrapper; 129 + options = ["-w"]; 130 + includes = ["*.html"]; 131 + # causes Go template plugin errors: https://github.com/NiklasPor/prettier-plugin-go-template/issues/120 132 + excludes = ["appview/pages/templates/layouts/repobase.html" "appview/pages/templates/repo/tags.html"]; 133 + }; 134 + }; 135 + }; 114 136 }); 115 137 defaultPackage = forAllSystems (system: self.packages.${system}.appview); 116 - formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra); 117 138 devShells = forAllSystems (system: let 118 139 pkgs = nixpkgsFor.${system}; 119 140 packages' = self.packages.${system}; ··· 134 155 pkgs.redis 135 156 pkgs.coreutils # for those of us who are on systems that use busybox (alpine) 136 157 packages'.lexgen 137 - packages'.prettier-wrapper 158 + packages'.treefmt-wrapper 138 159 ]; 139 160 shellHook = '' 140 161 mkdir -p appview/pages/static ··· 164 185 ${pkgs.tailwindcss}/bin/tailwindcss -w -i input.css -o ./appview/pages/static/tw.css 165 186 ''; 166 187 in { 188 + fmt = { 189 + type = "app"; 190 + program = pkgs.lib.getExe packages'.treefmt-wrapper; 191 + }; 167 192 watch-appview = { 168 193 type = "app"; 169 194 program = toString (pkgs.writeShellScript "watch-appview" ''