Skip to content

test: Check gofmt results - #4175

Merged
JoeKar merged 2 commits into
micro-editor:masterfrom
JoeKar:test/gofmt
Aug 18, 2026
Merged

test: Check gofmt results#4175
JoeKar merged 2 commits into
micro-editor:masterfrom
JoeKar:test/gofmt

Conversation

@JoeKar

@JoeKar JoeKar commented Aug 16, 2026

Copy link
Copy Markdown
Member

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.

@JoeKar
JoeKar marked this pull request as draft August 16, 2026 09:02
@JoeKar
JoeKar marked this pull request as ready for review August 16, 2026 09:11
Comment thread Makefile Outdated
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?)

@JoeKar JoeKar Aug 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Right, it requires \n (LF) only.

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?)

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be working 😉

Comment thread Makefile Outdated
Comment thread .gitattributes Outdated
JoeKar added 2 commits August 17, 2026 21:16
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.
@JoeKar
JoeKar merged commit 0922ee4 into micro-editor:master Aug 18, 2026
6 checks passed
@JoeKar
JoeKar deleted the test/gofmt branch August 18, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants