Skip to content

Commit

Permalink
new-from-rev: add support for finding issues in entire files in a diff (
Browse files Browse the repository at this point in the history
  • Loading branch information
natefinch committed Sep 30, 2021
1 parent cf9f3f9 commit 9b577fc
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}

Expand Down
1 change: 1 addition & 0 deletions pkg/config/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/lint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 4 additions & 1 deletion pkg/result/processors/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9b577fc

Please sign in to comment.