From de54060f7460645d34140adf582ae3be7158e6bd Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Thu, 30 Sep 2021 12:43:31 -0400 Subject: [PATCH] new-from-rev: add support for finding issues in entire files in a diff (#2264) --- go.mod | 2 +- go.sum | 4 ++-- pkg/commands/run.go | 2 ++ pkg/config/issues.go | 1 + pkg/lint/runner.go | 2 +- pkg/result/processors/diff.go | 5 ++++- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index ca07a85d57ce..071fdcef66df 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca github.com/golangci/misspell v0.3.5 - github.com/golangci/revgrep v0.0.0-20210208091834-cd28932614b5 + github.com/golangci/revgrep v0.0.0-20210930125155-c22e5001d4f2 github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254 github.com/gostaticanalysis/forcetypeassert v0.0.0-20200621232751-01d4955beaa5 diff --git a/go.sum b/go.sum index 3adc54230420..ede140520b94 100644 --- a/go.sum +++ b/go.sum @@ -278,8 +278,8 @@ github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca h1:kNY3/svz5T29M github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca/go.mod h1:tvlJhZqDe4LMs4ZHD0oMUlt9G2LWuDGoisJTBzLMV9o= github.com/golangci/misspell v0.3.5 h1:pLzmVdl3VxTOncgzHcvLOKirdvcx/TydsClUQXTehjo= github.com/golangci/misspell v0.3.5/go.mod h1:dEbvlSfYbMQDtrpRMQU675gSDLDNa8sCPPChZ7PhiVA= -github.com/golangci/revgrep v0.0.0-20210208091834-cd28932614b5 h1:c9Mqqrm/Clj5biNaG7rABrmwUq88nHh0uABo2b/WYmc= -github.com/golangci/revgrep v0.0.0-20210208091834-cd28932614b5/go.mod h1:LK+zW4MpyytAWQRz0M4xnzEk50lSvqDQKfx304apFkY= +github.com/golangci/revgrep v0.0.0-20210930125155-c22e5001d4f2 h1:SgM7GDZTxtTTQPU84heOxy34iG5Du7F2jcoZnvp+fXI= +github.com/golangci/revgrep v0.0.0-20210930125155-c22e5001d4f2/go.mod h1:LK+zW4MpyytAWQRz0M4xnzEk50lSvqDQKfx304apFkY= github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 h1:zwtduBRr5SSWhqsYNgcuWO2kFlpdOZbP0+yRjmvPGys= github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4/go.mod h1:Izgrg8RkN3rCIMLGE9CyYmU9pY2Jer6DgANEnZ/L/cQ= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 271fffe94f1a..f2ea5415a7fe 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -233,6 +233,8 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is wh("Show only new issues created after git revision `REV`")) fs.StringVar(&ic.DiffPatchFilePath, "new-from-patch", "", wh("Show only new issues created in git patch with file path `PATH`")) + fs.BoolVar(&ic.WholeFiles, "whole-files", false, + wh("Show issues in any part of update files (requires new-from-rev or new-from-patch)")) fs.BoolVar(&ic.NeedFix, "fix", false, "Fix found issues (if it's supported by the linter)") } diff --git a/pkg/config/issues.go b/pkg/config/issues.go index 71bf2a90ef1f..0f9ac5f61d83 100644 --- a/pkg/config/issues.go +++ b/pkg/config/issues.go @@ -115,6 +115,7 @@ type Issues struct { DiffFromRevision string `mapstructure:"new-from-rev"` DiffPatchFilePath string `mapstructure:"new-from-patch"` + WholeFiles bool `mapstructure:"whole-files"` Diff bool `mapstructure:"new"` NeedFix bool `mapstructure:"fix"` diff --git a/pkg/lint/runner.go b/pkg/lint/runner.go index 8882b9300960..856eec6b6f42 100644 --- a/pkg/lint/runner.go +++ b/pkg/lint/runner.go @@ -86,7 +86,7 @@ func NewRunner(cfg *config.Config, log logutils.Log, goenv *goutil.Env, es *lint processors.NewNolint(log.Child("nolint"), dbManager, enabledLinters), processors.NewUniqByLine(cfg), - processors.NewDiff(cfg.Issues.Diff, cfg.Issues.DiffFromRevision, cfg.Issues.DiffPatchFilePath), + processors.NewDiff(cfg.Issues.Diff, cfg.Issues.DiffFromRevision, cfg.Issues.DiffPatchFilePath, cfg.Issues.WholeFiles), processors.NewMaxPerFileFromLinter(cfg), processors.NewMaxSameIssues(cfg.Issues.MaxSameIssues, log.Child("max_same_issues"), cfg), processors.NewMaxFromLinter(cfg.Issues.MaxIssuesPerLinter, log.Child("max_from_linter"), cfg), diff --git a/pkg/result/processors/diff.go b/pkg/result/processors/diff.go index fc4aba4b9398..92ab2bd5ca4c 100644 --- a/pkg/result/processors/diff.go +++ b/pkg/result/processors/diff.go @@ -17,16 +17,18 @@ type Diff struct { onlyNew bool fromRev string patchFilePath string + wholeFiles bool patch string } var _ Processor = Diff{} -func NewDiff(onlyNew bool, fromRev, patchFilePath string) *Diff { +func NewDiff(onlyNew bool, fromRev, patchFilePath string, wholeFiles bool) *Diff { return &Diff{ onlyNew: onlyNew, fromRev: fromRev, patchFilePath: patchFilePath, + wholeFiles: wholeFiles, patch: os.Getenv("GOLANGCI_DIFF_PROCESSOR_PATCH"), } } @@ -54,6 +56,7 @@ func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) { c := revgrep.Checker{ Patch: patchReader, RevisionFrom: p.fromRev, + WholeFiles: p.wholeFiles, } if err := c.Prepare(); err != nil { return nil, fmt.Errorf("can't prepare diff by revgrep: %s", err)