-
Notifications
You must be signed in to change notification settings - Fork 131
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
Add gofmt -s
to CI
#146
Add gofmt -s
to CI
#146
Conversation
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.
Thank you for the PR.
I reckon it's sensible to run these checks only on Linux, assuming that gofmt
behaves consistently the same on Windows/macOS/Linux.
It seems that this won't be solved natively in gofmt
any time soon: golang/go#24230
and the only recommendation seems Linux/Unix-specific (test -z "$(gofmt -s -l "$file")"
)
I'm not sure about introducing platform-specific logic into the makefile as we just removed it recently in #98 but arguably Make is a unix tool anyway, so maybe that's expected? 🤔
Makefile
Outdated
@gofmt -s -w $(SOURCE_FILES) | ||
|
||
fmtcheck: | ||
@gofmt -s -l $(SOURCE_FILES) | grep ^; if [ $$? -eq 0 ]; then exit 1; fi |
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 think this won't work on Windows, which I suspect is the reason the first commit has failed CI checks.
Makefile
Outdated
@@ -1,6 +1,14 @@ | |||
SOURCE_FILES ?= $$(find . -not -path "./vendor/*" -type f -name "*.go") |
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 won't work on Windows I think
Thank you for the review. 😃 How about simply not using Makefile like this? |
I'm not opposed to it, but I'm also thinking about this from the perspective of a new contributor. If we enforce some checks in the CI, then contributors should have an easy way of (a) checking that their contribution complies, and (b) fix code that isn't compliant - and do this before they make that contribution. Right now it appears that Windows users would be left with the only option of either using IDE which does the appropriate formatting for them, or create their own PowerShell/other script. While I'm not Windows user myself, I think that's suboptimal. |
Make sense. My another idea is using golangci-lint. |
Yeah, I think that's a decent solution, but I'd like to first understand all the complexity introduced by My understanding is that it has some opinions on how code should be written and I wouldn't want to treat these opinions as a barrier for contributions to the language server. If CI does flag up something I'd like it to be really justified and I'd like to be sure that these are genuine problems or serious risks. With that in mind the |
I haven't tried this myself, but https://github.com/mh-cbon/go-fmt-fail looks like something I would otherwise build in this situation, so that may be worth checking too. |
Thank you for your polite comment.
I've tried go-fmt-fail in my forked repository ( jojo43#3 ), and it worked as same even on Windows. |
Sounds great - feel free to modify your PR to use that utility then 👍 Just a few suggestions wrt the linked PR in your repository (1) I believe it can be significantly simplified by invoking the tool via (2) Most Go commands (including That flag is something we should (and currently don't) generally use for all Go commands in CI/makefile to ensure reproducibility and consistency. That can be fixed by setting export GOFLAGS = -mod=vendor (which seems to work on Windows too FWIW) and by setting the same variable in the CI via (3)The failure you saw earlier in your Windows CI run is most likely related to the default git settings on Windows where it converts |
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.
Thank you for your advice. 😃
I've learned a lot from you.
I added some fixes.
Please take another look.
Thank you for making these last changes and for your contribution overall. 👍 |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Hi, this is my first contribution.
Please feedback me if there's anything.
This PR resolves a part of #108 .