7
7
"runtime/debug"
8
8
"strings"
9
9
10
+ "github.com/pkg/errors"
11
+
10
12
"github.com/golangci/golangci-lint/internal/errorutil"
11
13
"github.com/golangci/golangci-lint/pkg/config"
12
14
"github.com/golangci/golangci-lint/pkg/fsutils"
@@ -27,7 +29,7 @@ type Runner struct {
27
29
Log logutils.Log
28
30
}
29
31
30
- func NewRunner (cfg * config.Config , log logutils.Log , goenv * goutil.Env ,
32
+ func NewRunner (cfg * config.Config , log logutils.Log , goenv * goutil.Env , es * lintersdb. EnabledSet ,
31
33
lineCache * fsutils.LineCache , dbManager * lintersdb.Manager , pkgs []* gopackages.Package ) (* Runner , error ) {
32
34
icfg := cfg .Issues
33
35
excludePatterns := icfg .ExcludePatterns
@@ -77,11 +79,9 @@ func NewRunner(cfg *config.Config, log logutils.Log, goenv *goutil.Env,
77
79
excludeRulesProcessor = processors .NewExcludeRules (excludeRules , lineCache , log .Child ("exclude_rules" ))
78
80
}
79
81
80
- enabledLintersSet := lintersdb .NewEnabledSet (dbManager ,
81
- lintersdb .NewValidator (dbManager ), log .Child ("enabledLinters" ), cfg )
82
- lcs , err := enabledLintersSet .Get (false )
82
+ enabledLinters , err := es .GetEnabledLintersMap ()
83
83
if err != nil {
84
- return nil , err
84
+ return nil , errors . Wrap ( err , "failed to get enabled linters" )
85
85
}
86
86
87
87
return & Runner {
@@ -103,7 +103,7 @@ func NewRunner(cfg *config.Config, log logutils.Log, goenv *goutil.Env,
103
103
104
104
excludeProcessor ,
105
105
excludeRulesProcessor ,
106
- processors .NewNolint (log .Child ("nolint" ), dbManager , lcs ),
106
+ processors .NewNolint (log .Child ("nolint" ), dbManager , enabledLinters ),
107
107
108
108
processors .NewUniqByLine (cfg ),
109
109
processors .NewDiff (icfg .Diff , icfg .DiffFromRevision , icfg .DiffPatchFilePath ),
@@ -131,14 +131,17 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
131
131
}
132
132
}()
133
133
134
- specificLintCtx := * lintCtx
135
- specificLintCtx .Log = r .Log .Child (lc .Name ())
134
+ issues , err := lc .Linter .Run (ctx , lintCtx )
135
+
136
+ if lc .DoesChangeTypes {
137
+ // Packages in lintCtx might be dirty due to the last analysis,
138
+ // which affects to the next analysis.
139
+ // To avoid this issue, we clear type information from the packages.
140
+ // See https://github.com/golangci/golangci-lint/pull/944.
141
+ // Currently DoesChangeTypes is true only for `unused`.
142
+ lintCtx .ClearTypesInPackages ()
143
+ }
136
144
137
- // Packages in lintCtx might be dirty due to the last analysis,
138
- // which affects to the next analysis.
139
- // To avoid this issue, we clear type information from the packages.
140
- specificLintCtx .ClearTypesInPackages ()
141
- issues , err := lc .Linter .Run (ctx , & specificLintCtx )
142
145
if err != nil {
143
146
return nil , err
144
147
}
0 commit comments