chore: do a golangci-lint pass

golangci-lint doesn't follow the treefmt spec so it can't be integrated
with treefmt unfortunately.
This commit is contained in:
zimbatm 2024-06-14 12:32:41 +02:00
parent 251012657a
commit 6d6a71a3ca
6 changed files with 17 additions and 11 deletions

View File

@ -49,7 +49,7 @@ func TestOnUnmatched(t *testing.T) {
// - "haskell/treefmt.toml" // - "haskell/treefmt.toml"
} }
out, err := cmd(t, "-C", tempDir, "--allow-missing-formatter", "--on-unmatched", "fatal") _, err = cmd(t, "-C", tempDir, "--allow-missing-formatter", "--on-unmatched", "fatal")
as.ErrorContains(err, fmt.Sprintf("no formatter for path: %s", paths[0])) as.ErrorContains(err, fmt.Sprintf("no formatter for path: %s", paths[0]))
checkOutput := func(level string, output []byte) { checkOutput := func(level string, output []byte) {
@ -58,6 +58,8 @@ func TestOnUnmatched(t *testing.T) {
} }
} }
var out []byte
// default is warn // default is warn
out, err = cmd(t, "-C", tempDir, "--allow-missing-formatter", "-c") out, err = cmd(t, "-C", tempDir, "--allow-missing-formatter", "-c")
as.NoError(err) as.NoError(err)
@ -271,8 +273,13 @@ func TestCache(t *testing.T) {
}, },
} }
var (
out []byte
err error
)
test.WriteConfig(t, configPath, cfg) test.WriteConfig(t, configPath, cfg)
out, err := cmd(t, "--config-file", configPath, "--tree-root", tempDir) _, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err) as.NoError(err)
assertStats(t, as, 31, 31, 31, 0) assertStats(t, as, 31, 31, 31, 0)
@ -281,7 +288,7 @@ func TestCache(t *testing.T) {
assertFormatted(t, as, out, 0) assertFormatted(t, as, out, 0)
// clear cache // clear cache
out, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "-c") _, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "-c")
as.NoError(err) as.NoError(err)
assertStats(t, as, 31, 31, 31, 0) assertStats(t, as, 31, 31, 31, 0)
@ -290,7 +297,7 @@ func TestCache(t *testing.T) {
assertFormatted(t, as, out, 0) assertFormatted(t, as, out, 0)
// clear cache // clear cache
out, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "-c") _, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "-c")
as.NoError(err) as.NoError(err)
assertStats(t, as, 31, 31, 31, 0) assertStats(t, as, 31, 31, 31, 0)
@ -299,7 +306,7 @@ func TestCache(t *testing.T) {
assertFormatted(t, as, out, 0) assertFormatted(t, as, out, 0)
// no cache // no cache
out, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "--no-cache") _, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "--no-cache")
as.NoError(err) as.NoError(err)
assertStats(t, as, 31, 31, 31, 0) assertStats(t, as, 31, 31, 31, 0)
} }

View File

@ -31,8 +31,6 @@ type Formatter struct {
// internal compiled versions of Includes and Excludes. // internal compiled versions of Includes and Excludes.
includes []glob.Glob includes []glob.Glob
excludes []glob.Glob excludes []glob.Glob
batch []string
} }
// Executable returns the path to the executable defined by Command // Executable returns the path to the executable defined by Command
@ -80,7 +78,7 @@ func (f *Formatter) Apply(ctx context.Context, tasks []*Task) error {
// //
f.log.Infof("%v files processed in %v", len(tasks), time.Now().Sub(start)) f.log.Infof("%v files processed in %v", len(tasks), time.Since(start))
return nil return nil
} }

View File

@ -28,6 +28,7 @@
# golang # golang
go go
goreleaser goreleaser
golangci-lint
delve delve
pprof pprof
graphviz graphviz

View File

@ -42,7 +42,7 @@ func Value(t Type) int32 {
} }
func Elapsed() time.Duration { func Elapsed() time.Duration {
return time.Now().Sub(start) return time.Since(start)
} }
func Print() { func Print() {

View File

@ -28,7 +28,7 @@ func (f filesystemWalker) Walk(_ context.Context, fn WalkFunc) error {
return filepath.Rel(f.root, path) return filepath.Rel(f.root, path)
} }
walkFn := func(path string, info fs.FileInfo, err error) error { walkFn := func(path string, info fs.FileInfo, _ error) error {
if info == nil { if info == nil {
return fmt.Errorf("no such file or directory '%s'", path) return fmt.Errorf("no such file or directory '%s'", path)
} }

View File

@ -88,7 +88,7 @@ func (g *gitWalker) Walk(ctx context.Context, fn WalkFunc) error {
continue continue
} }
return filepath.Walk(path, func(path string, info fs.FileInfo, err error) error { return filepath.Walk(path, func(path string, info fs.FileInfo, _ error) error {
if info.IsDir() { if info.IsDir() {
return nil return nil
} }