Skip to content

Commit 36964d1

Browse files
authored
Merge pull request #457 from Luap99/gofumpt
image: enable gofumpt formatter
2 parents a806e5a + f0d4584 commit 36964d1

File tree

97 files changed

+492
-338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+492
-338
lines changed

CONTRIBUTING_GO.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ At present, this means the following repositories:
1414
## Topics
1515

1616
* [Unit Tests](#unit-tests)
17+
* [Go Format and lint](#go-format-and-lint)
1718
* [Go Dependency updates](#go-dependency-updates)
1819
* [Testing changes in a dependent repository](#testing-changes-in-a-dependent-repository)
1920
* [git bisect a change in a Go dependency](#git-bisect-a-change-in-a-go-dependency)
@@ -23,6 +24,11 @@ At present, this means the following repositories:
2324
Unit tests for Go code are added in a separate file within the same directory, named `..._test.go` (where the first part of the name is often the name of the file whose code is being tested).
2425
Our Go projects to not require unit tests, but contributors are strongly encouraged to unit test any code that can have a reasonable unit test written.
2526

27+
### Go Format and lint
28+
29+
We are using the [`gofumpt`](https://github.com/mvdan/gofumpt) formatter for our go code, you can either use it directly or format via `make fmt`.
30+
For linting we use [`golangci-lint`](github.com/golangci/golangci-lint), use `make validate` to run it together with some other basic commit checks.
31+
2632
## Go Dependency updates
2733

2834
To automatically keep dependencies up to date we use the [renovate](https://github.com/renovatebot/renovate) bot.

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ lint: .install.golangci-lint
4949
@$(MAKE) -C image lint
5050
@$(MAKE) -C storage lint
5151

52+
.PHONY: fmt
53+
fmt: .install.golangci-lint
54+
@$(MAKE) -C common fmt
55+
@$(MAKE) -C image fmt
56+
@$(MAKE) -C storage fmt
57+
5258
.PHONY: vendor-in-container
5359
vendor-in-container:
5460
podman run --privileged --rm --env HOME=/root -v `pwd`:/src -w /src golang make vendor

common/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ docs:
7474
lint:
7575
golangci-lint run
7676

77+
.PHONY: fmt
78+
fmt:
79+
golangci-lint fmt
80+
7781
.PHONY: validate
7882
validate: lint
7983
./tools/validate_seccomp.sh ./pkg/seccomp

image/.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
version: "2"
2+
3+
formatters:
4+
enable:
5+
- gofumpt
6+
27
linters:
38
enable:
49
- errorlint

image/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ test:
7575

7676
.PHONY: fmt
7777
fmt:
78-
@gofmt -l -s -w $(SOURCE_DIRS)
78+
golangci-lint fmt
7979

8080
.PHONY: lint
8181
lint:

image/copy/blob.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import (
1818
// and returns a complete blobInfo of the copied blob.
1919
func (ic *imageCopier) copyBlobFromStream(ctx context.Context, srcReader io.Reader, srcInfo types.BlobInfo,
2020
getOriginalLayerCopyWriter func(decompressor compressiontypes.DecompressorFunc) io.Writer,
21-
isConfig bool, toEncrypt bool, bar *progressBar, layerIndex int, emptyLayer bool) (types.BlobInfo, error) {
21+
isConfig bool, toEncrypt bool, bar *progressBar, layerIndex int, emptyLayer bool,
22+
) (types.BlobInfo, error) {
2223
// The copying happens through a pipeline of connected io.Readers;
2324
// that pipeline is built by updating stream.
2425
// === Input: srcReader

image/copy/compression.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ const (
109109
// Returns data for other steps; the caller should eventually call updateCompressionEdits and perhaps recordValidatedBlobData,
110110
// and must eventually call close.
111111
func (ic *imageCopier) blobPipelineCompressionStep(stream *sourceStream, canModifyBlob bool, srcInfo types.BlobInfo,
112-
detected bpDetectCompressionStepData) (*bpCompressionStepData, error) {
112+
detected bpDetectCompressionStepData,
113+
) (*bpCompressionStepData, error) {
113114
// WARNING: If you are adding new reasons to change the blob, update also the OptimizeDestinationImageAlreadyExists
114115
// short-circuit conditions
115116
layerCompressionChangeSupported := ic.src.CanChangeLayerCompression(stream.info.MediaType)
@@ -265,7 +266,8 @@ func (ic *imageCopier) bpcDecompressCompressed(stream *sourceStream, detected bp
265266
// This does not change the sourceStream parameter; we include it for symmetry with other
266267
// pipeline steps.
267268
func (ic *imageCopier) bpcPreserveOriginal(_ *sourceStream, detected bpDetectCompressionStepData,
268-
layerCompressionChangeSupported bool) *bpCompressionStepData {
269+
layerCompressionChangeSupported bool,
270+
) *bpCompressionStepData {
269271
logrus.Debugf("Using original blob without modification")
270272
// Remember if the original blob was compressed, and if so how, so that if
271273
// LayerInfosForCopy() returned something that differs from what was in the
@@ -320,7 +322,8 @@ func (d *bpCompressionStepData) updateCompressionEdits(operation *types.LayerCom
320322
// and the original srcInfo (which the caller guarantees has been validated).
321323
// This must ONLY be called if all data has been validated by OUR code, and is not coming from third parties.
322324
func (d *bpCompressionStepData) recordValidatedDigestData(c *copier, uploadedInfo types.BlobInfo, srcInfo types.BlobInfo,
323-
encryptionStep *bpEncryptionStepData, decryptionStep *bpDecryptionStepData) error {
325+
encryptionStep *bpEncryptionStepData, decryptionStep *bpDecryptionStepData,
326+
) error {
324327
// Don’t record any associations that involve encrypted data. This is a bit crude,
325328
// some blob substitutions (replacing pulls of encrypted data with local reuse of known decryption outcomes)
326329
// might be safe, but it’s not trivially obvious, so let’s be conservative for now.

image/copy/encryption.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ type bpEncryptionStepData struct {
8484
// srcInfo is primarily used for error messages.
8585
// Returns data for other steps; the caller should eventually call updateCryptoOperationAndAnnotations.
8686
func (ic *imageCopier) blobPipelineEncryptionStep(stream *sourceStream, toEncrypt bool, srcInfo types.BlobInfo,
87-
decryptionStep *bpDecryptionStepData) (*bpEncryptionStepData, error) {
87+
decryptionStep *bpDecryptionStepData,
88+
) (*bpEncryptionStepData, error) {
8889
if !toEncrypt || isOciEncrypted(srcInfo.MediaType) || ic.c.options.OciEncryptConfig == nil {
8990
return &bpEncryptionStepData{
9091
encrypting: false,

image/copy/manifest_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ func TestDetermineManifestConversion(t *testing.T) {
126126
},
127127
// Conversion necessary, a preferred format is not acceptable
128128
{
129-
"s2→OCI", manifest.DockerV2Schema2MediaType, []string{v1.MediaTypeImageManifest},
129+
"s2→OCI", manifest.DockerV2Schema2MediaType,
130+
[]string{v1.MediaTypeImageManifest},
130131
manifestConversionPlan{
131132
preferredMIMEType: v1.MediaTypeImageManifest,
132133
preferredMIMETypeNeedsConversion: true,
@@ -135,7 +136,8 @@ func TestDetermineManifestConversion(t *testing.T) {
135136
},
136137
// text/plain is converted if the destination does not accept s1
137138
{
138-
"text→s2", "text/plain", []string{manifest.DockerV2Schema2MediaType},
139+
"text→s2", "text/plain",
140+
[]string{manifest.DockerV2Schema2MediaType},
139141
manifestConversionPlan{
140142
preferredMIMEType: manifest.DockerV2Schema2MediaType,
141143
preferredMIMETypeNeedsConversion: true,
@@ -162,7 +164,8 @@ func TestDetermineManifestConversion(t *testing.T) {
162164
},
163165
},
164166
{
165-
"special→OCI", manifest.DockerV2ListMediaType, []string{v1.MediaTypeImageManifest, "other options", "with lower priority"},
167+
"special→OCI", manifest.DockerV2ListMediaType,
168+
[]string{v1.MediaTypeImageManifest, "other options", "with lower priority"},
166169
manifestConversionPlan{
167170
preferredMIMEType: v1.MediaTypeImageManifest,
168171
preferredMIMETypeNeedsConversion: true,

image/copy/multiple.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ func platformV1ToPlatformComparable(platform *imgspecv1.Platform) platformCompar
6060
}
6161
osFeatures := slices.Clone(platform.OSFeatures)
6262
sort.Strings(osFeatures)
63-
return platformComparable{architecture: platform.Architecture,
64-
os: platform.OS,
63+
return platformComparable{
64+
architecture: platform.Architecture,
65+
os: platform.OS,
6566
// This is strictly speaking ambiguous, fields of OSFeatures can contain a ','. Probably good enough for now.
6667
osFeatures: strings.Join(osFeatures, ","),
6768
osVersion: platform.OSVersion,
@@ -252,15 +253,17 @@ func (c *copier) copyMultipleImages(ctx context.Context) (copiedManifest []byte,
252253
UpdateDigest: updated.manifestDigest,
253254
UpdateSize: int64(len(updated.manifest)),
254255
UpdateCompressionAlgorithms: updated.compressionAlgorithms,
255-
UpdateMediaType: updated.manifestMIMEType})
256+
UpdateMediaType: updated.manifestMIMEType,
257+
})
256258
case instanceCopyClone:
257259
logrus.Debugf("Replicating instance %s (%d/%d)", instance.sourceDigest, i+1, len(instanceCopyList))
258260
c.Printf("Replicating image %s (%d/%d)\n", instance.sourceDigest, i+1, len(instanceCopyList))
259261
unparsedInstance := image.UnparsedInstance(c.rawSource, &instanceCopyList[i].sourceDigest)
260262
updated, err := c.copySingleImage(ctx, unparsedInstance, &instanceCopyList[i].sourceDigest, copySingleImageOptions{
261263
requireCompressionFormatMatch: true,
262264
compressionFormat: &instance.cloneCompressionVariant.Algorithm,
263-
compressionLevel: instance.cloneCompressionVariant.Level})
265+
compressionLevel: instance.cloneCompressionVariant.Level,
266+
})
264267
if err != nil {
265268
return nil, fmt.Errorf("replicating image %d/%d from manifest list: %w", i+1, len(instanceCopyList), err)
266269
}

0 commit comments

Comments
 (0)