Commit Graph

17 Commits

Author SHA1 Message Date
Brian McGee
9934a5764d
fix: --stdin flag
This was incorrectly ported from Rust to Go.

When provided, `treefmt` will take the contents of stdin and place them into the file provided with the `--stdin` flag, then format it according to the configured formatters.

If the file doesn't exist it is created. If it exists, it is first truncated and then populated with stdin.

Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-06-03 17:07:34 +01:00
Brian McGee
1b517c6502
feat: add --on-unmatched
By default, if a path does not match any formatter a log message at WARN level will be emitted. A user can change this by providing the `--on-unmatched` or `-u` flag and specifying a log level `debug,info,warn,error,fatal`.

If fatal, the process will exit with an error on the first unmatched path encountered.

Closes #302

Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-29 10:32:02 +01:00
Brian McGee
6cf9524aa7
fix: cleanup cwd change in deterministic pipeline test 2024-05-29 10:32:02 +01:00
Brian McGee
6c7fd57b5c
fix: remove config2 alias in format_test.go
It's unnecessary.
2024-05-29 10:32:02 +01:00
Brian McGee
ce14ee828f
feat: simplify pipeline model
For each path we determine the list of formatters that are interested in formatting it. From there, we sort
the list of formatters first by priority (lower value, higher priority) and then by name (lexicographically).

With this information we create a batch key which is based on the unique sequence of formatters. When enough paths with the same sequence is ready we apply them in order to each formatter.

By default, with no special configuration, this model guarantees that a given path will only be processed by one formatter at a time.

If a user wishes to influence the order in which formatters are applied they can use the priority field.

Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-26 16:52:04 +01:00
Brian McGee
06e41453ec
feat: error out when a path matches multiple formatters
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-17 11:55:31 +01:00
Brian McGee
4d07521d97
fix: -f short flag for specifying formatters
Preserves backwards compatibility with v1

Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-14 20:29:42 +01:00
Brian McGee
92321c8737
feat: improve specifying formatters test
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-10 11:43:28 +01:00
Brian McGee
8b92dca9c6
feat: streaming processing of paths from stdin and paths argument
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-07 17:20:04 +01:00
Brian McGee
f1f56d1bfc
fix: remove setting of cpu profile rate
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-07 17:19:02 +01:00
Brian McGee
a79ae9583c
feat: add cpu profile flag 2024-05-06 16:05:10 +01:00
Brian McGee
5a5c1ea03e
fix: record cache entries for files that don't match formatters
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-02 08:58:02 +01:00
Brian McGee
04330a39fa
feat: add stats output similar to treefmt.rs
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-05-01 11:23:55 +01:00
Brian McGee
40b76b74a0
feat: ensure deterministic application of formatters
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-04-26 10:33:29 +01:00
Brian McGee
fcce518d5e
feat: various perf improvements
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-04-25 12:16:04 +01:00
Brian McGee
8af5b3c076
feat: introduce concept of pipelines for better concurrency
Replaces the `Before` config option with an optional `Pipeline` key.

This is used to group formatters together in the order in which they are specified within the config file.

Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-04-24 16:33:22 +01:00
Brian McGee
d4ab015bc6
chore: remove internal directory
Signed-off-by: Brian McGee <brian@bmcgee.ie>
2024-02-15 13:59:55 +00:00