mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-20 18:28:44 -04:00
dev: the printer just needs Output configuration (#4479)
This commit is contained in:
parent
05f27abc01
commit
f0fdea006f
4 changed files with 53 additions and 56 deletions
pkg/commands
|
@ -35,6 +35,7 @@ import (
|
|||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis/load"
|
||||
"github.com/golangci/golangci-lint/pkg/goutil"
|
||||
"github.com/golangci/golangci-lint/pkg/lint"
|
||||
"github.com/golangci/golangci-lint/pkg/lint/linter"
|
||||
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
|
||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||
"github.com/golangci/golangci-lint/pkg/packages"
|
||||
|
@ -186,7 +187,7 @@ func (c *runCommand) preRunE(_ *cobra.Command, _ []string) error {
|
|||
|
||||
c.dbManager = dbManager
|
||||
|
||||
printer, err := printers.NewPrinter(c.log, c.cfg, c.reportData)
|
||||
printer, err := printers.NewPrinter(c.log, &c.cfg.Output, c.reportData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -327,11 +328,24 @@ func (c *runCommand) runAndPrint(ctx context.Context, args []string) error {
|
|||
}()
|
||||
}
|
||||
|
||||
enabledLintersMap, err := c.dbManager.GetEnabledLintersMap()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.printDeprecatedLinterMessages(enabledLintersMap)
|
||||
|
||||
issues, err := c.runAnalysis(ctx, args)
|
||||
if err != nil {
|
||||
return err // XXX: don't lose type
|
||||
}
|
||||
|
||||
// Fills linters information for the JSON printer.
|
||||
for _, lc := range c.dbManager.GetAllSupportedLinterConfigs() {
|
||||
isEnabled := enabledLintersMap[lc.Name()] != nil
|
||||
c.reportData.AddLinter(lc.Name(), isEnabled, lc.EnabledByDefault)
|
||||
}
|
||||
|
||||
err = c.printer.Print(issues)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -355,16 +369,6 @@ func (c *runCommand) runAnalysis(ctx context.Context, args []string) ([]result.I
|
|||
return nil, err
|
||||
}
|
||||
|
||||
enabledLintersMap, err := c.dbManager.GetEnabledLintersMap()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, lc := range c.dbManager.GetAllSupportedLinterConfigs() {
|
||||
isEnabled := enabledLintersMap[lc.Name()] != nil
|
||||
c.reportData.AddLinter(lc.Name(), isEnabled, lc.EnabledByDefault)
|
||||
}
|
||||
|
||||
lintCtx, err := c.contextLoader.Load(ctx, c.log.Child(logutils.DebugKeyLintersContext), lintersToRun)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("context loading failed: %w", err)
|
||||
|
@ -397,6 +401,25 @@ func (c *runCommand) setExitCodeIfIssuesFound(issues []result.Issue) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *runCommand) printDeprecatedLinterMessages(enabledLinters map[string]*linter.Config) {
|
||||
if c.cfg.InternalCmdTest {
|
||||
return
|
||||
}
|
||||
|
||||
for name, lc := range enabledLinters {
|
||||
if !lc.IsDeprecated() {
|
||||
continue
|
||||
}
|
||||
|
||||
var extra string
|
||||
if lc.Deprecation.Replacement != "" {
|
||||
extra = fmt.Sprintf("Replaced by %s.", lc.Deprecation.Replacement)
|
||||
}
|
||||
|
||||
c.log.Warnf("The linter '%s' is deprecated (since %s) due to: %s %s", name, lc.Deprecation.Since, lc.Deprecation.Message, extra)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *runCommand) printStats(issues []result.Issue) {
|
||||
if c.cfg.Run.ShowStats {
|
||||
c.log.Warnf("The configuration option `run.show-stats` is deprecated, please use `output.show-stats`")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue