forked from tangled.org/core
this repo has no description

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 - Avoid noisy commit messages like "wip" or "final fix"—rewrite history 56 before submitting if necessary. 57 58 ## proposals for bigger changes 59 60 Small fixes like typos, minor bugs, or trivial refactors can be
··· 55 - Avoid noisy commit messages like "wip" or "final fix"—rewrite history 56 before submitting if necessary. 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 + 64 ## proposals for bigger changes 65 66 Small fixes like typos, minor bugs, or trivial refactors can be
+31 -6
flake.nix
··· 107 pkgsCross-gnu64-pkgsStatic-knot-unwrapped = crossPackages.knot-unwrapped; 108 pkgsCross-gnu64-pkgsStatic-spindle = crossPackages.spindle; 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 - ''; 114 }); 115 defaultPackage = forAllSystems (system: self.packages.${system}.appview); 116 - formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra); 117 devShells = forAllSystems (system: let 118 pkgs = nixpkgsFor.${system}; 119 packages' = self.packages.${system}; ··· 134 pkgs.redis 135 pkgs.coreutils # for those of us who are on systems that use busybox (alpine) 136 packages'.lexgen 137 - packages'.prettier-wrapper 138 ]; 139 shellHook = '' 140 mkdir -p appview/pages/static ··· 164 ${pkgs.tailwindcss}/bin/tailwindcss -w -i input.css -o ./appview/pages/static/tw.css 165 ''; 166 in { 167 watch-appview = { 168 type = "app"; 169 program = toString (pkgs.writeShellScript "watch-appview" ''
··· 107 pkgsCross-gnu64-pkgsStatic-knot-unwrapped = crossPackages.knot-unwrapped; 108 pkgsCross-gnu64-pkgsStatic-spindle = crossPackages.spindle; 109 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 + }; 136 }); 137 defaultPackage = forAllSystems (system: self.packages.${system}.appview); 138 devShells = forAllSystems (system: let 139 pkgs = nixpkgsFor.${system}; 140 packages' = self.packages.${system}; ··· 155 pkgs.redis 156 pkgs.coreutils # for those of us who are on systems that use busybox (alpine) 157 packages'.lexgen 158 + packages'.treefmt-wrapper 159 ]; 160 shellHook = '' 161 mkdir -p appview/pages/static ··· 185 ${pkgs.tailwindcss}/bin/tailwindcss -w -i input.css -o ./appview/pages/static/tw.css 186 ''; 187 in { 188 + fmt = { 189 + type = "app"; 190 + program = pkgs.lib.getExe packages'.treefmt-wrapper; 191 + }; 192 watch-appview = { 193 type = "app"; 194 program = toString (pkgs.writeShellScript "watch-appview" ''