-
-
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
Use ignore directive to ignore test files not to be passes to gofumpt #4936
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".
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 |
Thanks for the feedback!
I see. Then how about this?
If we adopt this solution, Command+S won't become slow.
Thanks for the input. |
3665734
to
5412792
Compare
Thinking about it more, you could also argue that we don't need to pin the version of gofumpt at all, and in fact I think that's what I would propose right now. Really, the only reason why pinning came up now is because we want to ensure that people running Another reason to pin the version might be the naked return thing; however, we don't really have to pin it for that, either. We just need to fix our code so that all versions of gofumpt are happy with it (which you did in this branch). The only reason where we would need to pin the version is when different versions of gofumpt disagree on how a particular piece of code is formatted, in which case the code would oscillate back and forth as you switch between versions. I have never heard of an example of this happening, and if we ever run into such a case, we can react then. I also find the whole topic not important enough to spend a lot of time on it, to be honest. |
Thanks for the detailed reply! OK. So I'm going to close this PR for now. I'll make a change when it needed in the future. |
You must have got me wrong, I wasn't asking you to close the PR. Some of the changes are still useful; for example, fixing the naked returns is a good change for people who already updated their gofumpt. I also don't have objections against removing the I cleaned up the commit history a bit, and dropped the golangci-lint update. I'm happy to merge the PR in this state; please have a look if you agree. |
5412792
to
abae2e0
Compare
I misunderstood that you don't want to spend any time on this PR, and you think changes should be made when they become necessary. Anyway, thanks for the fix! |
This can be used by go tools such as gofumpt.
When a new enough gofumpt version is used (v0.9.0 or later), it suports the `ignore` directive that we just added, so the workaround is no longer needed. Co-authored-by: Stefan Haller <[email protected]>
When replacing the naked return with a `return result`, the linter starts to complain about "return copies lock value: sync/atomic.Int32 contains sync/atomic.noCopy". I suspect this is also a problem when using a naked return, and the linter just doesn't catch it in that case. Either way, it's better to use a pointer to ensure that the atomic is not copied. Co-authored-by: Stefan Haller <[email protected]>
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.
abae2e0
to
64bcc72
Compare
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 ./...
)