Compare commits
1 Commits
c92a65f0b5
...
f230dae37b
Author | SHA1 | Date | |
---|---|---|---|
f230dae37b |
@ -12,7 +12,6 @@ type Options struct {
|
||||
WorkingDirectory kong.ChangeDirFlag `default:"." short:"C" help:"Run as if treefmt was started in the specified working directory instead of the current working directory"`
|
||||
ClearCache bool `short:"c" help:"Reset the evaluation cache. Use in case the cache is not precise enough"`
|
||||
ConfigFile string `type:"existingfile" default:"./treefmt.toml"`
|
||||
FailOnChange bool `help:"Exit with error if any changes were made. Useful for CI"`
|
||||
Formatters []string `help:"Specify formatters to apply. Defaults to all formatters"`
|
||||
TreeRoot string `type:"existingdir" default:"."`
|
||||
Verbosity int `name:"verbose" short:"v" type:"counter" default:"0" env:"LOG_LEVEL" help:"Set the verbosity of logs e.g. -vv"`
|
||||
|
@ -18,8 +18,6 @@ import (
|
||||
|
||||
type Format struct{}
|
||||
|
||||
var ErrFailOnChange = errors.New("unexpected changes detected, --fail-on-change is enabled")
|
||||
|
||||
func (f *Format) Run() error {
|
||||
start := time.Now()
|
||||
|
||||
@ -112,7 +110,8 @@ func (f *Format) Run() error {
|
||||
// update cache as paths are completed
|
||||
eg.Go(func() error {
|
||||
batchSize := 1024
|
||||
batch := make([]string, 0, batchSize)
|
||||
batch := make([]string, batchSize)
|
||||
batch = batch[:0]
|
||||
|
||||
var pending, completed, changes int
|
||||
|
||||
@ -157,10 +156,6 @@ func (f *Format) Run() error {
|
||||
}
|
||||
changes += count
|
||||
|
||||
if Cli.FailOnChange && changes != 0 {
|
||||
return ErrFailOnChange
|
||||
}
|
||||
|
||||
fmt.Printf("%v files changed in %v", changes, time.Now().Sub(start))
|
||||
return nil
|
||||
})
|
||||
|
@ -213,27 +213,6 @@ func TestChangeWorkingDirectory(t *testing.T) {
|
||||
as.Contains(string(out), fmt.Sprintf("%d files changed", 29))
|
||||
}
|
||||
|
||||
func TestFailOnChange(t *testing.T) {
|
||||
as := require.New(t)
|
||||
|
||||
tempDir := test.TempExamples(t)
|
||||
configPath := tempDir + "/echo.toml"
|
||||
|
||||
// test without any excludes
|
||||
config := format.Config{
|
||||
Formatters: map[string]*format.Formatter{
|
||||
"echo": {
|
||||
Command: "echo",
|
||||
Includes: []string{"*"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
test.WriteConfig(t, configPath, config)
|
||||
_, err := cmd(t, "--fail-on-change", "--config-file", configPath, "--tree-root", tempDir)
|
||||
as.ErrorIs(err, ErrFailOnChange)
|
||||
}
|
||||
|
||||
func TestBustCacheOnFormatterChange(t *testing.T) {
|
||||
as := require.New(t)
|
||||
|
||||
|
Reference in New Issue
Block a user