-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Use ignore directive to ignore test files not to be passes to gofumpt #4936
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
base: master
Are you sure you want to change the base?
Conversation
in, err := os.Open(src) | ||
if err != nil { | ||
return //nolint: nakedret | ||
return err |
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.
This commit does not change actual behavior of this functions because err
is returned originally because this function uses "named return value".
We have adopted the workaround passing a result of `git ls-files '*.go' ':!vendor'` to gofumpt in jesseduffield#4809. Currently, gofumpt suports `ignore` directive. So we can use it without any workarounds.
After [v0.9.0](https://github.com/mvdan/gofumpt/releases/tag/v0.9.0), gofumpt prohibits "naked return" for the sake of clarity. This makes more readable when "named return value" is used. For more infomation for "prohibition of naked return": mvdan/gofumpt#285.
By running gofumpt@0.9.1, the return value of `makeAtomic` function is specified. After that, golangci-lint shows an error like `return copies lock value: sync/atomic.Int32 contains sync/atomic.noCopy`. This happens because atomic values should not be copied. So I made a change using them as pointers.
gofumpt version for local developement is updated to `v0.9.1`. This commit updates golangci-lint to `v2.5.0` which is the lastest and the first version supports `gofumpt@v0.9.1` to match the behavior of local dev and ci. This version of golangci-lint supports go 1.24 as well.
b31c53a
to
3665734
Compare
It may seem like a good idea to pin gofumpt to a specific version, but here you only do it for The only way I could find to pin format-on-save to a specific version is with a patch like this: diff --git a/.vscode/settings.json b/.vscode/settings.json
index dd4398af90..ab5f329f2d 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,6 +1,5 @@
{
"gopls": {
- "formatting.gofumpt": true,
"ui.diagnostic.staticcheck": true,
"ui.diagnostic.analyses": {
// This list must match the one in .golangci.yml
@@ -24,6 +23,8 @@
},
"go.alternateTools": {
"golangci-lint-v2": "${workspaceFolder}/scripts/golangci-lint-shim.sh",
+ "customFormatter": "${workspaceFolder}/scripts/gofumpt-shim.sh",
},
"go.lintTool": "golangci-lint-v2",
+ "go.formatTool": "custom",
}
diff --git a/scripts/gofumpt-shim.sh b/scripts/gofumpt-shim.sh
new file mode 100755
index 0000000000..8087384093
--- /dev/null
+++ b/scripts/gofumpt-shim.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+set -e
+
+# Must be kept in sync with ...
+version="v0.9.1"
+
+go run "mvdan.cc/gofumpt@$version" "$@" The downside is that it makes pressing Command-S slower (not very much, but still noticeable), so unless we find a better way to solve this, I'm against this change. Other places that also call or install gofumpt are |
Motivation
To replace the workaround introduced in #4809 with
ignore
directive to make the code simpler.Overview
This is a follow-up PR to #4809.
I have added 4 changes due to updating gofumpt to remove
git ls-files
workaround.Please take a look at each commit messages for details.
Please check if the PR fulfills these requirements
go generate ./...
)