Skip to content

Commit 7600885

Browse files
committed
feat: use meta formatter inside fixer processor
1 parent b8f3f33 commit 7600885

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pkg/lint/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti
105105
processors.NewSeverity(log.Child(logutils.DebugKeySeverityRules), files, &cfg.Severity),
106106

107107
// The fixer still needs to see paths for the issues that are relative to the current directory.
108-
processors.NewFixer(cfg, log, fileCache),
108+
processors.NewFixer(cfg, log, fileCache, metaFormatter),
109109
// The formatter needs to be after the fixer and the last processor that write files.
110110
formatter,
111111

pkg/result/processors/fixer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package processors
99
import (
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

Comments
 (0)