mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
dev: rewrite linters Manager (#4419)
This commit is contained in:
parent
26f8088b38
commit
b14d05cdb4
27 changed files with 1749 additions and 1825 deletions
|
@ -41,7 +41,7 @@ func newHelpCommand(logger logutils.Log) *helpCommand {
|
|||
Args: cobra.NoArgs,
|
||||
ValidArgsFunction: cobra.NoFileCompletions,
|
||||
Run: c.execute,
|
||||
PreRun: c.preRun,
|
||||
PreRunE: c.preRunE,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -50,10 +50,18 @@ func newHelpCommand(logger logutils.Log) *helpCommand {
|
|||
return c
|
||||
}
|
||||
|
||||
func (c *helpCommand) preRun(_ *cobra.Command, _ []string) {
|
||||
func (c *helpCommand) preRunE(_ *cobra.Command, _ []string) error {
|
||||
// The command doesn't depend on the real configuration.
|
||||
// It just needs the list of all plugins and all presets.
|
||||
c.dbManager = lintersdb.NewManager(config.NewDefault(), c.log)
|
||||
dbManager, err := lintersdb.NewManager(c.log.Child(logutils.DebugKeyLintersDB), config.NewDefault(),
|
||||
lintersdb.NewPluginBuilder(c.log), lintersdb.NewLinterBuilder())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.dbManager = dbManager
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *helpCommand) execute(_ *cobra.Command, _ []string) {
|
||||
|
|
|
@ -27,8 +27,7 @@ type lintersCommand struct {
|
|||
|
||||
log logutils.Log
|
||||
|
||||
dbManager *lintersdb.Manager
|
||||
enabledLintersSet *lintersdb.EnabledSet
|
||||
dbManager *lintersdb.Manager
|
||||
}
|
||||
|
||||
func newLintersCommand(logger logutils.Log, cfg *config.Config) *lintersCommand {
|
||||
|
@ -65,15 +64,19 @@ func (c *lintersCommand) preRunE(cmd *cobra.Command, _ []string) error {
|
|||
return fmt.Errorf("can't load config: %w", err)
|
||||
}
|
||||
|
||||
c.dbManager = lintersdb.NewManager(c.cfg, c.log)
|
||||
c.enabledLintersSet = lintersdb.NewEnabledSet(c.dbManager,
|
||||
lintersdb.NewValidator(c.dbManager), c.log.Child(logutils.DebugKeyLintersDB), c.cfg)
|
||||
dbManager, err := lintersdb.NewManager(c.log.Child(logutils.DebugKeyLintersDB), c.cfg,
|
||||
lintersdb.NewPluginBuilder(c.log), lintersdb.NewLinterBuilder())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.dbManager = dbManager
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *lintersCommand) execute(_ *cobra.Command, _ []string) error {
|
||||
enabledLintersMap, err := c.enabledLintersSet.GetEnabledLintersMap()
|
||||
enabledLintersMap, err := c.dbManager.GetEnabledLintersMap()
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't get enabled linters: %w", err)
|
||||
}
|
||||
|
|
|
@ -80,8 +80,7 @@ type runCommand struct {
|
|||
|
||||
buildInfo BuildInfo
|
||||
|
||||
dbManager *lintersdb.Manager
|
||||
enabledLintersSet *lintersdb.EnabledSet
|
||||
dbManager *lintersdb.Manager
|
||||
|
||||
log logutils.Log
|
||||
debugf logutils.DebugFunc
|
||||
|
@ -171,9 +170,13 @@ func (c *runCommand) persistentPostRunE(_ *cobra.Command, _ []string) error {
|
|||
}
|
||||
|
||||
func (c *runCommand) preRunE(_ *cobra.Command, _ []string) error {
|
||||
c.dbManager = lintersdb.NewManager(c.cfg, c.log)
|
||||
c.enabledLintersSet = lintersdb.NewEnabledSet(c.dbManager,
|
||||
lintersdb.NewValidator(c.dbManager), c.log.Child(logutils.DebugKeyLintersDB), c.cfg)
|
||||
dbManager, err := lintersdb.NewManager(c.log.Child(logutils.DebugKeyLintersDB), c.cfg,
|
||||
lintersdb.NewPluginBuilder(c.log), lintersdb.NewLinterBuilder())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.dbManager = dbManager
|
||||
|
||||
c.goenv = goutil.NewEnv(c.log.Child(logutils.DebugKeyGoEnv))
|
||||
|
||||
|
@ -340,12 +343,12 @@ func (c *runCommand) runAndPrint(ctx context.Context, args []string) error {
|
|||
func (c *runCommand) runAnalysis(ctx context.Context, args []string) ([]result.Issue, error) {
|
||||
c.cfg.Run.Args = args
|
||||
|
||||
lintersToRun, err := c.enabledLintersSet.GetOptimizedLinters()
|
||||
lintersToRun, err := c.dbManager.GetOptimizedLinters()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
enabledLintersMap, err := c.enabledLintersSet.GetEnabledLintersMap()
|
||||
enabledLintersMap, err := c.dbManager.GetEnabledLintersMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -361,8 +364,8 @@ func (c *runCommand) runAnalysis(ctx context.Context, args []string) ([]result.I
|
|||
}
|
||||
lintCtx.Log = c.log.Child(logutils.DebugKeyLintersContext)
|
||||
|
||||
runner, err := lint.NewRunner(c.cfg, c.log.Child(logutils.DebugKeyRunner),
|
||||
c.goenv, c.enabledLintersSet, c.lineCache, c.fileCache, c.dbManager, lintCtx.Packages)
|
||||
runner, err := lint.NewRunner(c.log.Child(logutils.DebugKeyRunner),
|
||||
c.cfg, c.goenv, c.lineCache, c.fileCache, c.dbManager, lintCtx.Packages)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ type versionInfo struct {
|
|||
}
|
||||
|
||||
type versionOptions struct {
|
||||
Format string `mapstructure:"format"`
|
||||
Debug bool `mapstructure:"debug"`
|
||||
Format string
|
||||
Debug bool
|
||||
}
|
||||
|
||||
type versionCommand struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue