Skip to content

Commit de54060

Browse files
natefinchSeigeC
authored andcommitted
new-from-rev: add support for finding issues in entire files in a diff (golangci#2264)
1 parent d7d79f6 commit de54060

File tree

6 files changed

+11
-5
lines changed

6 files changed

+11
-5
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0
3232
github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca
3333
github.com/golangci/misspell v0.3.5
34-
github.com/golangci/revgrep v0.0.0-20210208091834-cd28932614b5
34+
github.com/golangci/revgrep v0.0.0-20210930125155-c22e5001d4f2
3535
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
3636
github.com/gordonklaus/ineffassign v0.0.0-20210225214923-2e10b2664254
3737
github.com/gostaticanalysis/forcetypeassert v0.0.0-20200621232751-01d4955beaa5

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/commands/run.go

+2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is
233233
wh("Show only new issues created after git revision `REV`"))
234234
fs.StringVar(&ic.DiffPatchFilePath, "new-from-patch", "",
235235
wh("Show only new issues created in git patch with file path `PATH`"))
236+
fs.BoolVar(&ic.WholeFiles, "whole-files", false,
237+
wh("Show issues in any part of update files (requires new-from-rev or new-from-patch)"))
236238
fs.BoolVar(&ic.NeedFix, "fix", false, "Fix found issues (if it's supported by the linter)")
237239
}
238240

pkg/config/issues.go

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ type Issues struct {
115115

116116
DiffFromRevision string `mapstructure:"new-from-rev"`
117117
DiffPatchFilePath string `mapstructure:"new-from-patch"`
118+
WholeFiles bool `mapstructure:"whole-files"`
118119
Diff bool `mapstructure:"new"`
119120

120121
NeedFix bool `mapstructure:"fix"`

pkg/lint/runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func NewRunner(cfg *config.Config, log logutils.Log, goenv *goutil.Env, es *lint
8686
processors.NewNolint(log.Child("nolint"), dbManager, enabledLinters),
8787

8888
processors.NewUniqByLine(cfg),
89-
processors.NewDiff(cfg.Issues.Diff, cfg.Issues.DiffFromRevision, cfg.Issues.DiffPatchFilePath),
89+
processors.NewDiff(cfg.Issues.Diff, cfg.Issues.DiffFromRevision, cfg.Issues.DiffPatchFilePath, cfg.Issues.WholeFiles),
9090
processors.NewMaxPerFileFromLinter(cfg),
9191
processors.NewMaxSameIssues(cfg.Issues.MaxSameIssues, log.Child("max_same_issues"), cfg),
9292
processors.NewMaxFromLinter(cfg.Issues.MaxIssuesPerLinter, log.Child("max_from_linter"), cfg),

pkg/result/processors/diff.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ type Diff struct {
1717
onlyNew bool
1818
fromRev string
1919
patchFilePath string
20+
wholeFiles bool
2021
patch string
2122
}
2223

2324
var _ Processor = Diff{}
2425

25-
func NewDiff(onlyNew bool, fromRev, patchFilePath string) *Diff {
26+
func NewDiff(onlyNew bool, fromRev, patchFilePath string, wholeFiles bool) *Diff {
2627
return &Diff{
2728
onlyNew: onlyNew,
2829
fromRev: fromRev,
2930
patchFilePath: patchFilePath,
31+
wholeFiles: wholeFiles,
3032
patch: os.Getenv("GOLANGCI_DIFF_PROCESSOR_PATCH"),
3133
}
3234
}
@@ -54,6 +56,7 @@ func (p Diff) Process(issues []result.Issue) ([]result.Issue, error) {
5456
c := revgrep.Checker{
5557
Patch: patchReader,
5658
RevisionFrom: p.fromRev,
59+
WholeFiles: p.wholeFiles,
5760
}
5861
if err := c.Prepare(); err != nil {
5962
return nil, fmt.Errorf("can't prepare diff by revgrep: %s", err)

0 commit comments

Comments
 (0)