From d01848437635184b685088db7e86d7df7eb1584a Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 18 Dec 2021 16:01:10 +0300 Subject: feat(tools/depotfmt): add a treefmt wrapper with depot configuration Right now the only included formatter is gofmt, but we will extend this over time. The version of treefmt is bumped to 0.3.0 (which supports custom config files) until this lands in nixpkgs. Change-Id: I1e1aafd05ec7427c616f90c90490c528ecb2615c Reviewed-on: https://cl.tvl.fyi/c/depot/+/4399 Tested-by: BuildkiteCI Reviewed-by: grfn --- tools/depotfmt.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tools/depotfmt.nix (limited to 'tools/depotfmt.nix') diff --git a/tools/depotfmt.nix b/tools/depotfmt.nix new file mode 100644 index 000000000000..097bc29b4595 --- /dev/null +++ b/tools/depotfmt.nix @@ -0,0 +1,16 @@ +# Builds treefmt for depot, with a hardcoded configuration that +# includes the right paths to formatters. +{ pkgs, ... }: + +let + config = pkgs.writeText "depot-treefmt-config" '' + [formatter.go] + command = "${pkgs.go}/bin/gofmt" + options = [ "-w" ] + includes = ["*.go"] + ''; +in pkgs.writeShellScriptBin "depotfmt" '' + exec ${pkgs.treefmt}/bin/treefmt ''${@} \ + --config-file ${config} \ + --tree-root $(${pkgs.git}/bin/git rev-parse --show-toplevel) +'' -- cgit 1.4.1