@@ -17,7 +17,7 @@ const goModDirectivesName = "gomoddirectives"
17
17
// NewGoModDirectives returns a new gomoddirectives linter.
18
18
func NewGoModDirectives (settings * config.GoModDirectivesSettings ) * goanalysis.Linter {
19
19
var issues []goanalysis.Issue
20
- var mu sync.Mutex
20
+ var once sync.Once
21
21
22
22
var opts gomoddirectives.Options
23
23
if settings != nil {
@@ -39,24 +39,22 @@ func NewGoModDirectives(settings *config.GoModDirectivesSettings) *goanalysis.Li
39
39
nil ,
40
40
).WithContextSetter (func (lintCtx * linter.Context ) {
41
41
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
+ }
48
49
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
+ })
60
58
61
59
return nil , nil
62
60
}
0 commit comments