From 8117f1c746c793a6b2020de34c0ad81c0f9ba7a5 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Tue, 28 Sep 2021 23:32:45 -0400 Subject: [PATCH 1/3] add support for finding issues in entire files in a diff --- pkg/commands/run.go | 2 ++ pkg/config/issues.go | 1 + pkg/lint/runner.go | 2 +- pkg/result/processors/diff.go | 5 ++++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 271fffe94f1a..5b63c66a8bb5 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.DiffWholeFiles, "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..935d82c4e405 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.DiffWholeFiles), 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) From 2ebc6fa4469601392262f1c457e03f036583b255 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Tue, 28 Sep 2021 23:34:49 -0400 Subject: [PATCH 2/3] missed a file --- pkg/commands/run.go | 2 +- pkg/lint/runner.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 5b63c66a8bb5..f2ea5415a7fe 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -233,7 +233,7 @@ 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.DiffWholeFiles, "whole-files", false, + 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/lint/runner.go b/pkg/lint/runner.go index 935d82c4e405..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, cfg.Issues.DiffWholeFiles), + 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), From 7c281414d7f18067595b45aefed3179e1bfbee50 Mon Sep 17 00:00:00 2001 From: Nate Finch Date: Thu, 30 Sep 2021 09:35:50 -0400 Subject: [PATCH 3/3] update revgrep --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 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=