Skip to content

Commit 192e98b

Browse files
authored
feat: add new issues.new-from-merge-base option (#5362)
1 parent dfd79c9 commit 192e98b

File tree

7 files changed

+25
-10
lines changed

7 files changed

+25
-10
lines changed

.golangci.next.reference.yml

+4
Original file line numberDiff line numberDiff line change
@@ -4043,6 +4043,10 @@ issues:
40434043
# Default: false
40444044
new: true
40454045

4046+
# Show only new issues created after the best common ancestor (merge-base against HEAD).
4047+
# Default: ""
4048+
new-from-merge-base: main
4049+
40464050
# Show only new issues created after git revision `REV`.
40474051
# Default: ""
40484052
new-from-rev: HEAD

docs/src/docs/welcome/faq.mdx

+9-6
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,20 @@ Or you can create a [GitHub Issue](https://github.com/golangci/golangci-lint/iss
7676

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

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

82-
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.
83-
In that regard `--new-from-rev=HEAD~1` is safer.
82+
To do this setup CI to run `golangci-lint` with options `--new-from-merge-base=main` or `--new-from-rev=HEAD~1`.
83+
84+
Also, take a look at option `--new`,
85+
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.
86+
In that regard `--new-from-merge-base=main` or `--new-from-rev=HEAD~1` are safer.
8487

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

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

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

9194
If an issue is not reported as the same line as the changes then the issue will be skipped.
9295
This is the line of the issue is not inside the lines changed.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ require (
4848
github.com/golangci/gofmt v0.0.0-20250106114630-d62b90e6713d
4949
github.com/golangci/misspell v0.6.0
5050
github.com/golangci/plugin-module-register v0.1.1
51-
github.com/golangci/revgrep v0.7.0
51+
github.com/golangci/revgrep v0.8.0
5252
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed
5353
github.com/gordonklaus/ineffassign v0.1.0
5454
github.com/gostaticanalysis/forcetypeassert v0.1.0

go.sum

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

jsonschema/golangci.next.jsonschema.json

+4
Original file line numberDiff line numberDiff line change
@@ -4081,6 +4081,10 @@
40814081
"type": "boolean",
40824082
"default": false
40834083
},
4084+
"new-from-merge-base": {
4085+
"description": "Show only new issues created after the best common ancestor (merge-base against HEAD).",
4086+
"type": "string"
4087+
},
40844088
"new-from-rev": {
40854089
"description": "Show only new issues created after this git revision.",
40864090
"type": "string"

pkg/config/issues.go

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type Issues struct {
118118
UniqByLine bool `mapstructure:"uniq-by-line"`
119119

120120
DiffFromRevision string `mapstructure:"new-from-rev"`
121+
DiffFromMergeBase string `mapstructure:"new-from-merge-base"`
121122
DiffPatchFilePath string `mapstructure:"new-from-patch"`
122123
WholeFiles bool `mapstructure:"whole-files"`
123124
Diff bool `mapstructure:"new"`

pkg/result/processors/diff.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var _ Processor = (*Diff)(nil)
2727
type Diff struct {
2828
onlyNew bool
2929
fromRev string
30+
fromMergeBase string
3031
patchFilePath string
3132
wholeFiles bool
3233
patch string
@@ -36,6 +37,7 @@ func NewDiff(cfg *config.Issues) *Diff {
3637
return &Diff{
3738
onlyNew: cfg.Diff,
3839
fromRev: cfg.DiffFromRevision,
40+
fromMergeBase: cfg.DiffFromMergeBase,
3941
patchFilePath: cfg.DiffPatchFilePath,
4042
wholeFiles: cfg.WholeFiles,
4143
patch: os.Getenv(envGolangciDiffProcessorPatch),
@@ -47,7 +49,7 @@ func (*Diff) Name() string {
4749
}
4850

4951
func (p *Diff) Process(issues []result.Issue) ([]result.Issue, error) {
50-
if !p.onlyNew && p.fromRev == "" && p.patchFilePath == "" && p.patch == "" {
52+
if !p.onlyNew && p.fromRev == "" && p.fromMergeBase == "" && p.patchFilePath == "" && p.patch == "" {
5153
return issues, nil
5254
}
5355

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

0 commit comments

Comments
 (0)