-
Notifications
You must be signed in to change notification settings - Fork 386
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 gofumpt #2500
Use gofumpt #2500
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.
Thanks!
I don’t feel too strongly about this: The code does look a bit better (notably the handling of empty lines), but the cost is an extra step and frustration for occasional contributors, who are not specifically set up for c/image, file a PR, and see it fail tests. On balance, I don’t think it’s worth it — but that’s a guess.
I understand the concern; yet, most contributors use gofmt already, and gofumpt is not a huge superset of gofmt, so in many cases code formatted by gofmt will pass gofumpt. |
Instead, enable gofmt linter for golangci-lint. Same checking in CI, less infra code to maintain. Signed-off-by: Kir Kolyshkin <[email protected]>
gofumpt is essentially a stricter gofmt, adding some extra formatting rules. To me, using it almost always result in better looking and more readable code. This commit does two things: - formats all sources with gofumpt -w (using v0.6.0); - replaces gofmt linter with gofumpt (since it is a superset). PS If you already use gopls to autoformat the sources from your $EDITOR, you can switch to gofumpt; see [1]. [1]: https://github.com/golang/tools/blob/master/gopls/doc/settings.md#gofumpt-bool Signed-off-by: Kir Kolyshkin <[email protected]>
rebased |
@mtrmac what do you want me to do about this PR? Options I see are:
|
@@ -126,7 +126,8 @@ func TestDetermineManifestConversion(t *testing.T) { | |||
}, | |||
// Conversion necessary, a preferred format is not acceptable | |||
{ | |||
"s2→OCI", manifest.DockerV2Schema2MediaType, []string{v1.MediaTypeImageManifest}, | |||
"s2→OCI", manifest.DockerV2Schema2MediaType, | |||
[]string{v1.MediaTypeImageManifest}, |
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.
In this file: The line breaks are currently consistent across the table… and shorter entries, even if wider help scanning.
@@ -69,7 +69,7 @@ func TestTlsConfigFromCertPath(t *testing.T) { | |||
} | |||
|
|||
func TestSkipTLSVerifyOnly(t *testing.T) { | |||
//testDir := testDir(t) | |||
// testDir := testDir(t) |
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 comment can just be dropped.
@@ -340,21 +340,26 @@ type tarFI struct { | |||
func (t *tarFI) Name() string { | |||
return t.path | |||
} | |||
|
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.
Absolutely non-blocking: I’m not in love with these added lines. But then I can see argument that tarFI
could be in a separate file instead…
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.
Perhaps this can be reformatted like this instead?
func (t *tarFI) Name() string { return t.path }
func (t *tarFI) Size() int64 { return t.size }
func (t *tarFI) Mode() os.FileMode {
if t.isSymlink {
return os.ModeSymlink
}
return 0o444
}
func (t *tarFI) ModTime() time.Time { return time.Unix(0, 0) }
func (t *tarFI) IsDir() bool { return false }
func (t *tarFI) Sys() any { return nil }
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.
*shrug* That also works… I realize this is not worth that much discussion.
@@ -373,30 +374,39 @@ type memoryImageDest struct { | |||
func (d *memoryImageDest) Reference() types.ImageReference { | |||
return refImageReferenceMock{ref: d.ref} | |||
} | |||
|
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.
Non-blocking: Aesthetically I like these mocks without the blank lines, but, meh, not that important. Alternatively, this could be moved, maybe as a Forbidden*
parent, to internal/testing/mocks
. (It currently isn’t there because there is only a single user.)
{"unknown", nil, ""}, | ||
{"unknown", &compression.Gzip, ""}, | ||
{"", nil, ""}, | ||
{"", &compression.Gzip, ""}, | ||
} { |
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.
These are currently organized one line per input “MIME type”, e.g. all for AU
on a single line.
I suppose the test could be restructured to make that an explicit data structure instead; with extra type names that might end up with more noise, I’m not sure.
{d: digestCompressedA, lr: "A1"}, | ||
{d: digestCompressedA, lr: "A2"}, | ||
{d: digestCompressedB, lr: "B1"}, | ||
{d: digestCompressedB, lr: "B2"}, |
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.
Throughout this file, the two items on a single line show the relationship — same digest, specific order of locations.
I suppose the test could be restructured to make that an explicit data structure instead; with extra type names that might end up with more noise, I’m not sure.
root + "suffix4"}, // A valid root@graph+run set | ||
{"[" + driver + "@" + root + "suffix3+" + root + "suffix4:options,options,options]", | ||
root + "suffix4", | ||
}, // A valid root@graph+run set |
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.
Really the comments would be more helpful be on the {
line of the test
|
The main purpose of gofumpt is same as gofmt, i.e. "enable and forget", and if we can not do that, it doesn't make sense to have it. |
gofumpt is essentially a stricter gofmt, adding some extra formatting
rules. To me, using it almost always result in better looking and more
readable code.
This commit does two things:
PS If you already use gopls to autoformat the sources from your $EDITOR,
you can switch to gofumpt; see 1.