Skip to content

Commit d3eb3ed

Browse files
rskijirfag
authored andcommitted
point users to --new-from-rev=HEAD~ for CI setups in --help
Although the FAQ does eventually mention that --new-from-rev=origin/master is the right way, --help does not and using --new in CI is a terrible pitfall. Make --help point users to -new-from-rev=HEAD~ for CI setups. Also use HEAD~ instead of origin/master, since HEAD~ is more universally applicable, e.g. if golangci-lint is ran against a release branch.
1 parent a2450a5 commit d3eb3ed

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ Flags:
387387
--max-same-issues int Maximum count of issues with the same text. Set to 0 to disable (default 3)
388388
-n, --new Show only new issues: if there are unstaged changes or untracked files, only those changes are analyzed, else only changes in HEAD~ are analyzed.
389389
It's a super-useful option for integration of golangci-lint into existing large codebase.
390-
It's not practical to fix all existing issues at the moment of integration: much better don't allow issues in new code
390+
It's not practical to fix all existing issues at the moment of integration: much better to not allow issues in new code.
391+
For CI setups, prefer --new-from-rev=HEAD~, as --new can skip linting the current patch if any scripts generate unstaged files before golangci-lint runs.
391392
--new-from-rev REV Show only new issues created after git revision REV
392393
--new-from-patch PATH Show only new issues created in git patch with file path PATH
393394
-h, --help help for run
@@ -671,7 +672,7 @@ You can integrate it yourself, see this [wiki page](https://github.com/golangci/
671672

672673
**It's cool to use `golangci-lint` when starting a project, but what about existing projects with large codebase? It will take days to fix all found issues**
673674

674-
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 (or better use [GolangCI](https://golangci.com) to run `golangci-lint` with option `--new-from-rev=origin/master`. Also, take a look at option `-n`.
675+
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 (or better use [GolangCI](https://golangci.com)) to run `golangci-lint` with option `--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-rev=HEAD~1` is safer.
675676
By doing this you won't create new issues in your code and can choose fix existing issues (or not).
676677

677678
**How to use `golangci-lint` in CI (Continuous Integration)?**

README.tmpl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ You can integrate it yourself, see this [wiki page](https://github.com/golangci/
327327

328328
**It's cool to use `golangci-lint` when starting a project, but what about existing projects with large codebase? It will take days to fix all found issues**
329329

330-
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 (or better use [GolangCI](https://golangci.com) to run `golangci-lint` with option `--new-from-rev=origin/master`. Also, take a look at option `-n`.
330+
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 (or better use [GolangCI](https://golangci.com)) to run `golangci-lint` with option `--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-rev=HEAD~1` is safer.
331331
By doing this you won't create new issues in your code and can choose fix existing issues (or not).
332332

333333
**How to use `golangci-lint` in CI (Continuous Integration)?**

pkg/commands/run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config) {
153153
wh("Show only new issues: if there are unstaged changes or untracked files, only those changes "+
154154
"are analyzed, else only changes in HEAD~ are analyzed.\nIt's a super-useful option for integration "+
155155
"of golangci-lint into existing large codebase.\nIt's not practical to fix all existing issues at "+
156-
"the moment of integration: much better don't allow issues in new code"))
156+
"the moment of integration: much better to not allow issues in new code.\nFor CI setups, prefer "+
157+
"--new-from-rev=HEAD~, as --new can skip linting the current patch if any scripts generate "+
158+
"unstaged files before golangci-lint runs."))
157159
fs.StringVar(&ic.DiffFromRevision, "new-from-rev", "",
158160
wh("Show only new issues created after git revision `REV`"))
159161
fs.StringVar(&ic.DiffPatchFilePath, "new-from-patch", "",

0 commit comments

Comments
 (0)