mirror of
https://github.com/numtide/treefmt.git
synced 2024-08-16 20:30:25 +03:00
feat: add pipeline priority field
Allows for fine-grained control of execution order. Signed-off-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
parent
c71d69051a
commit
6ae0e4f8e4
@ -59,6 +59,18 @@ func TestReadConfigFile(t *testing.T) {
|
||||
as.Nil(alejandra.Options)
|
||||
as.Equal([]string{"*.nix"}, alejandra.Includes)
|
||||
as.Equal([]string{"examples/nix/sources.nix"}, alejandra.Excludes)
|
||||
as.Equal("nix", alejandra.Pipeline)
|
||||
as.Equal(1, alejandra.Priority)
|
||||
|
||||
// deadnix
|
||||
deadnix, ok := cfg.Formatters["deadnix"]
|
||||
as.True(ok, "deadnix formatter not found")
|
||||
as.Equal("deadnix", deadnix.Command)
|
||||
as.Nil(deadnix.Options)
|
||||
as.Equal([]string{"*.nix"}, deadnix.Includes)
|
||||
as.Nil(deadnix.Excludes)
|
||||
as.Equal("nix", deadnix.Pipeline)
|
||||
as.Equal(2, deadnix.Priority)
|
||||
|
||||
// ruby
|
||||
ruby, ok := cfg.Formatters["ruby"]
|
||||
|
@ -9,6 +9,8 @@ type Formatter struct {
|
||||
Includes []string
|
||||
// Excludes is an optional list of glob patterns used to exclude certain files from this Formatter.
|
||||
Excludes []string
|
||||
//
|
||||
// Indicates this formatter should be executed as part of a group of formatters all sharing the same pipeline key.
|
||||
Pipeline string
|
||||
// Indicates the order of precedence when executing as part of a pipeline.
|
||||
Priority int
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package format
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
)
|
||||
|
||||
type Pipeline struct {
|
||||
sequence []*Formatter
|
||||
@ -8,6 +11,10 @@ type Pipeline struct {
|
||||
|
||||
func (p *Pipeline) Add(f *Formatter) {
|
||||
p.sequence = append(p.sequence, f)
|
||||
// sort by priority in ascending order
|
||||
slices.SortFunc(p.sequence, func(a, b *Formatter) int {
|
||||
return a.config.Priority - b.config.Priority
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Pipeline) Wants(path string) bool {
|
||||
|
@ -32,11 +32,13 @@ includes = ["*.nix"]
|
||||
# Act as an example on how to exclude specific files
|
||||
excludes = ["examples/nix/sources.nix"]
|
||||
pipeline = "nix"
|
||||
priority = 1
|
||||
|
||||
[formatter.deadnix]
|
||||
command = "deadnix"
|
||||
includes = ["*.nix"]
|
||||
pipeline = "nix"
|
||||
priority = 2
|
||||
|
||||
[formatter.ruby]
|
||||
command = "rufo"
|
||||
|
Loading…
Reference in New Issue
Block a user