Skip to content

feat: add new issues.new-from-merge-base option #5362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4043,6 +4043,10 @@ issues:
# Default: false
new: true

# Show only new issues created after the best common ancestor (merge-base against HEAD).
# Default: ""
new-from-merge-base: main

# Show only new issues created after git revision `REV`.
# Default: ""
new-from-rev: HEAD
Expand Down
15 changes: 9 additions & 6 deletions docs/src/docs/welcome/faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,20 @@ Or you can create a [GitHub Issue](https://github.com/golangci/golangci-lint/iss

We are sure that every project can easily integrate `golangci-lint`, even the large one.

The idea is to not fix all existing issues. Fix only newly added issue: issues in new code.
To do this setup CI to run `golangci-lint` with option `--new-from-rev=HEAD~1`.
The idea is to not fix all existing issues.
Fix only newly added issue: issues in new code.

Also, take a look at option `--new`, but consider that CI scripts that generate unstaged files will make `--new` only point out issues in those files and not in the last commit.
In that regard `--new-from-rev=HEAD~1` is safer.
To do this setup CI to run `golangci-lint` with options `--new-from-merge-base=main` or `--new-from-rev=HEAD~1`.

Also, take a look at option `--new`,
but consider that CI scripts that generate unstaged files will make `--new` only point out issues in those files and not in the last commit.
In that regard `--new-from-merge-base=main` or `--new-from-rev=HEAD~1` are safer.

By doing this you won't create new issues in your code and can choose fix existing issues (or not).

## Why `--new-from-rev` or `--new-from-patch` don't seem to be working in some cases?
## Why `--new-from-xxx` don't seem to be working in some cases?

The options `--new-from-rev` and `--new-from-patch` work by comparing `git diff` output and issues.
The options `--new-from-merge-base`, `--new-from-rev`, and `--new-from-patch` work by comparing `git diff` output and issues.

If an issue is not reported as the same line as the changes then the issue will be skipped.
This is the line of the issue is not inside the lines changed.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ require (
github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d
github.com/golangci/misspell v0.6.0
github.com/golangci/plugin-module-register v0.1.1
github.com/golangci/revgrep v0.7.0
github.com/golangci/revgrep v0.8.0
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed
github.com/gordonklaus/ineffassign v0.1.0
github.com/gostaticanalysis/forcetypeassert v0.1.0
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.

4 changes: 4 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4081,6 +4081,10 @@
"type": "boolean",
"default": false
},
"new-from-merge-base": {
"description": "Show only new issues created after the best common ancestor (merge-base against HEAD).",
"type": "string"
},
"new-from-rev": {
"description": "Show only new issues created after this git revision.",
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions pkg/config/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type Issues struct {
UniqByLine bool `mapstructure:"uniq-by-line"`

DiffFromRevision string `mapstructure:"new-from-rev"`
DiffFromMergeBase string `mapstructure:"new-from-merge-base"`
DiffPatchFilePath string `mapstructure:"new-from-patch"`
WholeFiles bool `mapstructure:"whole-files"`
Diff bool `mapstructure:"new"`
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 @@ -27,6 +27,7 @@ var _ Processor = (*Diff)(nil)
type Diff struct {
onlyNew bool
fromRev string
fromMergeBase string
patchFilePath string
wholeFiles bool
patch string
Expand All @@ -36,6 +37,7 @@ func NewDiff(cfg *config.Issues) *Diff {
return &Diff{
onlyNew: cfg.Diff,
fromRev: cfg.DiffFromRevision,
fromMergeBase: cfg.DiffFromMergeBase,
patchFilePath: cfg.DiffPatchFilePath,
wholeFiles: cfg.WholeFiles,
patch: os.Getenv(envGolangciDiffProcessorPatch),
Expand All @@ -47,7 +49,7 @@ func (*Diff) Name() string {
}

func (p *Diff) Process(issues []result.Issue) ([]result.Issue, error) {
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" && p.patch == "" {
if !p.onlyNew && p.fromRev == "" && p.fromMergeBase == "" && p.patchFilePath == "" && p.patch == "" {
return issues, nil
}

Expand All @@ -68,6 +70,7 @@ func (p *Diff) Process(issues []result.Issue) ([]result.Issue, error) {
checker := revgrep.Checker{
Patch: patchReader,
RevisionFrom: p.fromRev,
MergeBase: p.fromMergeBase,
WholeFiles: p.wholeFiles,
}

Expand Down
Loading