@@ -9,7 +9,6 @@ package processors
99import (
1010 "errors"
1111 "fmt"
12- "go/format"
1312 "os"
1413 "slices"
1514
@@ -18,6 +17,7 @@ import (
1817 "github.com/golangci/golangci-lint/internal/x/tools/diff"
1918 "github.com/golangci/golangci-lint/pkg/config"
2019 "github.com/golangci/golangci-lint/pkg/fsutils"
20+ "github.com/golangci/golangci-lint/pkg/goformatters"
2121 "github.com/golangci/golangci-lint/pkg/goformatters/gci"
2222 "github.com/golangci/golangci-lint/pkg/goformatters/gofmt"
2323 "github.com/golangci/golangci-lint/pkg/goformatters/gofumpt"
@@ -36,14 +36,16 @@ type Fixer struct {
3636 log logutils.Log
3737 fileCache * fsutils.FileCache
3838 sw * timeutils.Stopwatch
39+ formatter * goformatters.MetaFormatter
3940}
4041
41- func NewFixer (cfg * config.Config , log logutils.Log , fileCache * fsutils.FileCache ) * Fixer {
42+ func NewFixer (cfg * config.Config , log logutils.Log , fileCache * fsutils.FileCache , formatter * goformatters. MetaFormatter ) * Fixer {
4243 return & Fixer {
4344 cfg : cfg ,
4445 log : log ,
4546 fileCache : fileCache ,
4647 sw : timeutils .NewStopwatch ("fixer" , log ),
48+ formatter : formatter ,
4749 }
4850}
4951
@@ -188,9 +190,7 @@ func (p Fixer) process(issues []result.Issue) ([]result.Issue, error) {
188190 }
189191
190192 // Try to format the file.
191- if formatted , err := format .Source (out ); err == nil {
192- out = formatted
193- }
193+ out = p .formatter .Format (path , out )
194194
195195 if err := os .WriteFile (path , out , filePerm ); err != nil {
196196 editError = errors .Join (editError , fmt .Errorf ("%s: %w" , path , err ))
0 commit comments