forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

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
···
-
flake.lock
-
-
# for now, we don't want these formatted, but let's consider it in the future?
-
*.json
-
*.md
-
*.yml
-
*.yaml
-
*.jsonc
-
*.json
-
-
# causes Go template plugin errors: https://github.com/NiklasPor/prettier-plugin-go-template/issues/120
-
appview/pages/templates/layouts/repobase.html
-
appview/pages/templates/repo/tags.html
+6
docs/contributing.md
···
- Avoid noisy commit messages like "wip" or "final fix"—rewrite history
before submitting if necessary.
+
## code formatting
+
+
We use a variety of tools to format our code, and multiplex them with
+
[`treefmt`](https://treefmt.com): all you need to do to format your changes
+
is run `nix run .#fmt` (or just `treefmt` if you're in the devshell).
+
## proposals for bigger changes
Small fixes like typos, minor bugs, or trivial refactors can be
+31 -6
flake.nix
···
pkgsCross-gnu64-pkgsStatic-knot-unwrapped = crossPackages.knot-unwrapped;
pkgsCross-gnu64-pkgsStatic-spindle = crossPackages.spindle;
-
prettier-wrapper = pkgs.runCommandLocal "prettier-wrapper" {nativeBuildInputs = [pkgs.makeWrapper];} ''
-
mkdir -p "$out/bin"
-
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"
-
'';
+
treefmt-wrapper = pkgs.treefmt.withConfig {
+
settings.formatter = {
+
alejandra = {
+
command = pkgs.lib.getExe pkgs.alejandra;
+
includes = ["*.nix"];
+
};
+
+
gofmt = {
+
command = pkgs.lib.getExe' pkgs.go "gofmt";
+
options = ["-w"];
+
includes = ["*.go"];
+
};
+
+
prettier = let
+
wrapper = pkgs.runCommandLocal "prettier-wrapper" {nativeBuildInputs = [pkgs.makeWrapper];} ''
+
makeWrapper ${pkgs.prettier}/bin/prettier "$out" --add-flags "--plugin=${pkgs.prettier-plugin-go-template}/lib/node_modules/prettier-plugin-go-template/lib/index.js"
+
'';
+
in {
+
command = wrapper;
+
options = ["-w"];
+
includes = ["*.html"];
+
# causes Go template plugin errors: https://github.com/NiklasPor/prettier-plugin-go-template/issues/120
+
excludes = ["appview/pages/templates/layouts/repobase.html" "appview/pages/templates/repo/tags.html"];
+
};
+
};
+
};
});
defaultPackage = forAllSystems (system: self.packages.${system}.appview);
-
formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra);
devShells = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
packages' = self.packages.${system};
···
pkgs.redis
pkgs.coreutils # for those of us who are on systems that use busybox (alpine)
packages'.lexgen
-
packages'.prettier-wrapper
+
packages'.treefmt-wrapper
];
shellHook = ''
mkdir -p appview/pages/static
···
${pkgs.tailwindcss}/bin/tailwindcss -w -i input.css -o ./appview/pages/static/tw.css
'';
in {
+
fmt = {
+
type = "app";
+
program = pkgs.lib.getExe packages'.treefmt-wrapper;
+
};
watch-appview = {
type = "app";
program = toString (pkgs.writeShellScript "watch-appview" ''