test: Check gofmt results - #4175
Conversation
| ifneq ($(GOHOSTOS), windows) | ||
| @# Do not perform this test under Windows, because gofmt will find | ||
| @# different line endings and complains about every file! | ||
| @# https://github.com/golang/go/issues/16355 |
There was a problem hiding this comment.
I'm not sure I understand. What is the existing behavior of gofmt: does it require \r\n endings on Windows, or does it require \n on Windows just like on Unix?
From golang/go#16355 it sounds like it requires \n on Windows just like on Unix?
And if so, it shouldn't complain, since Micro's source code is using \n endings? (And we do want it to complain in case when a Windows user submits a PR with \r\n endings?)
There was a problem hiding this comment.
What is the existing behavior of
gofmt: does it require\r\nendings on Windows, or does it require\non Windows just like on Unix?From golang/go#16355 it sounds like it requires
\non Windows just like on Unix?
Right, it requires \n (LF) only.
And if so, it shouldn't complain, since Micro's source code is using
\nendings? (And we do want it to complain in case when a Windows user submits a PR with\r\nendings?)
Depends how it is checked out.
I stumbled across that because the first action test run failed:
micro/actions/runs/31937703270/job/95142126755#step:5:24
I assume that the actions/checkout@v6 action converts the \n/LF to \r\n/CRLF (with autocrlf), because it is the default under Windows and this might be something any arbitrary user could do.
-> actions/checkout#135 confirms that
Sure, we could change our action runner, to perform as expected (actions/checkout#38), but still a native Windows user face this issue, when the test is active on all platforms.
For the Go compiler it is irrelevant, because it ignores the \r/CR, but not gofmt.
The only solution I see is adding a .gitattributes file to force this setting with our repository. 🤔
Then we would not need this switch in the test target of our Makefile.
I think it is worth the try.
This is required for tools like `gofmt` to process the files on all platforms the same. Otherwise it marks every file with CRLFs as unformatted.
We like to have gofmt-ed files present in PRs before a review is done. To reach this we let the PR test fail in the moment the files are not properly formatted.
We like to have gofmt-ed files present in PRs before a review is done. To reach this we let the PR test fail in the moment the files are not properly formatted.