Skip to content

Commit 22957f3

Browse files
committed
feat: once.
1 parent 3fdbcfb commit 22957f3

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

pkg/golinters/gomoddirectives.go

+16-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const goModDirectivesName = "gomoddirectives"
1717
// NewGoModDirectives returns a new gomoddirectives linter.
1818
func NewGoModDirectives(settings *config.GoModDirectivesSettings) *goanalysis.Linter {
1919
var issues []goanalysis.Issue
20-
var mu sync.Mutex
20+
var once sync.Once
2121

2222
var opts gomoddirectives.Options
2323
if settings != nil {
@@ -39,24 +39,22 @@ func NewGoModDirectives(settings *config.GoModDirectivesSettings) *goanalysis.Li
3939
nil,
4040
).WithContextSetter(func(lintCtx *linter.Context) {
4141
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
42-
results, err := gomoddirectives.Analyze(opts)
43-
if err != nil {
44-
lintCtx.Log.Warnf("running %s failed: %s: "+
45-
"if you are not using go modules it is suggested to disable this linter", goModDirectivesName, err)
46-
return nil, nil
47-
}
42+
once.Do(func() {
43+
results, err := gomoddirectives.Analyze(opts)
44+
if err != nil {
45+
lintCtx.Log.Warnf("running %s failed: %s: "+
46+
"if you are not using go modules it is suggested to disable this linter", goModDirectivesName, err)
47+
return
48+
}
4849

49-
mu.Lock()
50-
51-
for _, p := range results {
52-
issues = append(issues, goanalysis.NewIssue(&result.Issue{
53-
FromLinter: goModDirectivesName,
54-
Pos: p.Start,
55-
Text: p.Reason,
56-
}, pass))
57-
}
58-
59-
mu.Unlock()
50+
for _, p := range results {
51+
issues = append(issues, goanalysis.NewIssue(&result.Issue{
52+
FromLinter: goModDirectivesName,
53+
Pos: p.Start,
54+
Text: p.Reason,
55+
}, pass))
56+
}
57+
})
6058

6159
return nil, nil
6260
}

0 commit comments

Comments
 (0)