@@ -9,7 +9,6 @@ package processors
9
9
import (
10
10
"errors"
11
11
"fmt"
12
- "go/format"
13
12
"os"
14
13
"slices"
15
14
@@ -18,6 +17,7 @@ import (
18
17
"github.com/golangci/golangci-lint/internal/x/tools/diff"
19
18
"github.com/golangci/golangci-lint/pkg/config"
20
19
"github.com/golangci/golangci-lint/pkg/fsutils"
20
+ "github.com/golangci/golangci-lint/pkg/goformatters"
21
21
"github.com/golangci/golangci-lint/pkg/goformatters/gci"
22
22
"github.com/golangci/golangci-lint/pkg/goformatters/gofmt"
23
23
"github.com/golangci/golangci-lint/pkg/goformatters/gofumpt"
@@ -36,14 +36,16 @@ type Fixer struct {
36
36
log logutils.Log
37
37
fileCache * fsutils.FileCache
38
38
sw * timeutils.Stopwatch
39
+ formatter * goformatters.MetaFormatter
39
40
}
40
41
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 {
42
43
return & Fixer {
43
44
cfg : cfg ,
44
45
log : log ,
45
46
fileCache : fileCache ,
46
47
sw : timeutils .NewStopwatch ("fixer" , log ),
48
+ formatter : formatter ,
47
49
}
48
50
}
49
51
@@ -188,9 +190,7 @@ func (p Fixer) process(issues []result.Issue) ([]result.Issue, error) {
188
190
}
189
191
190
192
// 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 )
194
194
195
195
if err := os .WriteFile (path , out , filePerm ); err != nil {
196
196
editError = errors .Join (editError , fmt .Errorf ("%s: %w" , path , err ))
0 commit comments