diff --git a/docs/src/docs/contributing/architecture.mdx b/docs/src/docs/contributing/architecture.mdx index e9df647556da..e398db57e4e8 100644 --- a/docs/src/docs/contributing/architecture.mdx +++ b/docs/src/docs/contributing/architecture.mdx @@ -222,7 +222,7 @@ The abstraction is simple: ```go title=pkg/result/processors/processor.go type Processor interface { - Process(issues []result.Issue) ([]result.Issue, error) + Process(issues []*result.Issue) ([]*result.Issue, error) Name() string Finish() } diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 53902eafac24..4e2d3b1b984a 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -376,7 +376,7 @@ func (c *runCommand) runAndPrint(ctx context.Context) error { } // runAnalysis executes the linters that have been enabled in the configuration. -func (c *runCommand) runAnalysis(ctx context.Context) ([]result.Issue, error) { +func (c *runCommand) runAnalysis(ctx context.Context) ([]*result.Issue, error) { lintersToRun, err := c.dbManager.GetOptimizedLinters() if err != nil { return nil, err @@ -408,7 +408,7 @@ func (c *runCommand) setOutputToDevNull() (savedStdout, savedStderr *os.File) { return } -func (c *runCommand) setExitCodeIfIssuesFound(issues []result.Issue) { +func (c *runCommand) setExitCodeIfIssuesFound(issues []*result.Issue) { if len(issues) != 0 { c.exitCode = c.cfg.Run.ExitCodeIfIssuesFound } @@ -433,7 +433,7 @@ func (c *runCommand) printDeprecatedLinterMessages(enabledLinters map[string]*li } } -func (c *runCommand) printStats(issues []result.Issue) { +func (c *runCommand) printStats(issues []*result.Issue) { if !c.cfg.Output.ShowStats { return } diff --git a/pkg/goanalysis/issue.go b/pkg/goanalysis/issue.go index c41702595c55..88a59e53dbc9 100644 --- a/pkg/goanalysis/issue.go +++ b/pkg/goanalysis/issue.go @@ -9,13 +9,13 @@ import ( ) type Issue struct { - result.Issue + *result.Issue Pass *analysis.Pass } -func NewIssue(issue *result.Issue, pass *analysis.Pass) Issue { - return Issue{ - Issue: *issue, +func NewIssue(issue *result.Issue, pass *analysis.Pass) *Issue { + return &Issue{ + Issue: issue, Pass: pass, } } diff --git a/pkg/goanalysis/linter.go b/pkg/goanalysis/linter.go index 53f5b7bae455..29bd841a85c6 100644 --- a/pkg/goanalysis/linter.go +++ b/pkg/goanalysis/linter.go @@ -40,7 +40,7 @@ type Linter struct { name, desc string analyzers []*analysis.Analyzer cfg map[string]map[string]any - issuesReporter func(*linter.Context) []Issue + issuesReporter func(*linter.Context) []*Issue contextSetter func(*linter.Context) loadMode LoadMode needUseOriginalPackages bool @@ -54,7 +54,7 @@ func NewLinterFromAnalyzer(analyzer *analysis.Analyzer) *Linter { return NewLinter(analyzer.Name, analyzer.Doc, []*analysis.Analyzer{analyzer}, nil) } -func (lnt *Linter) Run(_ context.Context, lintCtx *linter.Context) ([]result.Issue, error) { +func (lnt *Linter) Run(_ context.Context, lintCtx *linter.Context) ([]*result.Issue, error) { if err := lnt.preRun(lintCtx); err != nil { return nil, err } @@ -93,7 +93,7 @@ func (lnt *Linter) WithLoadMode(loadMode LoadMode) *Linter { return lnt } -func (lnt *Linter) WithIssuesReporter(r func(*linter.Context) []Issue) *Linter { +func (lnt *Linter) WithIssuesReporter(r func(*linter.Context) []*Issue) *Linter { lnt.issuesReporter = r return lnt } @@ -193,7 +193,7 @@ func (lnt *Linter) useOriginalPackages() bool { return lnt.needUseOriginalPackages } -func (lnt *Linter) reportIssues(lintCtx *linter.Context) []Issue { +func (lnt *Linter) reportIssues(lintCtx *linter.Context) []*Issue { if lnt.issuesReporter != nil { return lnt.issuesReporter(lintCtx) } diff --git a/pkg/goanalysis/metalinter.go b/pkg/goanalysis/metalinter.go index 4db143baddb3..b9a210a66fc8 100644 --- a/pkg/goanalysis/metalinter.go +++ b/pkg/goanalysis/metalinter.go @@ -21,7 +21,7 @@ func NewMetaLinter(linters []*Linter) *MetaLinter { return ml } -func (ml MetaLinter) Run(_ context.Context, lintCtx *linter.Context) ([]result.Issue, error) { +func (ml MetaLinter) Run(_ context.Context, lintCtx *linter.Context) ([]*result.Issue, error) { for _, l := range ml.linters { if err := l.preRun(lintCtx); err != nil { return nil, fmt.Errorf("failed to pre-run %s: %w", l.Name(), err) @@ -65,8 +65,8 @@ func (MetaLinter) useOriginalPackages() bool { return false // `unused` can't be run by this metalinter } -func (ml MetaLinter) reportIssues(lintCtx *linter.Context) []Issue { - var ret []Issue +func (ml MetaLinter) reportIssues(lintCtx *linter.Context) []*Issue { + var ret []*Issue for _, lnt := range ml.linters { if lnt.issuesReporter != nil { ret = append(ret, lnt.issuesReporter(lintCtx)...) diff --git a/pkg/goanalysis/pkgerrors/errors.go b/pkg/goanalysis/pkgerrors/errors.go index 587e72720e98..062a8f43aeff 100644 --- a/pkg/goanalysis/pkgerrors/errors.go +++ b/pkg/goanalysis/pkgerrors/errors.go @@ -18,8 +18,8 @@ func (e *IllTypedError) Error() string { return fmt.Sprintf("IllTypedError: errors in package: %v", e.Pkg.Errors) } -func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]result.Issue, error) { - var issues []result.Issue +func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]*result.Issue, error) { + var issues []*result.Issue uniqReportedIssues := map[string]bool{} var other error @@ -43,7 +43,7 @@ func BuildIssuesFromIllTypedError(errs []error, lintCtx *linter.Context) ([]resu lintCtx.Log.Errorf("typechecking error: %s", err.Msg) } else { issue.Pkg = ill.Pkg // to save to cache later - issues = append(issues, *issue) + issues = append(issues, issue) } } } diff --git a/pkg/goanalysis/runner.go b/pkg/goanalysis/runner.go index 808c9d2ad68c..6cc0a7077109 100644 --- a/pkg/goanalysis/runner.go +++ b/pkg/goanalysis/runner.go @@ -76,7 +76,7 @@ func newRunner(prefix string, logger logutils.Log, pkgCache *cache.Cache, loadGu // It provides most of the logic for the main functions of both the // singlechecker and the multi-analysis commands. // It returns the appropriate exit code. -func (r *runner) run(analyzers []*analysis.Analyzer, initialPackages []*packages.Package) ([]Diagnostic, +func (r *runner) run(analyzers []*analysis.Analyzer, initialPackages []*packages.Package) ([]*Diagnostic, []error, map[*analysis.Pass]*packages.Package, ) { debugf("Analyzing %d packages on load mode %s", len(initialPackages), r.loadMode) @@ -275,7 +275,7 @@ func (r *runner) analyze(pkgs []*packages.Package, analyzers []*analysis.Analyze return rootActions } -func extractDiagnostics(roots []*action) (retDiags []Diagnostic, retErrors []error) { +func extractDiagnostics(roots []*action) (retDiags []*Diagnostic, retErrors []error) { extracted := make(map[*action]bool) var extract func(*action) var visitAll func(actions []*action) @@ -322,7 +322,7 @@ func extractDiagnostics(roots []*action) (retDiags []Diagnostic, retErrors []err } seen[k] = true - retDiag := Diagnostic{ + retDiag := &Diagnostic{ File: file, Diagnostic: diag, Analyzer: act.Analyzer, diff --git a/pkg/goanalysis/runners.go b/pkg/goanalysis/runners.go index fe8d8fe854d3..bcbc0033ef9a 100644 --- a/pkg/goanalysis/runners.go +++ b/pkg/goanalysis/runners.go @@ -3,6 +3,7 @@ package goanalysis import ( "fmt" "go/token" + "slices" "strings" "golang.org/x/tools/go/analysis" @@ -20,11 +21,11 @@ type runAnalyzersConfig interface { getLinterNameForDiagnostic(*Diagnostic) string getAnalyzers() []*analysis.Analyzer useOriginalPackages() bool - reportIssues(*linter.Context) []Issue + reportIssues(*linter.Context) []*Issue getLoadMode() LoadMode } -func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Issue, error) { +func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]*result.Issue, error) { log := lintCtx.Log.Child(logutils.DebugKeyGoAnalysis) sw := timeutils.NewStopwatch("analyzers", log) @@ -56,18 +57,19 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss } }() - buildAllIssues := func() []result.Issue { - var retIssues []result.Issue + buildAllIssues := func() []*result.Issue { + var retIssues []*result.Issue + reportedIssues := cfg.reportIssues(lintCtx) - for i := range reportedIssues { - issue := &reportedIssues[i].Issue - if issue.Pkg == nil { - issue.Pkg = passToPkg[reportedIssues[i].Pass] + for _, reportedIssue := range reportedIssues { + if reportedIssue.Pkg == nil { + reportedIssue.Pkg = passToPkg[reportedIssue.Pass] } - retIssues = append(retIssues, *issue) + + retIssues = append(retIssues, reportedIssue.Issue) } - retIssues = append(retIssues, buildIssues(diags, cfg.getLinterNameForDiagnostic)...) - return retIssues + + return slices.Concat(retIssues, buildIssues(diags, cfg.getLinterNameForDiagnostic)) } errIssues, err := pkgerrors.BuildIssuesFromIllTypedError(errs, lintCtx) @@ -81,11 +83,10 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss return issues, nil } -func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) string) []result.Issue { - var issues []result.Issue +func buildIssues(diags []*Diagnostic, linterNameBuilder func(diag *Diagnostic) string) []*result.Issue { + var issues []*result.Issue - for i := range diags { - diag := &diags[i] + for _, diag := range diags { linterName := linterNameBuilder(diag) var text string @@ -126,7 +127,7 @@ func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) st suggestedFixes = append(suggestedFixes, nsf) } - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ FromLinter: linterName, Text: text, Pos: diag.Position, @@ -142,7 +143,7 @@ func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) st relatedPos = diag.Position } - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ FromLinter: linterName, Text: fmt.Sprintf("%s(related information): %s", diag.Analyzer.Name, info.Message), Pos: relatedPos, diff --git a/pkg/goanalysis/runners_cache.go b/pkg/goanalysis/runners_cache.go index 9673197c9ec9..5cd8a6b1ccd4 100644 --- a/pkg/goanalysis/runners_cache.go +++ b/pkg/goanalysis/runners_cache.go @@ -17,13 +17,12 @@ import ( ) func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages.Package]bool, - issues []result.Issue, lintCtx *linter.Context, analyzers []*analysis.Analyzer, + issues []*result.Issue, lintCtx *linter.Context, analyzers []*analysis.Analyzer, ) { startedAt := time.Now() - perPkgIssues := map[*packages.Package][]result.Issue{} - for ind := range issues { - i := &issues[ind] - perPkgIssues[i.Pkg] = append(perPkgIssues[i.Pkg], *i) + perPkgIssues := map[*packages.Package][]*result.Issue{} + for _, issue := range issues { + perPkgIssues[issue.Pkg] = append(perPkgIssues[issue.Pkg], issue) } var savedIssuesCount int64 = 0 @@ -34,23 +33,22 @@ func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages. wg.Add(workerCount) pkgCh := make(chan *packages.Package, len(allPkgs)) - for i := 0; i < workerCount; i++ { + for range workerCount { go func() { defer wg.Done() for pkg := range pkgCh { pkgIssues := perPkgIssues[pkg] encodedIssues := make([]EncodingIssue, 0, len(pkgIssues)) - for ind := range pkgIssues { - i := &pkgIssues[ind] + for _, issue := range pkgIssues { encodedIssues = append(encodedIssues, EncodingIssue{ - FromLinter: i.FromLinter, - Text: i.Text, - Severity: i.Severity, - Pos: i.Pos, - LineRange: i.LineRange, - SuggestedFixes: i.SuggestedFixes, - ExpectNoLint: i.ExpectNoLint, - ExpectedNoLintLinter: i.ExpectedNoLintLinter, + FromLinter: issue.FromLinter, + Text: issue.Text, + Severity: issue.Severity, + Pos: issue.Pos, + LineRange: issue.LineRange, + SuggestedFixes: issue.SuggestedFixes, + ExpectNoLint: issue.ExpectNoLint, + ExpectedNoLintLinter: issue.ExpectedNoLintLinter, }) } @@ -81,12 +79,12 @@ func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages. func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, analyzers []*analysis.Analyzer, -) (issuesFromCache []result.Issue, pkgsFromCache map[*packages.Package]bool) { +) (issuesFromCache []*result.Issue, pkgsFromCache map[*packages.Package]bool) { startedAt := time.Now() lintResKey := getIssuesCacheKey(analyzers) type cacheRes struct { - issues []result.Issue + issues []*result.Issue loadErr error } pkgToCacheRes := make(map[*packages.Package]*cacheRes, len(pkgs)) @@ -103,7 +101,7 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, go func() { defer wg.Done() for pkg := range pkgCh { - var pkgIssues []EncodingIssue + var pkgIssues []*EncodingIssue err := lintCtx.PkgCache.Get(pkg, cache.HashModeNeedAllDeps, lintResKey, &pkgIssues) cacheRes := pkgToCacheRes[pkg] cacheRes.loadErr = err @@ -114,10 +112,9 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context, continue } - issues := make([]result.Issue, 0, len(pkgIssues)) - for i := range pkgIssues { - issue := &pkgIssues[i] - issues = append(issues, result.Issue{ + issues := make([]*result.Issue, 0, len(pkgIssues)) + for _, issue := range pkgIssues { + issues = append(issues, &result.Issue{ FromLinter: issue.FromLinter, Text: issue.Text, Severity: issue.Severity, diff --git a/pkg/golinters/dupl/dupl.go b/pkg/golinters/dupl/dupl.go index 6d5323a8bad4..0b6b3a162c2e 100644 --- a/pkg/golinters/dupl/dupl.go +++ b/pkg/golinters/dupl/dupl.go @@ -20,7 +20,7 @@ const linterName = "dupl" func New(settings *config.DuplSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue return goanalysis. NewLinterFromAnalyzer(&analysis.Analyzer{ @@ -43,13 +43,13 @@ func New(settings *config.DuplSettings) *goanalysis.Linter { return nil, nil }, }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeSyntax) } -func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.Issue, error) { +func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]*goanalysis.Issue, error) { issues, err := duplAPI.Run(internal.GetGoFileNames(pass), settings.Threshold) if err != nil { return nil, err @@ -59,7 +59,7 @@ func runDupl(pass *analysis.Pass, settings *config.DuplSettings) ([]goanalysis.I return nil, nil } - res := make([]goanalysis.Issue, 0, len(issues)) + res := make([]*goanalysis.Issue, 0, len(issues)) for _, i := range issues { toFilename, err := fsutils.ShortestRelPath(i.To.Filename(), "") diff --git a/pkg/golinters/errcheck/errcheck.go b/pkg/golinters/errcheck/errcheck.go index ae34a53ef62c..6bd473845c3f 100644 --- a/pkg/golinters/errcheck/errcheck.go +++ b/pkg/golinters/errcheck/errcheck.go @@ -21,7 +21,7 @@ const linterName = "errcheck" func New(settings *config.ErrcheckSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue analyzer := &analysis.Analyzer{ Name: linterName, @@ -50,13 +50,13 @@ func New(settings *config.ErrcheckSettings) *goanalysis.Linter { return nil, nil } }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker, verbose bool) []goanalysis.Issue { +func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker, verbose bool) []*goanalysis.Issue { pkg := &packages.Package{ Fset: pass.Fset, Syntax: pass.Files, @@ -69,7 +69,7 @@ func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker, verbose bool) [ return nil } - issues := make([]goanalysis.Issue, len(lintIssues.UncheckedErrors)) + issues := make([]*goanalysis.Issue, len(lintIssues.UncheckedErrors)) for i, err := range lintIssues.UncheckedErrors { text := "Error return value is not checked" diff --git a/pkg/golinters/gochecksumtype/gochecksumtype.go b/pkg/golinters/gochecksumtype/gochecksumtype.go index 85be045dfa8a..825975f14570 100644 --- a/pkg/golinters/gochecksumtype/gochecksumtype.go +++ b/pkg/golinters/gochecksumtype/gochecksumtype.go @@ -18,7 +18,7 @@ const linterName = "gochecksumtype" func New(settings *config.GoChecksumTypeSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue return goanalysis. NewLinterFromAnalyzer(&analysis.Analyzer{ @@ -41,14 +41,14 @@ func New(settings *config.GoChecksumTypeSettings) *goanalysis.Linter { return nil, nil }, }). - WithIssuesReporter(func(_ *linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(_ *linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runGoCheckSumType(pass *analysis.Pass, settings *config.GoChecksumTypeSettings) ([]goanalysis.Issue, error) { - var resIssues []goanalysis.Issue +func runGoCheckSumType(pass *analysis.Pass, settings *config.GoChecksumTypeSettings) ([]*goanalysis.Issue, error) { + var resIssues []*goanalysis.Issue pkg := &packages.Package{ Fset: pass.Fset, diff --git a/pkg/golinters/gocognit/gocognit.go b/pkg/golinters/gocognit/gocognit.go index e72a9bdfe67a..b17912c0a649 100644 --- a/pkg/golinters/gocognit/gocognit.go +++ b/pkg/golinters/gocognit/gocognit.go @@ -19,7 +19,7 @@ const linterName = "gocognit" func New(settings *config.GocognitSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue return goanalysis. NewLinterFromAnalyzer(&analysis.Analyzer{ @@ -39,13 +39,13 @@ func New(settings *config.GocognitSettings) *goanalysis.Linter { return nil, nil }, }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeSyntax) } -func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []goanalysis.Issue { +func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []*goanalysis.Issue { var stats []gocognit.Stat for _, f := range pass.Files { stats = gocognit.ComplexityStats(f, pass.Fset, stats) @@ -58,7 +58,7 @@ func runGocognit(pass *analysis.Pass, settings *config.GocognitSettings) []goana return stats[i].Complexity > stats[j].Complexity }) - issues := make([]goanalysis.Issue, 0, len(stats)) + issues := make([]*goanalysis.Issue, 0, len(stats)) for _, s := range stats { if s.Complexity <= settings.MinComplexity { break // Break as the stats is already sorted from greatest to least diff --git a/pkg/golinters/goconst/goconst.go b/pkg/golinters/goconst/goconst.go index 5a44d4a5ce3a..b58d860c6eda 100644 --- a/pkg/golinters/goconst/goconst.go +++ b/pkg/golinters/goconst/goconst.go @@ -18,7 +18,7 @@ const linterName = "goconst" func New(settings *config.GoConstSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue return goanalysis. NewLinterFromAnalyzer(&analysis.Analyzer{ @@ -41,13 +41,13 @@ func New(settings *config.GoConstSettings) *goanalysis.Linter { return nil, nil }, }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]goanalysis.Issue, error) { +func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]*goanalysis.Issue, error) { cfg := goconstAPI.Config{ IgnoreStrings: settings.IgnoreStringValues, MatchWithConstants: settings.MatchWithConstants, @@ -77,7 +77,7 @@ func runGoconst(pass *analysis.Pass, settings *config.GoConstSettings) ([]goanal return nil, nil } - res := make([]goanalysis.Issue, 0, len(lintIssues)) + res := make([]*goanalysis.Issue, 0, len(lintIssues)) for i := range lintIssues { issue := &lintIssues[i] diff --git a/pkg/golinters/gocyclo/gocyclo.go b/pkg/golinters/gocyclo/gocyclo.go index 17b868d4972a..de0374607c06 100644 --- a/pkg/golinters/gocyclo/gocyclo.go +++ b/pkg/golinters/gocyclo/gocyclo.go @@ -18,7 +18,7 @@ const linterName = "gocyclo" func New(settings *config.GoCycloSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue return goanalysis. NewLinterFromAnalyzer(&analysis.Analyzer{ @@ -38,13 +38,13 @@ func New(settings *config.GoCycloSettings) *goanalysis.Linter { return nil, nil }, }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeSyntax) } -func runGoCyclo(pass *analysis.Pass, settings *config.GoCycloSettings) []goanalysis.Issue { +func runGoCyclo(pass *analysis.Pass, settings *config.GoCycloSettings) []*goanalysis.Issue { var stats gocyclo.Stats for _, f := range pass.Files { stats = gocyclo.AnalyzeASTFile(f, pass.Fset, stats) @@ -55,7 +55,7 @@ func runGoCyclo(pass *analysis.Pass, settings *config.GoCycloSettings) []goanaly stats = stats.SortAndFilter(-1, settings.MinComplexity) - issues := make([]goanalysis.Issue, 0, len(stats)) + issues := make([]*goanalysis.Issue, 0, len(stats)) for _, s := range stats { text := fmt.Sprintf("cyclomatic complexity %d of func %s is high (> %d)", diff --git a/pkg/golinters/gomoddirectives/gomoddirectives.go b/pkg/golinters/gomoddirectives/gomoddirectives.go index e11313a62b9c..dd6656fb6cb6 100644 --- a/pkg/golinters/gomoddirectives/gomoddirectives.go +++ b/pkg/golinters/gomoddirectives/gomoddirectives.go @@ -17,7 +17,7 @@ import ( const linterName = "gomoddirectives" func New(settings *config.GoModDirectivesSettings) *goanalysis.Linter { - var issues []goanalysis.Issue + var issues []*goanalysis.Issue var once sync.Once var opts gomoddirectives.Options @@ -79,7 +79,7 @@ func New(settings *config.GoModDirectivesSettings) *goanalysis.Linter { return nil, nil } }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return issues }). WithLoadMode(goanalysis.LoadModeSyntax) diff --git a/pkg/golinters/gomodguard/gomodguard.go b/pkg/golinters/gomodguard/gomodguard.go index 502610341342..7d16f57b3a5c 100644 --- a/pkg/golinters/gomodguard/gomodguard.go +++ b/pkg/golinters/gomodguard/gomodguard.go @@ -16,7 +16,7 @@ import ( const linterName = "gomodguard" func New(settings *config.GoModGuardSettings) *goanalysis.Linter { - var issues []goanalysis.Issue + var issues []*goanalysis.Issue var mu sync.Mutex processorCfg := &gomodguard.Configuration{} @@ -82,7 +82,7 @@ func New(settings *config.GoModGuardSettings) *goanalysis.Linter { return nil, nil } }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return issues }). WithLoadMode(goanalysis.LoadModeSyntax) diff --git a/pkg/golinters/gosec/gosec.go b/pkg/golinters/gosec/gosec.go index e38de1ee20e5..66d229295a3f 100644 --- a/pkg/golinters/gosec/gosec.go +++ b/pkg/golinters/gosec/gosec.go @@ -26,7 +26,7 @@ const linterName = "gosec" func New(settings *config.GoSecSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue conf := gosec.NewConfig() @@ -73,13 +73,13 @@ func New(settings *config.GoSecSettings) *goanalysis.Linter { return nil, nil } }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoSecSettings, analyzer *gosec.Analyzer) []goanalysis.Issue { +func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoSecSettings, analyzer *gosec.Analyzer) []*goanalysis.Issue { pkg := &packages.Package{ Fset: pass.Fset, Syntax: pass.Files, @@ -107,7 +107,7 @@ func runGoSec(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoS secIssues = filterIssues(secIssues, severity, confidence) - issues := make([]goanalysis.Issue, 0, len(secIssues)) + issues := make([]*goanalysis.Issue, 0, len(secIssues)) for _, i := range secIssues { text := fmt.Sprintf("%s: %s", i.RuleID, i.What) diff --git a/pkg/golinters/nolintlint/internal/nolintlint.go b/pkg/golinters/nolintlint/internal/nolintlint.go index 2be7c5c144ea..a20161405f1c 100644 --- a/pkg/golinters/nolintlint/internal/nolintlint.go +++ b/pkg/golinters/nolintlint/internal/nolintlint.go @@ -55,8 +55,8 @@ var ( ) //nolint:funlen,gocyclo // the function is going to be refactored in the future -func (l Linter) Run(pass *analysis.Pass) ([]goanalysis.Issue, error) { - var issues []goanalysis.Issue +func (l Linter) Run(pass *analysis.Pass) ([]*goanalysis.Issue, error) { + var issues []*goanalysis.Issue for _, file := range pass.Files { for _, c := range file.Comments { diff --git a/pkg/golinters/nolintlint/internal/nolintlint_test.go b/pkg/golinters/nolintlint/internal/nolintlint_test.go index 788d6b5a84dd..b534fbf89511 100644 --- a/pkg/golinters/nolintlint/internal/nolintlint_test.go +++ b/pkg/golinters/nolintlint/internal/nolintlint_test.go @@ -19,7 +19,7 @@ func TestLinter_Run(t *testing.T) { needs Needs excludes []string contents string - expected []result.Issue + expected []*result.Issue }{ { desc: "when no explanation is provided", @@ -36,7 +36,7 @@ func foo() { other() //nolintother } `, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "nolintlint", Text: "directive `//nolint` should provide explanation such as `//nolint // this is why`", @@ -69,7 +69,7 @@ func foo() { //nolint:dupl func foo() {} `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint:dupl` should provide explanation such as `//nolint:dupl // this is why`", Pos: token.Position{Filename: "testing.go", Offset: 47, Line: 5, Column: 1}, @@ -97,7 +97,7 @@ func foo() { bad() //nolint // because } `, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "nolintlint", Text: "directive `//nolint` should mention specific linter such as `//nolint:my-linter`", @@ -120,7 +120,7 @@ func foo() { good() //nolint } `, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "nolintlint", Text: "directive `// nolint` should be written without leading space as `//nolint`", @@ -158,7 +158,7 @@ func foo() { good() //nolint: linter1, linter2 } `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint:linter1 linter2` should match `//nolint[:] [// ]`", Pos: token.Position{Filename: "testing.go", Offset: 71, Line: 5, Column: 9}, @@ -183,7 +183,7 @@ func foo() { bad() //nolint } `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint` is unused", Pos: token.Position{Filename: "testing.go", Offset: 34, Line: 4, Column: 9}, @@ -205,7 +205,7 @@ func foo() { bad() //nolint:somelinter } `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint:somelinter` is unused for linter \"somelinter\"", Pos: token.Position{Filename: "testing.go", Offset: 34, Line: 4, Column: 9}, @@ -229,7 +229,7 @@ func foo() { bad() } `, - expected: []result.Issue{{ + expected: []*result.Issue{{ FromLinter: "nolintlint", Text: "directive `//nolint:somelinter` is unused for linter \"somelinter\"", Pos: token.Position{Filename: "testing.go", Offset: 13, Line: 3, Column: 1}, @@ -252,7 +252,7 @@ func foo() { bad() //nolint:linter1,linter2 } `, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "nolintlint", Text: "directive `//nolint:linter1,linter2` is unused for linter \"linter1\"", @@ -289,7 +289,7 @@ func foo() { analysisIssues, err := linter.Run(pass) require.NoError(t, err) - var issues []result.Issue + var issues []*result.Issue for _, i := range analysisIssues { issues = append(issues, i.Issue) } diff --git a/pkg/golinters/nolintlint/nolintlint.go b/pkg/golinters/nolintlint/nolintlint.go index 37f9cb96aac7..6f3d373063f8 100644 --- a/pkg/golinters/nolintlint/nolintlint.go +++ b/pkg/golinters/nolintlint/nolintlint.go @@ -17,7 +17,7 @@ const LinterName = nolintlint.LinterName func New(settings *config.NoLintLintSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue var needs nolintlint.Needs if settings.RequireExplanation { @@ -56,7 +56,7 @@ func New(settings *config.NoLintLintSettings) *goanalysis.Linter { return nil, nil }, }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeSyntax) diff --git a/pkg/golinters/promlinter/promlinter.go b/pkg/golinters/promlinter/promlinter.go index 2cb59cbe6f1a..491409f4ef7a 100644 --- a/pkg/golinters/promlinter/promlinter.go +++ b/pkg/golinters/promlinter/promlinter.go @@ -17,7 +17,7 @@ const linterName = "promlinter" func New(settings *config.PromlinterSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue var promSettings promlinter.Setting if settings != nil { @@ -45,20 +45,20 @@ func New(settings *config.PromlinterSettings) *goanalysis.Linter { return nil, nil }, }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeSyntax) } -func runPromLinter(pass *analysis.Pass, promSettings promlinter.Setting) []goanalysis.Issue { +func runPromLinter(pass *analysis.Pass, promSettings promlinter.Setting) []*goanalysis.Issue { lintIssues := promlinter.RunLint(pass.Fset, pass.Files, promSettings) if len(lintIssues) == 0 { return nil } - issues := make([]goanalysis.Issue, len(lintIssues)) + issues := make([]*goanalysis.Issue, len(lintIssues)) for k, i := range lintIssues { issue := result.Issue{ Pos: i.Pos, diff --git a/pkg/golinters/revive/revive.go b/pkg/golinters/revive/revive.go index b06b5de8aa28..3e13c516fa12 100644 --- a/pkg/golinters/revive/revive.go +++ b/pkg/golinters/revive/revive.go @@ -35,7 +35,7 @@ var ( func New(settings *config.ReviveSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue analyzer := &analysis.Analyzer{ Name: linterName, @@ -69,7 +69,7 @@ func New(settings *config.ReviveSettings) *goanalysis.Linter { return nil, nil } }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeSyntax) @@ -106,7 +106,7 @@ func newWrapper(settings *config.ReviveSettings) (*wrapper, error) { }, nil } -func (w *wrapper) run(pass *analysis.Pass) ([]goanalysis.Issue, error) { +func (w *wrapper) run(pass *analysis.Pass) ([]*goanalysis.Issue, error) { packages := [][]string{internal.GetGoFileNames(pass)} failures, err := w.revive.Lint(packages, w.lintingRules, *w.conf) @@ -114,7 +114,7 @@ func (w *wrapper) run(pass *analysis.Pass) ([]goanalysis.Issue, error) { return nil, err } - var issues []goanalysis.Issue + var issues []*goanalysis.Issue for failure := range failures { if failure.Confidence < w.conf.Confidence { continue @@ -126,7 +126,7 @@ func (w *wrapper) run(pass *analysis.Pass) ([]goanalysis.Issue, error) { return issues, nil } -func (w *wrapper) toIssue(pass *analysis.Pass, failure *lint.Failure) goanalysis.Issue { +func (w *wrapper) toIssue(pass *analysis.Pass, failure *lint.Failure) *goanalysis.Issue { lineRangeTo := failure.Position.End.Line if failure.RuleName == (&rule.ExportedRule{}).Name() { lineRangeTo = failure.Position.Start.Line diff --git a/pkg/golinters/unconvert/unconvert.go b/pkg/golinters/unconvert/unconvert.go index c9b3f75dd169..593dfbe96e63 100644 --- a/pkg/golinters/unconvert/unconvert.go +++ b/pkg/golinters/unconvert/unconvert.go @@ -16,7 +16,7 @@ const linterName = "unconvert" func New(settings *config.UnconvertSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue unconvert.SetFastMath(settings.FastMath) unconvert.SetSafe(settings.Safe) @@ -39,16 +39,16 @@ func New(settings *config.UnconvertSettings) *goanalysis.Linter { return nil, nil }, }). - WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { + WithIssuesReporter(func(*linter.Context) []*goanalysis.Issue { return resIssues }). WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runUnconvert(pass *analysis.Pass) []goanalysis.Issue { +func runUnconvert(pass *analysis.Pass) []*goanalysis.Issue { positions := unconvert.Run(pass) - var issues []goanalysis.Issue + var issues []*goanalysis.Issue for _, position := range positions { issues = append(issues, goanalysis.NewIssue(&result.Issue{ Pos: position, diff --git a/pkg/golinters/unused/unused.go b/pkg/golinters/unused/unused.go index 375962259676..c0f4657dcc26 100644 --- a/pkg/golinters/unused/unused.go +++ b/pkg/golinters/unused/unused.go @@ -20,7 +20,7 @@ const linterName = "unused" func New(settings *config.UnusedSettings) *goanalysis.Linter { var mu sync.Mutex - var resIssues []goanalysis.Issue + var resIssues []*goanalysis.Issue analyzer := &analysis.Analyzer{ Name: linterName, @@ -45,12 +45,12 @@ func New(settings *config.UnusedSettings) *goanalysis.Linter { "Checks Go code for unused constants, variables, functions and types", []*analysis.Analyzer{analyzer}, nil, - ).WithIssuesReporter(func(_ *linter.Context) []goanalysis.Issue { + ).WithIssuesReporter(func(_ *linter.Context) []*goanalysis.Issue { return resIssues }).WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runUnused(pass *analysis.Pass, cfg *config.UnusedSettings) []goanalysis.Issue { +func runUnused(pass *analysis.Pass, cfg *config.UnusedSettings) []*goanalysis.Issue { res := getUnusedResults(pass, cfg) used := make(map[string]bool) @@ -58,7 +58,7 @@ func runUnused(pass *analysis.Pass, cfg *config.UnusedSettings) []goanalysis.Iss used[fmt.Sprintf("%s %d %s", obj.Position.Filename, obj.Position.Line, obj.Name)] = true } - var issues []goanalysis.Issue + var issues []*goanalysis.Issue // Inspired by https://github.com/dominikh/go-tools/blob/d694aadcb1f50c2d8ac0a1dd06217ebb9f654764/lintcmd/lint.go#L177-L197 for _, object := range res.Unused { diff --git a/pkg/lint/linter/linter.go b/pkg/lint/linter/linter.go index 7f68545cf159..e6b484efbb05 100644 --- a/pkg/lint/linter/linter.go +++ b/pkg/lint/linter/linter.go @@ -8,7 +8,7 @@ import ( ) type Linter interface { - Run(ctx context.Context, lintCtx *Context) ([]result.Issue, error) + Run(ctx context.Context, lintCtx *Context) ([]*result.Issue, error) Name() string Desc() string } @@ -43,7 +43,7 @@ func NewNoopDeprecated(name string, cfg *config.Config, level DeprecationLevel) return noop } -func (n Noop) Run(_ context.Context, lintCtx *Context) ([]result.Issue, error) { +func (n Noop) Run(_ context.Context, lintCtx *Context) ([]*result.Issue, error) { if n.reason == "" { return nil, nil } diff --git a/pkg/lint/runner.go b/pkg/lint/runner.go index 5ede9b24dae5..5cc46feb101d 100644 --- a/pkg/lint/runner.go +++ b/pkg/lint/runner.go @@ -118,17 +118,17 @@ func NewRunner(log logutils.Log, cfg *config.Config, goenv *goutil.Env, }, nil } -func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]result.Issue, error) { +func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]*result.Issue, error) { sw := timeutils.NewStopwatch("linters", r.Log) defer sw.Print() var ( lintErrors error - issues []result.Issue + issues []*result.Issue ) for _, lc := range linters { - linterIssues, err := timeutils.TrackStage(sw, lc.Name(), func() ([]result.Issue, error) { + linterIssues, err := timeutils.TrackStage(sw, lc.Name(), func() ([]*result.Issue, error) { return r.runLinterSafe(ctx, r.lintCtx, lc) }) if err != nil { @@ -146,7 +146,7 @@ func (r *Runner) Run(ctx context.Context, linters []*linter.Config) ([]result.Is func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context, lc *linter.Config, -) (ret []result.Issue, err error) { +) (ret []*result.Issue, err error) { defer func() { if panicData := recover(); panicData != nil { if pe, ok := panicData.(*errorutil.PanicError); ok { @@ -185,13 +185,13 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context, return issues, nil } -func (r *Runner) processLintResults(inIssues []result.Issue) []result.Issue { +func (r *Runner) processLintResults(inIssues []*result.Issue) []*result.Issue { sw := timeutils.NewStopwatch("processing", r.Log) var issuesBefore, issuesAfter int statPerProcessor := map[string]processorStat{} - var outIssues []result.Issue + var outIssues []*result.Issue if len(inIssues) != 0 { issuesBefore += len(inIssues) outIssues = r.processIssues(inIssues, sw, statPerProcessor) @@ -225,9 +225,9 @@ func (r *Runner) printPerProcessorStat(stat map[string]processorStat) { } } -func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []result.Issue { +func (r *Runner) processIssues(issues []*result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []*result.Issue { for _, p := range r.Processors { - newIssues, err := timeutils.TrackStage(sw, p.Name(), func() ([]result.Issue, error) { + newIssues, err := timeutils.TrackStage(sw, p.Name(), func() ([]*result.Issue, error) { return p.Process(issues) }) @@ -243,7 +243,7 @@ func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, s // This is required by JSON serialization if issues == nil { - issues = []result.Issue{} + issues = []*result.Issue{} } } diff --git a/pkg/printers/checkstyle.go b/pkg/printers/checkstyle.go index 5a60554bdb62..c3869bd39d9d 100644 --- a/pkg/printers/checkstyle.go +++ b/pkg/printers/checkstyle.go @@ -37,15 +37,14 @@ func NewCheckstyle(log logutils.Log, w io.Writer) *Checkstyle { } } -func (p *Checkstyle) Print(issues []result.Issue) error { +func (p *Checkstyle) Print(issues []*result.Issue) error { out := checkstyleOutput{ Version: "5.0", } files := map[string]*checkstyleFile{} - for i := range issues { - issue := &issues[i] + for _, issue := range issues { file, ok := files[issue.FilePath()] if !ok { file = &checkstyleFile{ diff --git a/pkg/printers/checkstyle_test.go b/pkg/printers/checkstyle_test.go index f087a79b83b0..5c8781e388fb 100644 --- a/pkg/printers/checkstyle_test.go +++ b/pkg/printers/checkstyle_test.go @@ -14,7 +14,7 @@ import ( ) func TestCheckstyle_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/codeclimate.go b/pkg/printers/codeclimate.go index 872d860d3ba4..e2eded608fb9 100644 --- a/pkg/printers/codeclimate.go +++ b/pkg/printers/codeclimate.go @@ -30,12 +30,10 @@ func NewCodeClimate(log logutils.Log, w io.Writer) *CodeClimate { } } -func (p *CodeClimate) Print(issues []result.Issue) error { +func (p *CodeClimate) Print(issues []*result.Issue) error { ccIssues := make([]codeClimateIssue, 0, len(issues)) - for i := range issues { - issue := issues[i] - + for _, issue := range issues { ccIssue := codeClimateIssue{ Description: issue.Description(), CheckName: issue.FromLinter, diff --git a/pkg/printers/codeclimate_test.go b/pkg/printers/codeclimate_test.go index 28fd281c4548..159dd86e37ae 100644 --- a/pkg/printers/codeclimate_test.go +++ b/pkg/printers/codeclimate_test.go @@ -13,7 +13,7 @@ import ( ) func TestCodeClimate_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "minor", diff --git a/pkg/printers/html.go b/pkg/printers/html.go index 0f99bb7ff8ce..1f6ed18344b0 100644 --- a/pkg/printers/html.go +++ b/pkg/printers/html.go @@ -132,20 +132,20 @@ func NewHTML(w io.Writer) *HTML { return &HTML{w: w} } -func (p HTML) Print(issues []result.Issue) error { +func (p HTML) Print(issues []*result.Issue) error { var htmlIssues []htmlIssue - for i := range issues { - pos := fmt.Sprintf("%s:%d", issues[i].FilePath(), issues[i].Line()) - if issues[i].Pos.Column != 0 { - pos += fmt.Sprintf(":%d", issues[i].Pos.Column) + for _, issue := range issues { + pos := fmt.Sprintf("%s:%d", issue.FilePath(), issue.Line()) + if issue.Pos.Column != 0 { + pos += fmt.Sprintf(":%d", issue.Pos.Column) } htmlIssues = append(htmlIssues, htmlIssue{ - Title: strings.TrimSpace(issues[i].Text), + Title: strings.TrimSpace(issue.Text), Pos: pos, - Linter: issues[i].FromLinter, - Code: strings.Join(issues[i].SourceLines, "\n"), + Linter: issue.FromLinter, + Code: strings.Join(issue.SourceLines, "\n"), }) } diff --git a/pkg/printers/html_test.go b/pkg/printers/html_test.go index 3964d81ddeaf..17db307509c2 100644 --- a/pkg/printers/html_test.go +++ b/pkg/printers/html_test.go @@ -118,7 +118,7 @@ const expectedHTML = ` ` func TestHTML_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/json.go b/pkg/printers/json.go index 64fd33c7bae5..97354081c903 100644 --- a/pkg/printers/json.go +++ b/pkg/printers/json.go @@ -22,17 +22,17 @@ func NewJSON(w io.Writer, rd *report.Data) *JSON { } type JSONResult struct { - Issues []result.Issue + Issues []*result.Issue Report *report.Data } -func (p JSON) Print(issues []result.Issue) error { +func (p JSON) Print(issues []*result.Issue) error { res := JSONResult{ Issues: issues, Report: p.rd, } if res.Issues == nil { - res.Issues = []result.Issue{} + res.Issues = []*result.Issue{} } return json.NewEncoder(p.w).Encode(res) diff --git a/pkg/printers/json_test.go b/pkg/printers/json_test.go index 001c283ee611..50c67f995fe1 100644 --- a/pkg/printers/json_test.go +++ b/pkg/printers/json_test.go @@ -12,7 +12,7 @@ import ( ) func TestJSON_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/junitxml.go b/pkg/printers/junitxml.go index 708f83e5a860..b040e746703c 100644 --- a/pkg/printers/junitxml.go +++ b/pkg/printers/junitxml.go @@ -27,31 +27,30 @@ func NewJUnitXML(w io.Writer, extended bool) *JUnitXML { } } -func (p JUnitXML) Print(issues []result.Issue) error { +func (p JUnitXML) Print(issues []*result.Issue) error { suites := make(map[string]testSuiteXML) // use a map to group by file - for ind := range issues { - i := &issues[ind] - suiteName := i.FilePath() + for _, issue := range issues { + suiteName := issue.FilePath() testSuite := suites[suiteName] - testSuite.Suite = i.FilePath() + testSuite.Suite = issue.FilePath() testSuite.Tests++ testSuite.Failures++ tc := testCaseXML{ - Name: i.FromLinter, - ClassName: i.Pos.String(), + Name: issue.FromLinter, + ClassName: issue.Pos.String(), Failure: failureXML{ - Type: i.Severity, - Message: i.Pos.String() + ": " + i.Text, + Type: issue.Severity, + Message: issue.Pos.String() + ": " + issue.Text, Content: fmt.Sprintf("%s: %s\nCategory: %s\nFile: %s\nLine: %d\nDetails: %s", - i.Severity, i.Text, i.FromLinter, i.Pos.Filename, i.Pos.Line, strings.Join(i.SourceLines, "\n")), + issue.Severity, issue.Text, issue.FromLinter, issue.Pos.Filename, issue.Pos.Line, strings.Join(issue.SourceLines, "\n")), }, } if p.extended { - tc.File = i.Pos.Filename - tc.Line = i.Pos.Line + tc.File = issue.Pos.Filename + tc.Line = issue.Pos.Line } testSuite.TestCases = append(testSuite.TestCases, tc) diff --git a/pkg/printers/junitxml_test.go b/pkg/printers/junitxml_test.go index 7a429e546f46..90a365e79870 100644 --- a/pkg/printers/junitxml_test.go +++ b/pkg/printers/junitxml_test.go @@ -12,7 +12,7 @@ import ( ) func TestJUnitXML_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/printer.go b/pkg/printers/printer.go index 575bba75f1d5..bb3eab6205e8 100644 --- a/pkg/printers/printer.go +++ b/pkg/printers/printer.go @@ -23,7 +23,7 @@ const ( const defaultFileMode = 0o644 type issuePrinter interface { - Print(issues []result.Issue) error + Print(issues []*result.Issue) error } // Printer prints issues. @@ -63,7 +63,7 @@ func NewPrinter(log logutils.Log, cfg *config.Formats, reportData *report.Data, // Print prints issues based on the formats defined. // //nolint:gocyclo,funlen // the complexity is related to the number of formats. -func (c *Printer) Print(issues []result.Issue) error { +func (c *Printer) Print(issues []*result.Issue) error { if c.cfg.IsEmpty() { c.cfg.Text.Path = outputStdOut } diff --git a/pkg/printers/printer_test.go b/pkg/printers/printer_test.go index 850ee94a097b..6b3737f16688 100644 --- a/pkg/printers/printer_test.go +++ b/pkg/printers/printer_test.go @@ -29,7 +29,7 @@ func unmarshalFile(t *testing.T, filename string, v any) { func TestPrinter_Print_stdout(t *testing.T) { logger := logutils.NewStderrLog("skip") - var issues []result.Issue + var issues []*result.Issue unmarshalFile(t, "in-issues.json", &issues) data := &report.Data{} @@ -86,7 +86,7 @@ func TestPrinter_Print_stdout(t *testing.T) { func TestPrinter_Print_stderr(t *testing.T) { logger := logutils.NewStderrLog("skip") - var issues []result.Issue + var issues []*result.Issue unmarshalFile(t, "in-issues.json", &issues) data := &report.Data{} @@ -122,7 +122,7 @@ func TestPrinter_Print_stderr(t *testing.T) { func TestPrinter_Print_file(t *testing.T) { logger := logutils.NewStderrLog("skip") - var issues []result.Issue + var issues []*result.Issue unmarshalFile(t, "in-issues.json", &issues) data := &report.Data{} @@ -165,7 +165,7 @@ func TestPrinter_Print_file(t *testing.T) { func TestPrinter_Print_multiple(t *testing.T) { logger := logutils.NewStderrLog("skip") - var issues []result.Issue + var issues []*result.Issue unmarshalFile(t, "in-issues.json", &issues) data := &report.Data{} diff --git a/pkg/printers/sarif.go b/pkg/printers/sarif.go index e8d8c64f7da3..e1caf179a821 100644 --- a/pkg/printers/sarif.go +++ b/pkg/printers/sarif.go @@ -36,14 +36,12 @@ func NewSarif(log logutils.Log, w io.Writer) *Sarif { } } -func (p *Sarif) Print(issues []result.Issue) error { +func (p *Sarif) Print(issues []*result.Issue) error { run := sarifRun{} run.Tool.Driver.Name = "golangci-lint" run.Results = make([]sarifResult, 0) - for i := range issues { - issue := issues[i] - + for _, issue := range issues { sr := sarifResult{ RuleID: issue.FromLinter, Level: p.sanitizer.Sanitize(issue.Severity), diff --git a/pkg/printers/sarif_test.go b/pkg/printers/sarif_test.go index f6ddf4d81f07..400bb25bed37 100644 --- a/pkg/printers/sarif_test.go +++ b/pkg/printers/sarif_test.go @@ -13,7 +13,7 @@ import ( ) func TestSarif_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/tab.go b/pkg/printers/tab.go index 0d14593e5950..8edbb05e11fe 100644 --- a/pkg/printers/tab.go +++ b/pkg/printers/tab.go @@ -40,11 +40,11 @@ func (p *Tab) SprintfColored(ca color.Attribute, format string, args ...any) str return c.Sprintf(format, args...) } -func (p *Tab) Print(issues []result.Issue) error { +func (p *Tab) Print(issues []*result.Issue) error { w := tabwriter.NewWriter(p.w, 0, 0, 2, ' ', 0) - for i := range issues { - p.printIssue(&issues[i], w) + for _, issue := range issues { + p.printIssue(issue, w) } if err := w.Flush(); err != nil { diff --git a/pkg/printers/tab_test.go b/pkg/printers/tab_test.go index f8e47f84b2b1..1920334753e8 100644 --- a/pkg/printers/tab_test.go +++ b/pkg/printers/tab_test.go @@ -22,7 +22,7 @@ func TestTab_Print(t *testing.T) { }) color.NoColor = false - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/printers/teamcity.go b/pkg/printers/teamcity.go index a85307729d05..36114fedfc57 100644 --- a/pkg/printers/teamcity.go +++ b/pkg/printers/teamcity.go @@ -48,12 +48,10 @@ func NewTeamCity(log logutils.Log, w io.Writer) *TeamCity { } } -func (p *TeamCity) Print(issues []result.Issue) error { +func (p *TeamCity) Print(issues []*result.Issue) error { uniqLinters := map[string]struct{}{} - for i := range issues { - issue := issues[i] - + for _, issue := range issues { _, ok := uniqLinters[issue.FromLinter] if !ok { inspectionType := InspectionType{ diff --git a/pkg/printers/teamcity_test.go b/pkg/printers/teamcity_test.go index eda415670273..121a0519eb48 100644 --- a/pkg/printers/teamcity_test.go +++ b/pkg/printers/teamcity_test.go @@ -13,7 +13,7 @@ import ( ) func TestTeamCity_Print(t *testing.T) { - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "WARNING", diff --git a/pkg/printers/text.go b/pkg/printers/text.go index 545679fb7b45..eb9297615be2 100644 --- a/pkg/printers/text.go +++ b/pkg/printers/text.go @@ -42,16 +42,16 @@ func (p *Text) SprintfColored(ca color.Attribute, format string, args ...any) st return c.Sprintf(format, args...) } -func (p *Text) Print(issues []result.Issue) error { - for i := range issues { - p.printIssue(&issues[i]) +func (p *Text) Print(issues []*result.Issue) error { + for _, issue := range issues { + p.printIssue(issue) if !p.printIssuedLine { continue } - p.printSourceCode(&issues[i]) - p.printUnderLinePointer(&issues[i]) + p.printSourceCode(issue) + p.printUnderLinePointer(issue) } return nil diff --git a/pkg/printers/text_test.go b/pkg/printers/text_test.go index 4a1c39483526..4aa784ee4457 100644 --- a/pkg/printers/text_test.go +++ b/pkg/printers/text_test.go @@ -22,7 +22,7 @@ func TestText_Print(t *testing.T) { }) color.NoColor = false - issues := []result.Issue{ + issues := []*result.Issue{ { FromLinter: "linter-a", Severity: "warning", diff --git a/pkg/result/issue.go b/pkg/result/issue.go index 86a4ef3b7369..2587ffff2cc7 100644 --- a/pkg/result/issue.go +++ b/pkg/result/issue.go @@ -32,7 +32,7 @@ type Issue struct { // HunkPos is used only when golangci-lint is run over a diff HunkPos int `json:",omitempty"` - // If we know how to fix the issue we can provide replacement lines + // If we know how to fix the issue, we can provide replacement lines SuggestedFixes []analysis.SuggestedFix `json:",omitempty"` // If we are expecting a nolint (because this is from nolintlint), record the expected linter @@ -42,7 +42,7 @@ type Issue struct { // Only for Diff processor needs. WorkingDirectoryRelativePath string `json:"-"` - // Only for processor that need relative paths evaluation. + // Only for processors that need relative paths evaluation. RelativePath string `json:"-"` } diff --git a/pkg/result/processors/cgo.go b/pkg/result/processors/cgo.go index dea3801e2c8a..4cc7b57dbf05 100644 --- a/pkg/result/processors/cgo.go +++ b/pkg/result/processors/cgo.go @@ -31,7 +31,7 @@ func (*Cgo) Name() string { return "cgo" } -func (p *Cgo) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *Cgo) Process(issues []*result.Issue) ([]*result.Issue, error) { return filterIssuesErr(issues, p.shouldPassIssue) } diff --git a/pkg/result/processors/diff.go b/pkg/result/processors/diff.go index a84caf7b686a..15574ff0d374 100644 --- a/pkg/result/processors/diff.go +++ b/pkg/result/processors/diff.go @@ -48,7 +48,7 @@ func (*Diff) Name() string { return "diff" } -func (p *Diff) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *Diff) Process(issues []*result.Issue) ([]*result.Issue, error) { if !p.onlyNew && p.fromRev == "" && p.fromMergeBase == "" && p.patchFilePath == "" && p.patch == "" { return issues, nil } diff --git a/pkg/result/processors/exclusion_generated_file_filter.go b/pkg/result/processors/exclusion_generated_file_filter.go index 6cbde3aedf58..d76ec3184f86 100644 --- a/pkg/result/processors/exclusion_generated_file_filter.go +++ b/pkg/result/processors/exclusion_generated_file_filter.go @@ -40,7 +40,7 @@ func (*GeneratedFileFilter) Name() string { return "generated_file_filter" } -func (p *GeneratedFileFilter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *GeneratedFileFilter) Process(issues []*result.Issue) ([]*result.Issue, error) { if p.mode == config.GeneratedModeDisable { return issues, nil } diff --git a/pkg/result/processors/exclusion_paths.go b/pkg/result/processors/exclusion_paths.go index 90c5f522f8bd..acf13edd0797 100644 --- a/pkg/result/processors/exclusion_paths.go +++ b/pkg/result/processors/exclusion_paths.go @@ -68,7 +68,7 @@ func (*ExclusionPaths) Name() string { return "exclusion_paths" } -func (p *ExclusionPaths) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *ExclusionPaths) Process(issues []*result.Issue) ([]*result.Issue, error) { if len(p.pathPatterns) == 0 && len(p.pathExceptPatterns) == 0 { return issues, nil } diff --git a/pkg/result/processors/exclusion_paths_test.go b/pkg/result/processors/exclusion_paths_test.go index deac410ab366..bfd19af13e65 100644 --- a/pkg/result/processors/exclusion_paths_test.go +++ b/pkg/result/processors/exclusion_paths_test.go @@ -19,22 +19,22 @@ func TestExclusionPaths_Process(t *testing.T) { testCases := []struct { desc string cfg *config.LinterExclusions - issues []result.Issue - expected []result.Issue + issues []*result.Issue + expected []*result.Issue }{ { desc: "paths: word", cfg: &config.LinterExclusions{ Paths: []string{"foo"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: "foo.go"}, {RelativePath: "foo/foo.go"}, {RelativePath: "foo/bar.go"}, {RelativePath: "bar/foo.go"}, {RelativePath: "bar/bar.go"}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: "bar/bar.go"}, }, }, @@ -43,14 +43,14 @@ func TestExclusionPaths_Process(t *testing.T) { cfg: &config.LinterExclusions{ Paths: []string{"^foo"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("foo.go")}, {RelativePath: filepath.FromSlash("foo/foo.go")}, {RelativePath: filepath.FromSlash("foo/bar.go")}, {RelativePath: filepath.FromSlash("bar/foo.go")}, {RelativePath: filepath.FromSlash("bar/bar.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("bar/foo.go")}, {RelativePath: filepath.FromSlash("bar/bar.go")}, }, @@ -60,14 +60,14 @@ func TestExclusionPaths_Process(t *testing.T) { cfg: &config.LinterExclusions{ Paths: []string{"^foo/"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("foo.go")}, {RelativePath: filepath.FromSlash("foo/foo.go")}, {RelativePath: filepath.FromSlash("foo/bar.go")}, {RelativePath: filepath.FromSlash("bar/foo.go")}, {RelativePath: filepath.FromSlash("bar/bar.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("foo.go")}, {RelativePath: filepath.FromSlash("bar/foo.go")}, {RelativePath: filepath.FromSlash("bar/bar.go")}, @@ -78,22 +78,22 @@ func TestExclusionPaths_Process(t *testing.T) { cfg: &config.LinterExclusions{ Paths: []string{"c/d.go"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, {RelativePath: filepath.FromSlash("c/d.go")}, }, - expected: []result.Issue{}, + expected: []*result.Issue{}, }, { desc: "paths: same suffix with constrained expression", cfg: &config.LinterExclusions{ Paths: []string{"^c/d.go"}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, {RelativePath: filepath.FromSlash("c/d.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, }, }, @@ -106,11 +106,11 @@ func TestExclusionPaths_Process(t *testing.T) { `^c/d.go`, }, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, {RelativePath: filepath.FromSlash("c/d.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("a/b/c/d.go")}, }, }, @@ -119,7 +119,7 @@ func TestExclusionPaths_Process(t *testing.T) { cfg: &config.LinterExclusions{ PathsExcept: []string{`^base/c/.*$`}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, {RelativePath: filepath.FromSlash("base/b/file.go")}, {RelativePath: filepath.FromSlash("base/c/file.go")}, @@ -127,7 +127,7 @@ func TestExclusionPaths_Process(t *testing.T) { {RelativePath: filepath.FromSlash("base/c/b/file.go")}, {RelativePath: filepath.FromSlash("base/d/file.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("base/c/file.go")}, {RelativePath: filepath.FromSlash("base/c/a/file.go")}, {RelativePath: filepath.FromSlash("base/c/b/file.go")}, @@ -142,7 +142,7 @@ func TestExclusionPaths_Process(t *testing.T) { `^base/c/.*$`, }, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, {RelativePath: filepath.FromSlash("base/b/file.go")}, {RelativePath: filepath.FromSlash("base/c/file.go")}, @@ -150,7 +150,7 @@ func TestExclusionPaths_Process(t *testing.T) { {RelativePath: filepath.FromSlash("base/c/b/file.go")}, {RelativePath: filepath.FromSlash("base/d/file.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("base/c/file.go")}, {RelativePath: filepath.FromSlash("base/c/a/file.go")}, {RelativePath: filepath.FromSlash("base/c/b/file.go")}, @@ -164,7 +164,7 @@ func TestExclusionPaths_Process(t *testing.T) { `^base/c/.*$`, }, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, {RelativePath: filepath.FromSlash("base/b/file.go")}, {RelativePath: filepath.FromSlash("base/c/file.go")}, @@ -173,7 +173,7 @@ func TestExclusionPaths_Process(t *testing.T) { {RelativePath: filepath.FromSlash("base/d/file.go")}, {RelativePath: filepath.FromSlash("base/e/file.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("base/c/file.go")}, {RelativePath: filepath.FromSlash("base/c/a/file.go")}, {RelativePath: filepath.FromSlash("base/c/b/file.go")}, @@ -186,7 +186,7 @@ func TestExclusionPaths_Process(t *testing.T) { Paths: []string{"^base/b/"}, PathsExcept: []string{`^base/c/.*$`}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, {RelativePath: filepath.FromSlash("base/b/file.go")}, {RelativePath: filepath.FromSlash("base/c/file.go")}, @@ -194,7 +194,7 @@ func TestExclusionPaths_Process(t *testing.T) { {RelativePath: filepath.FromSlash("base/c/b/file.go")}, {RelativePath: filepath.FromSlash("base/d/file.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("base/c/file.go")}, {RelativePath: filepath.FromSlash("base/c/a/file.go")}, {RelativePath: filepath.FromSlash("base/c/b/file.go")}, @@ -206,7 +206,7 @@ func TestExclusionPaths_Process(t *testing.T) { Paths: []string{"^base/c/a/"}, PathsExcept: []string{`^base/c/.*$`}, }, - issues: []result.Issue{ + issues: []*result.Issue{ {RelativePath: filepath.FromSlash("base/a/file.go")}, {RelativePath: filepath.FromSlash("base/b/file.go")}, {RelativePath: filepath.FromSlash("base/c/file.go")}, @@ -214,7 +214,7 @@ func TestExclusionPaths_Process(t *testing.T) { {RelativePath: filepath.FromSlash("base/c/b/file.go")}, {RelativePath: filepath.FromSlash("base/d/file.go")}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {RelativePath: filepath.FromSlash("base/c/file.go")}, {RelativePath: filepath.FromSlash("base/c/b/file.go")}, }, diff --git a/pkg/result/processors/exclusion_rules.go b/pkg/result/processors/exclusion_rules.go index 064921ae607a..2b5221a89085 100644 --- a/pkg/result/processors/exclusion_rules.go +++ b/pkg/result/processors/exclusion_rules.go @@ -49,7 +49,7 @@ func (*ExclusionRules) Name() string { return "exclusion_rules" } -func (p *ExclusionRules) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *ExclusionRules) Process(issues []*result.Issue) ([]*result.Issue, error) { if len(p.rules) == 0 { return issues, nil } diff --git a/pkg/result/processors/exclusion_rules_test.go b/pkg/result/processors/exclusion_rules_test.go index 5657f45ed7a3..6f78ee2d2b3e 100644 --- a/pkg/result/processors/exclusion_rules_test.go +++ b/pkg/result/processors/exclusion_rules_test.go @@ -63,7 +63,7 @@ func TestExclusionRules_Process_multiple(t *testing.T) { {Path: filepath.FromSlash("testdata/exclusion_rules/exclusion_rules.go"), Line: 3, Linter: "lll"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } @@ -105,9 +105,9 @@ func TestExclusionRules_Process_text(t *testing.T) { p := NewExclusionRules(nil, lines, cfg) texts := []string{"exclude", "1", "", "exclud", "notexclude"} - var issues []result.Issue + var issues []*result.Issue for _, t := range texts { - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ Text: t, FromLinter: "linter", }) @@ -178,7 +178,7 @@ func TestExclusionRules_Process_caseSensitive_multiple(t *testing.T) { {Path: filepath.FromSlash("testdata/exclusion_rules/case_sensitive.go"), Line: 3, Linter: "lll"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } @@ -225,9 +225,9 @@ func TestExclusionRules_Process_caseSensitive_text(t *testing.T) { texts := []string{"exclude", "excLude", "1", "", "exclud", "notexclude"} - var issues []result.Issue + var issues []*result.Issue for _, t := range texts { - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ Text: t, FromLinter: "linter", }) diff --git a/pkg/result/processors/filename_unadjuster.go b/pkg/result/processors/filename_unadjuster.go index a3cdd8e6ed7c..e39601d5a4a4 100644 --- a/pkg/result/processors/filename_unadjuster.go +++ b/pkg/result/processors/filename_unadjuster.go @@ -66,7 +66,7 @@ func (*FilenameUnadjuster) Name() string { return "filename_unadjuster" } -func (p *FilenameUnadjuster) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *FilenameUnadjuster) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, func(issue *result.Issue) *result.Issue { mapper := p.m[issue.FilePath()] if mapper == nil { diff --git a/pkg/result/processors/fixer.go b/pkg/result/processors/fixer.go index d2beaa0ebafe..ce33b27fb276 100644 --- a/pkg/result/processors/fixer.go +++ b/pkg/result/processors/fixer.go @@ -56,14 +56,14 @@ func (Fixer) Name() string { return "fixer" } -func (p Fixer) Process(issues []result.Issue) ([]result.Issue, error) { +func (p Fixer) Process(issues []*result.Issue) ([]*result.Issue, error) { if !p.cfg.Issues.NeedFix { return issues, nil } p.log.Infof("Applying suggested fixes") - notFixableIssues, err := timeutils.TrackStage(p.sw, "all", func() ([]result.Issue, error) { + notFixableIssues, err := timeutils.TrackStage(p.sw, "all", func() ([]*result.Issue, error) { return p.process(issues) }) if err != nil { @@ -76,13 +76,13 @@ func (p Fixer) Process(issues []result.Issue) ([]result.Issue, error) { } //nolint:funlen,gocyclo // This function should not be split. -func (p Fixer) process(issues []result.Issue) ([]result.Issue, error) { +func (p Fixer) process(issues []*result.Issue) ([]*result.Issue, error) { // filenames / linters / edits editsByLinter := make(map[string]map[string][]diff.Edit) formatters := []string{gofumpt.Name, goimports.Name, gofmt.Name, gci.Name, golines.Name, swaggo.Name} - var notFixableIssues []result.Issue + var notFixableIssues []*result.Issue toBeFormattedFiles := make(map[string]struct{}) @@ -94,7 +94,7 @@ func (p Fixer) process(issues []result.Issue) ([]result.Issue, error) { continue } - if issue.SuggestedFixes == nil || skipNoTextEdit(&issue) { + if issue.SuggestedFixes == nil || skipNoTextEdit(issue) { notFixableIssues = append(notFixableIssues, issue) continue } diff --git a/pkg/result/processors/invalid_issue.go b/pkg/result/processors/invalid_issue.go index a7f45d408333..fa1b19e82c17 100644 --- a/pkg/result/processors/invalid_issue.go +++ b/pkg/result/processors/invalid_issue.go @@ -24,7 +24,7 @@ func (InvalidIssue) Name() string { return "invalid_issue" } -func (p InvalidIssue) Process(issues []result.Issue) ([]result.Issue, error) { +func (p InvalidIssue) Process(issues []*result.Issue) ([]*result.Issue, error) { tcIssues := filterIssuesUnsafe(issues, func(issue *result.Issue) bool { return issue.FromLinter == typeCheckName }) diff --git a/pkg/result/processors/invalid_issue_test.go b/pkg/result/processors/invalid_issue_test.go index 32628c336d31..c685551a9673 100644 --- a/pkg/result/processors/invalid_issue_test.go +++ b/pkg/result/processors/invalid_issue_test.go @@ -19,21 +19,21 @@ func TestInvalidIssue_Process(t *testing.T) { testCases := []struct { desc string - issues []result.Issue - expected []result.Issue + issues []*result.Issue + expected []*result.Issue }{ { desc: "typecheck", - issues: []result.Issue{ + issues: []*result.Issue{ {FromLinter: "typecheck"}, }, - expected: []result.Issue{ + expected: []*result.Issue{ {FromLinter: "typecheck"}, }, }, { desc: "keep only typecheck issues if any exist", - issues: []result.Issue{ + issues: []*result.Issue{ {FromLinter: "typecheck"}, { FromLinter: "example", @@ -42,13 +42,13 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{ + expected: []*result.Issue{ {FromLinter: "typecheck"}, }, }, { desc: "Go file", - issues: []result.Issue{ + issues: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -56,7 +56,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -67,7 +67,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, { desc: "go.mod", - issues: []result.Issue{ + issues: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -75,7 +75,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{ + expected: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -86,7 +86,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, { desc: "non Go file", - issues: []result.Issue{ + issues: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -94,11 +94,11 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{}, + expected: []*result.Issue{}, }, { desc: "no filename", - issues: []result.Issue{ + issues: []*result.Issue{ { FromLinter: "example", Pos: token.Position{ @@ -106,7 +106,7 @@ func TestInvalidIssue_Process(t *testing.T) { }, }, }, - expected: []result.Issue{}, + expected: []*result.Issue{}, }, } diff --git a/pkg/result/processors/issues.go b/pkg/result/processors/issues.go index 1e76291c77a1..cc4deeb5267e 100644 --- a/pkg/result/processors/issues.go +++ b/pkg/result/processors/issues.go @@ -6,62 +6,62 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func filterIssues(issues []result.Issue, filter func(issue *result.Issue) bool) []result.Issue { - retIssues := make([]result.Issue, 0, len(issues)) - for i := range issues { - if issues[i].FromLinter == typeCheckName { +func filterIssues(issues []*result.Issue, filter func(issue *result.Issue) bool) []*result.Issue { + retIssues := make([]*result.Issue, 0, len(issues)) + for _, issue := range issues { + if issue.FromLinter == typeCheckName { // don't hide typechecking errors in generated files: users expect to see why the project isn't compiling - retIssues = append(retIssues, issues[i]) + retIssues = append(retIssues, issue) continue } - if filter(&issues[i]) { - retIssues = append(retIssues, issues[i]) + if filter(issue) { + retIssues = append(retIssues, issue) } } return retIssues } -func filterIssuesUnsafe(issues []result.Issue, filter func(issue *result.Issue) bool) []result.Issue { - retIssues := make([]result.Issue, 0, len(issues)) - for i := range issues { - if filter(&issues[i]) { - retIssues = append(retIssues, issues[i]) +func filterIssuesUnsafe(issues []*result.Issue, filter func(issue *result.Issue) bool) []*result.Issue { + retIssues := make([]*result.Issue, 0, len(issues)) + for _, issue := range issues { + if filter(issue) { + retIssues = append(retIssues, issue) } } return retIssues } -func filterIssuesErr(issues []result.Issue, filter func(issue *result.Issue) (bool, error)) ([]result.Issue, error) { - retIssues := make([]result.Issue, 0, len(issues)) - for i := range issues { - if issues[i].FromLinter == typeCheckName { +func filterIssuesErr(issues []*result.Issue, filter func(issue *result.Issue) (bool, error)) ([]*result.Issue, error) { + retIssues := make([]*result.Issue, 0, len(issues)) + for _, issue := range issues { + if issue.FromLinter == typeCheckName { // don't hide typechecking errors in generated files: users expect to see why the project isn't compiling - retIssues = append(retIssues, issues[i]) + retIssues = append(retIssues, issue) continue } - ok, err := filter(&issues[i]) + ok, err := filter(issue) if err != nil { - return nil, fmt.Errorf("can't filter issue %#v: %w", issues[i], err) + return nil, fmt.Errorf("can't filter issue %#v: %w", issue, err) } if ok { - retIssues = append(retIssues, issues[i]) + retIssues = append(retIssues, issue) } } return retIssues, nil } -func transformIssues(issues []result.Issue, transform func(issue *result.Issue) *result.Issue) []result.Issue { - retIssues := make([]result.Issue, 0, len(issues)) - for i := range issues { - newIssue := transform(&issues[i]) +func transformIssues(issues []*result.Issue, transform func(issue *result.Issue) *result.Issue) []*result.Issue { + retIssues := make([]*result.Issue, 0, len(issues)) + for _, issue := range issues { + newIssue := transform(issue) if newIssue != nil { - retIssues = append(retIssues, *newIssue) + retIssues = append(retIssues, newIssue) } } diff --git a/pkg/result/processors/max_from_linter.go b/pkg/result/processors/max_from_linter.go index dec9f3e7f13a..bc7572f2ccaf 100644 --- a/pkg/result/processors/max_from_linter.go +++ b/pkg/result/processors/max_from_linter.go @@ -29,7 +29,7 @@ func (*MaxFromLinter) Name() string { return "max_from_linter" } -func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *MaxFromLinter) Process(issues []*result.Issue) ([]*result.Issue, error) { if p.limit <= 0 { // no limit return issues, nil } diff --git a/pkg/result/processors/max_per_file_from_linter.go b/pkg/result/processors/max_per_file_from_linter.go index 2608c22e22ab..b04b92ea7a7f 100644 --- a/pkg/result/processors/max_per_file_from_linter.go +++ b/pkg/result/processors/max_per_file_from_linter.go @@ -40,7 +40,7 @@ func (*MaxPerFileFromLinter) Name() string { return "max_per_file_from_linter" } -func (p *MaxPerFileFromLinter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *MaxPerFileFromLinter) Process(issues []*result.Issue) ([]*result.Issue, error) { return filterIssuesUnsafe(issues, func(issue *result.Issue) bool { limit := p.maxPerFileFromLinterConfig[issue.FromLinter] if limit == 0 { diff --git a/pkg/result/processors/max_per_file_from_linter_test.go b/pkg/result/processors/max_per_file_from_linter_test.go index c5bc7ebc1e8b..a886b47c75f0 100644 --- a/pkg/result/processors/max_per_file_from_linter_test.go +++ b/pkg/result/processors/max_per_file_from_linter_test.go @@ -7,8 +7,8 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func newFromLinterIssue(linterName string) result.Issue { - return result.Issue{ +func newFromLinterIssue(linterName string) *result.Issue { + return &result.Issue{ FromLinter: linterName, } } diff --git a/pkg/result/processors/max_same_issues.go b/pkg/result/processors/max_same_issues.go index 06e87586e171..ba22cf31fb62 100644 --- a/pkg/result/processors/max_same_issues.go +++ b/pkg/result/processors/max_same_issues.go @@ -31,7 +31,7 @@ func (*MaxSameIssues) Name() string { return "max_same_issues" } -func (p *MaxSameIssues) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *MaxSameIssues) Process(issues []*result.Issue) ([]*result.Issue, error) { if p.limit <= 0 { // no limit return issues, nil } diff --git a/pkg/result/processors/max_same_issues_test.go b/pkg/result/processors/max_same_issues_test.go index 574059ebbb41..8eb7de0e39a8 100644 --- a/pkg/result/processors/max_same_issues_test.go +++ b/pkg/result/processors/max_same_issues_test.go @@ -10,10 +10,10 @@ import ( func TestMaxSameIssues(t *testing.T) { p := NewMaxSameIssues(1, logutils.NewStderrLog(logutils.DebugKeyEmpty), &config.Config{}) - i1 := result.Issue{ + i1 := &result.Issue{ Text: "1", } - i2 := result.Issue{ + i2 := &result.Issue{ Text: "2", } diff --git a/pkg/result/processors/nolint_filter.go b/pkg/result/processors/nolint_filter.go index e17fd7ad2521..bd2a09abea43 100644 --- a/pkg/result/processors/nolint_filter.go +++ b/pkg/result/processors/nolint_filter.go @@ -91,7 +91,7 @@ func (*NolintFilter) Name() string { return "nolint_filter" } -func (p *NolintFilter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *NolintFilter) Process(issues []*result.Issue) ([]*result.Issue, error) { // put nolintlint issues last because we process other issues first to determine which nolint directives are unused sort.Stable(sortWithNolintlintLast(issues)) return filterIssuesErr(issues, p.shouldPassIssue) @@ -299,7 +299,7 @@ func (e *rangeExpander) Visit(node ast.Node) ast.Visitor { } // put nolintlint last -type sortWithNolintlintLast []result.Issue +type sortWithNolintlintLast []*result.Issue func (issues sortWithNolintlintLast) Len() int { return len(issues) diff --git a/pkg/result/processors/nolint_filter_test.go b/pkg/result/processors/nolint_filter_test.go index 79dc6c1ce4bb..c620875aba98 100644 --- a/pkg/result/processors/nolint_filter_test.go +++ b/pkg/result/processors/nolint_filter_test.go @@ -16,8 +16,8 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func newNolintFileIssue(line int, fromLinter string) result.Issue { - return result.Issue{ +func newNolintFileIssue(line int, fromLinter string) *result.Issue { + return &result.Issue{ Pos: token.Position{ Filename: filepath.FromSlash("testdata/nolint_filter/nolint.go"), Line: line, @@ -26,7 +26,7 @@ func newNolintFileIssue(line int, fromLinter string) result.Issue { } } -func newNolint2FileIssue(line int) result.Issue { +func newNolint2FileIssue(line int) *result.Issue { i := newNolintFileIssue(line, "errcheck") i.Pos.Filename = filepath.FromSlash("testdata/nolint_filter/nolint2.go") return i @@ -126,7 +126,7 @@ func TestTestNolintFilter_Process(t *testing.T) { func TestNolintFilter_Process_invalidLinterName(t *testing.T) { fileName := filepath.FromSlash("testdata/nolint_filter/bad_names.go") - issues := []result.Issue{ + issues := []*result.Issue{ { Pos: token.Position{ Filename: fileName, @@ -161,7 +161,7 @@ func TestNolintFilter_Process_invalidLinterName(t *testing.T) { func TestNolintFilter_Process_invalidLinterNameWithViolationOnTheSameLine(t *testing.T) { log := getMockLog() log.On("Warnf", "Found unknown linters in //nolint directives: %s", "foobar") - issues := []result.Issue{ + issues := []*result.Issue{ { Pos: token.Position{ Filename: filepath.FromSlash("testdata/nolint_filter/apply_to_unknown.go"), @@ -246,14 +246,14 @@ func TestNolintFilter_Process_wholeFile(t *testing.T) { p := newTestNolintFilter(getMockLog()) defer p.Finish() - processAssertEmpty(t, p, result.Issue{ + processAssertEmpty(t, p, &result.Issue{ Pos: token.Position{ Filename: fileName, Line: 9, }, FromLinter: "errcheck", }) - processAssertSame(t, p, result.Issue{ + processAssertSame(t, p, &result.Issue{ Pos: token.Position{ Filename: fileName, Line: 14, @@ -284,7 +284,7 @@ func TestNolintFilter_Process_unused(t *testing.T) { } // the issue below is the nolintlint issue that would be generated for the test file - nolintlintIssueMisspell := result.Issue{ + nolintlintIssueMisspell := &result.Issue{ Pos: token.Position{ Filename: fileName, Line: 3, @@ -295,7 +295,7 @@ func TestNolintFilter_Process_unused(t *testing.T) { } // the issue below is another nolintlint issue that would be generated for the test file - nolintlintIssueMisspellUnusedOK := result.Issue{ + nolintlintIssueMisspellUnusedOK := &result.Issue{ Pos: token.Position{ Filename: fileName, Line: 5, @@ -323,7 +323,7 @@ func TestNolintFilter_Process_unused(t *testing.T) { p := createProcessor(t, log, []string{"misspell", "nolintlint"}) defer p.Finish() - processAssertEmpty(t, p, []result.Issue{{ + processAssertEmpty(t, p, []*result.Issue{{ Pos: token.Position{ Filename: fileName, Line: 3, diff --git a/pkg/result/processors/path_absoluter.go b/pkg/result/processors/path_absoluter.go index 99f3de42a2cd..240cedf8eaf4 100644 --- a/pkg/result/processors/path_absoluter.go +++ b/pkg/result/processors/path_absoluter.go @@ -22,7 +22,7 @@ func (*PathAbsoluter) Name() string { return "path_absoluter" } -func (p *PathAbsoluter) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *PathAbsoluter) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, func(issue *result.Issue) *result.Issue { if filepath.IsAbs(issue.FilePath()) { return issue diff --git a/pkg/result/processors/path_prettifier.go b/pkg/result/processors/path_prettifier.go index cb6ef8ebc27d..94dfbab370ab 100644 --- a/pkg/result/processors/path_prettifier.go +++ b/pkg/result/processors/path_prettifier.go @@ -30,7 +30,7 @@ func (*PathPrettifier) Name() string { return "path_prettifier" } -func (p *PathPrettifier) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *PathPrettifier) Process(issues []*result.Issue) ([]*result.Issue, error) { if p.cfg.PathMode == fsutils.OutputPathModeAbsolute { return issues, nil } diff --git a/pkg/result/processors/path_prettifier_test.go b/pkg/result/processors/path_prettifier_test.go index 824509712ef7..2f403d46a327 100644 --- a/pkg/result/processors/path_prettifier_test.go +++ b/pkg/result/processors/path_prettifier_test.go @@ -13,15 +13,15 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func newPPIssue(fn, rp string) result.Issue { - return result.Issue{ +func newPPIssue(fn, rp string) *result.Issue { + return &result.Issue{ Pos: token.Position{Filename: filepath.FromSlash(fn)}, RelativePath: filepath.FromSlash(rp), } } func TestPathPrettifier_Process(t *testing.T) { - paths := func(ps ...string) (issues []result.Issue) { + paths := func(ps ...string) (issues []*result.Issue) { for _, p := range ps { issues = append(issues, newPPIssue("test", p)) } @@ -30,12 +30,12 @@ func TestPathPrettifier_Process(t *testing.T) { for _, tt := range []struct { name, prefix string - issues, want []result.Issue + issues, want []*result.Issue }{ { name: "empty prefix", issues: paths("some/path", "cool"), - want: []result.Issue{ + want: []*result.Issue{ newPPIssue("some/path", "some/path"), newPPIssue("cool", "cool"), }, @@ -44,7 +44,7 @@ func TestPathPrettifier_Process(t *testing.T) { name: "prefix", prefix: "ok", issues: paths("some/path", "cool"), - want: []result.Issue{ + want: []*result.Issue{ newPPIssue("ok/some/path", "some/path"), newPPIssue("ok/cool", "cool"), }, @@ -53,7 +53,7 @@ func TestPathPrettifier_Process(t *testing.T) { name: "prefix slashed", prefix: "ok/", issues: paths("some/path", "cool"), - want: []result.Issue{ + want: []*result.Issue{ newPPIssue("ok/some/path", "some/path"), newPPIssue("ok/cool", "cool"), }, diff --git a/pkg/result/processors/path_relativity.go b/pkg/result/processors/path_relativity.go index 8b2958a4a308..c68662c7bb1f 100644 --- a/pkg/result/processors/path_relativity.go +++ b/pkg/result/processors/path_relativity.go @@ -36,7 +36,7 @@ func (*PathRelativity) Name() string { return "path_relativity" } -func (p *PathRelativity) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *PathRelativity) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, func(issue *result.Issue) *result.Issue { newIssue := *issue diff --git a/pkg/result/processors/path_shortener.go b/pkg/result/processors/path_shortener.go index 7a14c39c972e..23df4f02cc20 100644 --- a/pkg/result/processors/path_shortener.go +++ b/pkg/result/processors/path_shortener.go @@ -29,7 +29,7 @@ func (PathShortener) Name() string { return "path_shortener" } -func (p PathShortener) Process(issues []result.Issue) ([]result.Issue, error) { +func (p PathShortener) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, func(issue *result.Issue) *result.Issue { newIssue := issue newIssue.Text = strings.ReplaceAll(newIssue.Text, p.wd+"/", "") diff --git a/pkg/result/processors/processor.go b/pkg/result/processors/processor.go index 1976d6e44ad9..f5603c94dc75 100644 --- a/pkg/result/processors/processor.go +++ b/pkg/result/processors/processor.go @@ -7,7 +7,7 @@ import ( const typeCheckName = "typecheck" type Processor interface { - Process(issues []result.Issue) ([]result.Issue, error) + Process(issues []*result.Issue) ([]*result.Issue, error) Name() string Finish() } diff --git a/pkg/result/processors/processor_test.go b/pkg/result/processors/processor_test.go index 41bb78a7b3ae..95fdb5f81445 100644 --- a/pkg/result/processors/processor_test.go +++ b/pkg/result/processors/processor_test.go @@ -18,8 +18,8 @@ type issueTestCase struct { Severity string } -func newIssueFromIssueTestCase(c issueTestCase) result.Issue { - return result.Issue{ +func newIssueFromIssueTestCase(c issueTestCase) *result.Issue { + return &result.Issue{ Text: c.Text, FromLinter: c.Linter, Severity: c.Severity, @@ -31,13 +31,13 @@ func newIssueFromIssueTestCase(c issueTestCase) result.Issue { } } -func newIssueFromTextTestCase(text string) result.Issue { - return result.Issue{ +func newIssueFromTextTestCase(text string) *result.Issue { + return &result.Issue{ Text: text, } } -func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue { +func process(t *testing.T, p Processor, issues ...*result.Issue) []*result.Issue { t.Helper() processedIssues, err := p.Process(issues) @@ -45,14 +45,14 @@ func process(t *testing.T, p Processor, issues ...result.Issue) []result.Issue { return processedIssues } -func processAssertSame(t *testing.T, p Processor, issues ...result.Issue) { +func processAssertSame(t *testing.T, p Processor, issues ...*result.Issue) { t.Helper() processedIssues := process(t, p, issues...) assert.Equal(t, issues, processedIssues) } -func processAssertEmpty(t *testing.T, p Processor, issues ...result.Issue) { +func processAssertEmpty(t *testing.T, p Processor, issues ...*result.Issue) { t.Helper() processedIssues := process(t, p, issues...) diff --git a/pkg/result/processors/severity.go b/pkg/result/processors/severity.go index 035ca80c4e1d..33c3997f8889 100644 --- a/pkg/result/processors/severity.go +++ b/pkg/result/processors/severity.go @@ -43,7 +43,7 @@ func NewSeverity(log logutils.Log, lines *fsutils.LineCache, cfg *config.Severit func (p *Severity) Name() string { return p.name } -func (p *Severity) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *Severity) Process(issues []*result.Issue) ([]*result.Issue, error) { if len(p.rules) == 0 && p.defaultSeverity == "" { return issues, nil } diff --git a/pkg/result/processors/severity_test.go b/pkg/result/processors/severity_test.go index 0774f0b1d517..a5c50d0011cc 100644 --- a/pkg/result/processors/severity_test.go +++ b/pkg/result/processors/severity_test.go @@ -92,7 +92,7 @@ func TestSeverity_multiple(t *testing.T) { {Path: "empty.go", Text: "empty", Linter: "empty"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } @@ -141,9 +141,9 @@ func TestSeverity_text(t *testing.T) { p := NewSeverity(nil, nil, opts) texts := []string{"seveRity", "1", "", "serverit", "notseverity"} - var issues []result.Issue + var issues []*result.Issue for _, t := range texts { - issues = append(issues, result.Issue{ + issues = append(issues, &result.Issue{ Text: t, FromLinter: "linter", }) @@ -176,7 +176,7 @@ func TestSeverity_onlyDefault(t *testing.T) { {Path: "empty.go", Text: "empty", Linter: "empty"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } @@ -230,7 +230,7 @@ func TestSeverity_caseSensitive(t *testing.T) { {Path: "e.go", Text: "ssL", Linter: "gosec"}, } - var issues []result.Issue + var issues []*result.Issue for _, c := range cases { issues = append(issues, newIssueFromIssueTestCase(c)) } diff --git a/pkg/result/processors/sort_results.go b/pkg/result/processors/sort_results.go index 033eca9a4374..8ba06bccfd10 100644 --- a/pkg/result/processors/sort_results.go +++ b/pkg/result/processors/sort_results.go @@ -54,7 +54,7 @@ func NewSortResults(cfg *config.Output) *SortResults { func (SortResults) Name() string { return "sort_results" } // Process is performing sorting of the result issues. -func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) { +func (p SortResults) Process(issues []*result.Issue) ([]*result.Issue, error) { if len(p.cfg.SortOrder) == 0 { p.cfg.SortOrder = []string{orderNameLinter, orderNameFile} } @@ -72,8 +72,8 @@ func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) { comp := mergeComparators(cmps...) - slices.SortFunc(issues, func(a, b result.Issue) int { - return comp(&a, &b) + slices.SortFunc(issues, func(a, b *result.Issue) int { + return comp(a, b) }) return issues, nil diff --git a/pkg/result/processors/sort_results_test.go b/pkg/result/processors/sort_results_test.go index fcfd824c8eb1..dc097cc967de 100644 --- a/pkg/result/processors/sort_results_test.go +++ b/pkg/result/processors/sort_results_test.go @@ -12,7 +12,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -var issues = []result.Issue{ +var issues = []*result.Issue{ { FromLinter: "b", Severity: "medium", @@ -50,7 +50,7 @@ var issues = []result.Issue{ }, } -var extraSeverityIssues = []result.Issue{ +var extraSeverityIssues = []*result.Issue{ { FromLinter: "c", Severity: "error", @@ -72,16 +72,16 @@ var extraSeverityIssues = []result.Issue{ } type compareTestCase struct { - a, b result.Issue + a, b *result.Issue expected int } func testCompareValues(t *testing.T, cmp issueComparator, name string, tests []compareTestCase) { - for i, test := range tests { //nolint:gocritic // To ignore rangeValCopy rule + for i, test := range tests { t.Run(fmt.Sprintf("%s(%d)", name, i), func(t *testing.T) { t.Parallel() - res := cmp(&test.a, &test.b) + res := cmp(test.a, test.b) assert.Equal(t, compToString(test.expected), compToString(res)) }) @@ -210,7 +210,7 @@ func Test_numericCompare(t *testing.T) { } func TestSortResults_Process(t *testing.T) { - tests := make([]result.Issue, len(issues)) + tests := make([]*result.Issue, len(issues)) copy(tests, issues) cfg := &config.Output{} @@ -219,7 +219,7 @@ func TestSortResults_Process(t *testing.T) { results, err := sr.Process(tests) require.NoError(t, err) - assert.Equal(t, []result.Issue{issues[1], issues[0], issues[3], issues[2]}, results) + assert.Equal(t, []*result.Issue{issues[1], issues[0], issues[3], issues[2]}, results) } func compToString(c int) string { diff --git a/pkg/result/processors/source_code.go b/pkg/result/processors/source_code.go index 1096269c8176..d4e82643c0d9 100644 --- a/pkg/result/processors/source_code.go +++ b/pkg/result/processors/source_code.go @@ -31,7 +31,7 @@ func (SourceCode) Name() string { return "source_code" } -func (p SourceCode) Process(issues []result.Issue) ([]result.Issue, error) { +func (p SourceCode) Process(issues []*result.Issue) ([]*result.Issue, error) { return transformIssues(issues, p.transform), nil } diff --git a/pkg/result/processors/uniq_by_line.go b/pkg/result/processors/uniq_by_line.go index 113b5814ad16..953496355b09 100644 --- a/pkg/result/processors/uniq_by_line.go +++ b/pkg/result/processors/uniq_by_line.go @@ -25,7 +25,7 @@ func (*UniqByLine) Name() string { return "uniq_by_line" } -func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) { +func (p *UniqByLine) Process(issues []*result.Issue) ([]*result.Issue, error) { if !p.enabled { return issues, nil } diff --git a/pkg/result/processors/uniq_by_line_test.go b/pkg/result/processors/uniq_by_line_test.go index dadca6a9afa1..d623c2e62569 100644 --- a/pkg/result/processors/uniq_by_line_test.go +++ b/pkg/result/processors/uniq_by_line_test.go @@ -7,8 +7,8 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/result" ) -func newULIssue(file string, line int) result.Issue { - return result.Issue{ +func newULIssue(file string, line int) *result.Issue { + return &result.Issue{ Pos: token.Position{ Filename: file, Line: line, diff --git a/scripts/website/expand_templates/thanks_test.go b/scripts/website/expand_templates/thanks_test.go index 6af152336e99..7caa7e28c49f 100644 --- a/scripts/website/expand_templates/thanks_test.go +++ b/scripts/website/expand_templates/thanks_test.go @@ -14,7 +14,7 @@ type FakeLinter struct { name string } -func (*FakeLinter) Run(_ context.Context, _ *linter.Context) ([]result.Issue, error) { +func (*FakeLinter) Run(_ context.Context, _ *linter.Context) ([]*result.Issue, error) { return nil, nil }