-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat(golangcilint): bump to v2 #661
base: master
Are you sure you want to change the base?
Conversation
ecfc792
to
96e6f65
Compare
1f9c6b8
to
1a48393
Compare
7f65427
to
8352cdd
Compare
@thall Yes, I think that's good - I'll remove anything formatting related from the PR. But just so it is clear, the formatting does not happen on |
8352cdd
to
4928a1f
Compare
Ah okej, that is good! Lets keep this PR as small as possible then. |
4928a1f
to
62698d7
Compare
@thall But apart from that, I think primarily we need to get the |
3291ec2
to
6aad113
Compare
Perfect, looks like it just got sorted. I can try this PR out in some repos as well. |
@@ -44,9 +55,9 @@ linters: | |||
# [fast: ?, auto-fix: true] | |||
- exptostd | |||
|
|||
# Check package import order and make it always deterministic. | |||
# [fast: true, auto-fix: true] | |||
- gci |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this removed in the new config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unable to add gci
back in:
[go-lint] Error: can't load config: gci is a formatter
[go-lint] Failed executing command with error: can't load config: gci is a formatter
Their migration guide is very confusing around gci/gofumpt. But when looking at the linters page, you can see it is no longer available as linter. I guess we can only use it as a formatter now. See https://golangci-lint.run/usage/formatters/
I'm adding those in here: #662
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -60,10 +71,6 @@ linters: | |||
# [fast: true, auto-fix: true] | |||
- godot | |||
|
|||
# Check whether code was gofumpt-ed. | |||
# [fast: true, auto-fix: true] | |||
- gofumpt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was moved out of the linters
section and is now a formatter, like with gci
.
[go-lint] Error: can't load config: gofumpt is a formatter
[go-lint] Failed executing command with error: can't load config: gofumpt is a formatter
Again, I'm adding it here: #662
@fredrikaverpil Tried this out in one of our repos, what is the intended migration path for code like this: return sggolangcilint.Run(
ctx,
"--exclude-dirs",
"website",
"--exclude-dirs",
"terraform",
"--exclude-dirs",
"api",
"--exclude-dirs",
"data-mesh",
) Fails with:
|
@thall unfortunately, I think exclusions now need to exist in ❯ golangci-lint run --help
Run the linters
Usage:
golangci-lint run [flags]
Flags:
-c, --config PATH Read config from file path PATH
--no-config Don't read config file
--default string Default set of linters to enable (default "standard")
-D, --disable strings Disable specific linter
-E, --enable strings Enable specific linter
--enable-only strings Override linters configuration section to only run the specific linter(s)
--fast-only Filter enabled linters to run only fast linters
-j, --concurrency int Number of CPUs to use (Default: Automatically set to match Linux container CPU quota and fall back to the number of logical CPUs in the machine)
--modules-download-mode string Modules download mode. If not empty, passed as -mod=<mode> to go tools
--issues-exit-code int Exit code when issues were found (default 1)
--build-tags strings Build tags
--timeout duration Timeout for total work. Disabled by default
--tests Analyze tests (*_test.go) (default true)
--allow-parallel-runners Allow multiple parallel golangci-lint instances running.
If false (default) - golangci-lint acquires file lock on start.
--allow-serial-runners Allow multiple golangci-lint instances running, but serialize them around a lock.
If false (default) - golangci-lint exits with an error if it fails to acquire file lock on start.
--path-prefix string Path prefix to add to output
--show-stats Show statistics per linter (default true)
--output.text.path stdout Output path can be either stdout, `stderr` or path to the file to write to.
--output.text.print-linter-name Print linter name in the end of issue text. (default true)
--output.text.print-issued-lines Print lines of code with issue. (default true)
--output.text.colors Use colors. (default true)
--output.json.path stdout Output path can be either stdout, `stderr` or path to the file to write to.
--output.tab.path stdout Output path can be either stdout, `stderr` or path to the file to write to.
--output.tab.print-linter-name Print linter name in the end of issue text. (default true)
--output.tab.colors Use colors. (default true)
--output.html.path stdout Output path can be either stdout, `stderr` or path to the file to write to.
--output.checkstyle.path stdout Output path can be either stdout, `stderr` or path to the file to write to.
--output.code-climate.path stdout Output path can be either stdout, `stderr` or path to the file to write to.
--output.junit-xml.path stdout Output path can be either stdout, `stderr` or path to the file to write to.
--output.junit-xml.extended Support extra JUnit XML fields.
--output.teamcity.path stdout Output path can be either stdout, `stderr` or path to the file to write to.
--output.sarif.path stdout Output path can be either stdout, `stderr` or path to the file to write to.
--max-issues-per-linter int Maximum issues count per one linter. Set to 0 to disable (default 50)
--max-same-issues int Maximum count of issues with the same text. Set to 0 to disable (default 3)
--uniq-by-line Make issues output unique by line (default true)
-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.
It's a super-useful option for integration of golangci-lint into existing large codebase.
It's not practical to fix all existing issues at the moment of integration: much better to not allow issues in new code.
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.
--new-from-rev REV Show only new issues created after git revision REV
--new-from-patch PATH Show only new issues created in git patch with file path PATH
--new-from-merge-base string Show only new issues created after the best common ancestor (merge-base against HEAD)
--whole-files Show issues in any part of update files (requires new-from-rev or new-from-patch)
--fix Fix found issues (if it's supported by the linter)
--cpu-profile-path string Path to CPU profile output file
--mem-profile-path string Path to memory profile output file
--print-resources-usage Print avg and max memory usage of golangci-lint and total time
--trace-path string Path to trace output file
Global Flags:
--color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto")
-h, --help Help for a command
-v, --verbose Verbose output Meaning, you have to remove the |
@thall it's worth noting that even if you exclude paths in the config, the directories are still traversed. From the config file docs: linters:
exclusions:
# Which file paths to exclude: they will be analyzed, but issues from them won't be reported.
# "/" will be replaced by the current OS file path separator to properly work on Windows.
# Default: []
paths:
- ".*\\.my\\.go$"
- lib/bad.go
# Which file paths to not exclude.
# Default: []
paths-except:
- ".*\\.my\\.go$"
- lib/bad.go |
6aad113
to
eb28029
Compare
@fredrikaverpil I understand why its failing, the problem here is that the config is located within Sage, and thus not possible to modify in order to achieve the same behavior as today. |
@thall no, I see it the same way as you do, unless you are fine with skipping those exclusions. |
eb28029
to
df59ac3
Compare
df59ac3
to
eef925f
Compare
// CommandInDirectoryV2 does not automatically append any arguments, and delegates any confiuration to the caller. | ||
func CommandInDirectoryV2(ctx context.Context, directory string, args ...string) *exec.Cmd { | ||
cmdArgs := append([]string{"run"}, args...) | ||
cmd := Command(ctx, cmdArgs...) | ||
cmd.Dir = directory | ||
return cmd | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thall not a fantastic name (CommandInDirectoryV2
), but this could be used to supply all arguments yourself.
Another alternative is to create other config files for specific use cases next to the golangci.yml
we have now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought, since we have so much Go code and this changes both how the tool itself works and linting results, what do you think about adding a new package sggolangcilintV2
and let everyone migrate at their own pace?
@kristofferwanglund yes, I thought about this too, actually. I think the bigger question is how we want to deal with the config file which might no longer be suitable for all projects if different projects needs different exclusion filters. |
Why?
Golangci-lint was bumped to v2.
What?
v2.0.2
in Sage.golangci-lint migrate -c golangci.yml
. This sorted the linters for us, so they are now in alphabetical order. Thegci
,gofumpt
linters were removed (now exists as formatters) andgosimple
has been absorbed bystaticcheck
.relative-path-mode
(see separate comment).--exclude "(is a global variable|is unused)"
CLI argument (as it must now be configured in the yaml instead). But I don't think this kind of exclusion is needed, so I did not add it into the yaml.Will be saved for a separate PR
Enabled vs disabled linters
Notes