Commit Graph

35 Commits

Author SHA1 Message Date
d53f98ea05
feat: support --version
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-15 13:59:56 +00:00
d4ab015bc6
chore: remove internal directory
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-15 13:59:55 +00:00
0fbae06f19
feat: support reading paths from stdin
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-15 10:37:56 +00:00
4dd4c55ff5
feat: add nix direnv source to .envrc
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-14 15:15:39 +00:00
6225883073
chore: update lock file
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-14 15:13:41 +00:00
cb9564c7ef
feat: add -s -w build flags to reduce binary size
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-14 15:10:20 +00:00
b109358490 feat: create config package (#25)
Move all config related code into a config package.

Signed-off-by: Brian McGee <brian@bmcgee.ie>

Reviewed-on: #25
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-15 10:46:49 +00:00
15db7f459c fix: duplicate processing in ordered formatters (#24)
Fixes a bug with formatters processing paths out of order.

Signed-off-by: Brian McGee <brian@bmcgee.ie>

Reviewed-on: #24
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-12 15:15:51 +00:00
c7d0138a02 support formatter ordering (#20)
Allows specifying the order in which formatters are applied.

Very simple for now, adding a `Before` field to the formatted config which allows the user to say that formatter `x` needs to be applied _before_ formatted `y`.

```toml
[formatter.statix]
command = "statix"
includes = ["*.nix"]
before = "deadnix"

[formatter.deadnix]
command = "statix"
includes = ["*.nix"]
```

Signed-off-by: Brian McGee <brian@bmcgee.ie>
Reviewed-on: #20
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-12 11:46:04 +00:00
80e99b6d75 feat: use go-git index instead of git ls-files (#23)
Figured out how to use `go-git` properly.

```console
# git

❯ nix run .# -- --config-file ./test/echo.toml --tree-root /home/brian/Development/com/github/nixos/nixpkgs -c
38539 files changed in 272.843495ms

# filesystem

❯ nix run .# -- --config-file ./test/echo.toml --tree-root /home/brian/Development/com/github/nixos/nixpkgs -c --walk filesystem
38567 files changed in 348.84277ms
```

Signed-off-by: Brian McGee <brian@bmcgee.ie>
Reviewed-on: #23
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-12 11:33:14 +00:00
5711caebb9 feat: support .gitignore files (#19)
Introduces a `--walk` flag which can be used to tell `treefmt` how to traverse the directory specified by `--tree-root`.

By default, it will attempt to use `git ls-files`. If this fails, it falls back to using the filesystem.

You can explicitly traverse the filesystem instead of using git by providing `--walk filesystem`.

Close #1

Reviewed-on: #19
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-11 20:52:22 +00:00
55ca4468cc fix: stalling on large file sets (#18)
When running against nixpkgs we were stalling. This was due to a long running read tx which was preventing any writes.

This breaks up reading the cache when walking the filesystem into many smaller read txs.

On my laptop I'm now getting the following with the echo sample:

```console
# fresh cache

❯ nix run .# -- -c --config-file ./test/echo.toml --tree-root ../../../github.com/nixos/nixpkgs
38825 files changed in 320.655826ms

# hot cache

❯ nix run .# -- --config-file ./test/echo.toml --tree-root ../../../github.com/nixos/nixpkgs
0 files changed in 252.920853ms%
```

Signed-off-by: Brian McGee <brian@bmcgee.ie>

Reviewed-on: #18
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-07 18:57:51 +00:00
a3ca7825a6 feat: support changing work directory (#15)
Closes #10

Signed-off-by: Brian McGee <brian@bmcgee.ie>

Reviewed-on: #15
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-03 15:21:45 +00:00
84629f7b94 feat: support fail on change (#16)
Closes #8

Signed-off-by: Brian McGee <brian@bmcgee.ie>

Reviewed-on: #16
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-03 13:10:54 +00:00
aebbcfd4f1 nit: clean batch capacity (#17)
Since we discussed this in #14 (comment)

It doesn't really matter.

Reviewed-on: #17
Co-authored-by: zimbatm <zimbatm@zimbatm.com>
Co-committed-by: zimbatm <zimbatm@zimbatm.com>
2024-01-03 10:39:55 +00:00
4a78a1e319
fix: nix build
- update `gomod2nix.toml`
- add formatters as `nativeBuildInputs` for nix build
- export a `XDG_CACHE_HOME` for checks

Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-01-03 09:20:32 +00:00
811f883a2b feat/bust-cache-validators-change (#14)
Tracks the mod time and size of a formatter's executable in bolt.

The cache is busted using the following criteria:

- a new formatter has been configured.
- an existing formatter has changed (mod time or size)
- an existing formatter has been removed from config

Also implemented better resolution of symlinks when determining a formatters executable path.

Reviewed-on: #14
Reviewed-by: Jonas Chevalier <zimbatm@noreply.git.numtide.com>
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2024-01-03 08:08:57 +00:00
ada9a72a7e
feat: simplify some test code
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-01-02 14:57:21 +00:00
96b1560327 feat: support global excludes (#13)
Stacked on top of #11

Co-authored-by: Brian McGee <brian@bmcgee.ie>
Reviewed-on: #13
Co-authored-by: zimbatm <zimbatm@zimbatm.com>
Co-committed-by: zimbatm <zimbatm@zimbatm.com>
2024-01-02 12:12:47 +00:00
d8d666a132
feat: use exec.LookPath to find formatter executable
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-01-02 10:36:51 +00:00
26c2ae1cda
feat: hex encode db name
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-01-02 10:36:48 +00:00
1019851207 chore: remove dependency on juju/errors (#11)
The package was created before Go introduced their own "errors"
package.

Trade the better juju errors semantic for a smaller dependency tree.

Reviewed-on: #11
Co-authored-by: zimbatm <zimbatm@zimbatm.com>
Co-committed-by: zimbatm <zimbatm@zimbatm.com>
2024-01-02 10:33:50 +00:00
60a1d7848e
fixup! feat: clean up and documentation
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2023-12-26 10:12:13 +00:00
7c137bfe35
feat: listen for shutdown correctly
Closes #5

Signed-off-by: Brian McGee <brian@bmcgee.ie>
2023-12-26 10:12:01 +00:00
9b84155265
feat: allow specifying formatters in cli
Closes #9
2023-12-25 12:26:18 +00:00
b6405d0714
feat: clean up and documentation 2023-12-24 11:59:05 +00:00
f322e1ffb8
fix: include correct gotools package 2023-12-24 11:19:48 +00:00
4c45d2aa7e feat: allow missing formatters (#6)
Closes #3

Reviewed-on: #6
Co-authored-by: Brian McGee <brian@bmcgee.ie>
Co-committed-by: Brian McGee <brian@bmcgee.ie>
2023-12-23 15:00:39 +00:00
298e5ac217
feat: change module root to git.numtide.com 2023-12-23 13:39:16 +00:00
25230e236f
fix: license contributors 2023-12-23 13:33:37 +00:00
18bdb7210d
feat: compare with cache before reporting a file as changed 2023-12-23 13:31:08 +00:00
12aa9a7bef
fix: glob patterns for includes and excludes
Prefix with **/
2023-12-23 13:20:11 +00:00
12452b01b6
feat: align example treefmt config with flake treefmt config
Prevent unnecessary reformatting
2023-12-23 13:06:50 +00:00
0c93d98483
feat: use a named type for Cli options 2023-12-23 12:56:17 +00:00
6904097171
feat: initial import 2023-12-23 12:50:51 +00:00