Skip to content

Commit e1fbf35

Browse files
committed
chore: migrate unparam
1 parent c7e3c0f commit e1fbf35

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

pkg/golinters/unparam/unparam.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package unparam
22

33
import (
4-
"sync"
5-
64
"golang.org/x/tools/go/analysis"
75
"golang.org/x/tools/go/analysis/passes/buildssa"
86
"golang.org/x/tools/go/packages"
@@ -11,33 +9,21 @@ import (
119
"github.com/golangci/golangci-lint/pkg/config"
1210
"github.com/golangci/golangci-lint/pkg/goanalysis"
1311
"github.com/golangci/golangci-lint/pkg/lint/linter"
14-
"github.com/golangci/golangci-lint/pkg/result"
1512
)
1613

1714
const linterName = "unparam"
1815

1916
func New(settings *config.UnparamSettings) *goanalysis.Linter {
20-
var mu sync.Mutex
21-
var resIssues []goanalysis.Issue
22-
2317
analyzer := &analysis.Analyzer{
2418
Name: linterName,
2519
Doc: goanalysis.TheOnlyanalyzerDoc,
2620
Requires: []*analysis.Analyzer{buildssa.Analyzer},
2721
Run: func(pass *analysis.Pass) (any, error) {
28-
issues, err := runUnparam(pass, settings)
22+
err := runUnparam(pass, settings)
2923
if err != nil {
3024
return nil, err
3125
}
3226

33-
if len(issues) == 0 {
34-
return nil, nil
35-
}
36-
37-
mu.Lock()
38-
resIssues = append(resIssues, issues...)
39-
mu.Unlock()
40-
4127
return nil, nil
4228
},
4329
}
@@ -51,12 +37,10 @@ func New(settings *config.UnparamSettings) *goanalysis.Linter {
5137
if settings.Algo != "cha" {
5238
lintCtx.Log.Warnf("`linters-settings.unparam.algo` isn't supported by the newest `unparam`")
5339
}
54-
}).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
55-
return resIssues
5640
}).WithLoadMode(goanalysis.LoadModeTypesInfo)
5741
}
5842

59-
func runUnparam(pass *analysis.Pass, settings *config.UnparamSettings) ([]goanalysis.Issue, error) {
43+
func runUnparam(pass *analysis.Pass, settings *config.UnparamSettings) error {
6044
ssa := pass.ResultOf[buildssa.Analyzer].(*buildssa.SSA)
6145
ssaPkg := ssa.Pkg
6246

@@ -74,17 +58,15 @@ func runUnparam(pass *analysis.Pass, settings *config.UnparamSettings) ([]goanal
7458

7559
unparamIssues, err := c.Check()
7660
if err != nil {
77-
return nil, err
61+
return err
7862
}
7963

80-
var issues []goanalysis.Issue
8164
for _, i := range unparamIssues {
82-
issues = append(issues, goanalysis.NewIssue(&result.Issue{
83-
Pos: pass.Fset.Position(i.Pos()),
84-
Text: i.Message(),
85-
FromLinter: linterName,
86-
}, pass))
65+
pass.Report(analysis.Diagnostic{
66+
Pos: i.Pos(),
67+
Message: i.Message(),
68+
})
8769
}
8870

89-
return issues, nil
71+
return nil
9072
}

0 commit comments

Comments
 (0)