Skip to content
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

updates and fixes to linters #4828

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ linters:
disable-all: true

linters-settings:
govet:
enable:
- nilness
- unusedwrite
# enable-all: true
# disable:
# - fieldalignment
# - shadow
depguard:
rules:
main:
Expand Down
5 changes: 2 additions & 3 deletions cache/blobs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ func (sr *immutableRef) tryComputeOverlayBlob(ctx context.Context, lower, upper
if err := compressed.Close(); err != nil {
return emptyDesc, false, errors.Wrap(err, "failed to close compressed diff writer")
}
if labels == nil {
labels = map[string]string{}
labels = map[string]string{
labelspkg.LabelUncompressed: dgstr.Digest().String(),
}
labels[labelspkg.LabelUncompressed] = dgstr.Digest().String()
} else {
if err = overlay.WriteUpperdir(ctx, bufW, upperdir, lower); err != nil {
return emptyDesc, false, errors.Wrap(err, "failed to write diff")
Expand Down
8 changes: 4 additions & 4 deletions hack/dockerfiles/lint.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG GO_VERSION=1.21
ARG ALPINE_VERSION=3.19
ARG XX_VERSION=1.4.0
ARG PROTOLINT_VERSION=0.45.0
ARG GOLANGCI_LINT_VERSION=1.55.0
ARG GOLANGCI_LINT_VERSION=1.57.1

FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golang-base
FROM --platform=$BUILDPLATFORM yoheimuta/protolint:${PROTOLINT_VERSION} AS protolint-base
Expand All @@ -19,7 +19,7 @@ COPY --link --from=protolint-base /usr/local/bin/protolint /usr/local/bin/protol
COPY --link --from=xx / /
WORKDIR /go/src/github.com/moby/buildkit

FROM base as golangci-lint
FROM base AS golangci-lint
ARG TARGETNAME
ARG BUILDTAGS
ARG TARGETPLATFORM
Expand All @@ -29,12 +29,12 @@ RUN --mount=target=/go/src/github.com/moby/buildkit \
golangci-lint run --build-tags "${BUILDTAGS}" && \
touch /golangci-lint.done

FROM base as yamllint
FROM base AS yamllint
RUN --mount=target=/go/src/github.com/moby/buildkit \
yamllint -c .yamllint.yml --strict . && \
touch /yamllint.done

FROM base as protolint
FROM base AS protolint
RUN --mount=target=/go/src/github.com/moby/buildkit \
protolint lint . && \
touch /protolint.done
Expand Down
3 changes: 0 additions & 3 deletions source/git/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,6 @@ func (gs *gitSourceHandler) Snapshot(ctx context.Context, g session.Group) (out
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}
defer cleanup()
gitDir, err := git.GitDir(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion util/imageutil/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestConfigMultiplatform(t *testing.T) {
pArm64 := platforms.MustParse("linux/arm64")
cfgDescArm64 := cc.Add(t, ocispecs.Image{Platform: pArm64}, ocispecs.MediaTypeImageConfig, nil)
mfstArm64 := ocispecs.Manifest{MediaType: ocispecs.MediaTypeImageManifest, Config: cfgDescArm64}
_, descArm64 := makeDesc(t, mfst386, mfstArm64.MediaType, &pArm64)
_, descArm64 := makeDesc(t, mfstArm64, mfstArm64.MediaType, &pArm64)

idx := ocispecs.Index{
MediaType: ocispecs.MediaTypeImageIndex,
Expand Down
2 changes: 1 addition & 1 deletion util/overlay/overlay_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func Changes(ctx context.Context, changeFn fs.ChangeFunc, upperdir, upperdirView
} else if os.IsNotExist(err) || errors.Is(err, unix.ENOTDIR) {
// File doesn't exist in the base layer. Thus this is added.
kind = fs.ChangeKindAdd
} else if err != nil {
} else {
return errors.Wrap(err, "failed to stat base file during overlay diff")
}

Expand Down
2 changes: 1 addition & 1 deletion util/system/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestNormalizeWorkdir(t *testing.T) {
func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) {
// Fails if not C drive.
_, err := CheckSystemDriveAndRemoveDriveLetter(`d:\`, "windows")
if err == nil || (err != nil && err.Error() != "The specified path is not on the system drive (C:)") {
if err == nil || err.Error() != "The specified path is not on the system drive (C:)" {
t.Fatalf("Expected error for d:")
}

Expand Down
Loading