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

golangci-lint: update config file and make relevant changes to the code #253

Merged
merged 4 commits into from
Sep 23, 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
42 changes: 25 additions & 17 deletions .golanci.yml → .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ run:
issues-exit-code: 1

output:
formats: colored-line-number
formats:
- format: colored-line-number

linters-settings:
errcheck:
Expand All @@ -16,22 +17,22 @@ linters-settings:
- default
- blank
- dot
- prefix(github.com/linode)
- prefix(github.com/linode/linode-blockstorage-csi-driver)

govet:
check-shadowing: false
enable:
- shadow

golint:
min-confidence: 0.8
gosec:
confidence: "medium"
excludes:
- G115

gofmt:
simplify: true

goimports:
local-prefixes: github.com/linode/

maligned:
suggest-new: true
local-prefixes: github.com/linode/linode-blockstorage-csi-driver

dupl:
threshold: 100
Expand Down Expand Up @@ -70,10 +71,10 @@ linters:
enable:
- asasalint
- asciicheck
- bidicheck
- bodyclose
- containedctx
- contextcheck
- copyloopvar
- decorder
- dogsled
- dupl
Expand All @@ -83,9 +84,7 @@ linters:
- errname
- errorlint
- errcheck
- exportloopref
- exhaustive
- exportloopref
- forbidigo
- forcetypeassert
- gci
Expand All @@ -103,13 +102,11 @@ linters:
- maintidx
- makezero
- misspell
- mnd
- nestif
- nilerr
- nilnil
- noctx
- nolintlint
- parlalleltest
- prealloc
- predeclared
- reassign
Expand All @@ -131,11 +128,23 @@ linters:

issues:
exclude-rules:
- path: _test\.go
# Exclude some linters from running on tests files.
- path: _test(ing)?\.go
linters:
- gocyclo
- maintidx
- errcheck
- dupl
- exportloopref
- gosec
- copyloopvar
- unparam
- varnamelen

# Ease some gocritic warnings on test files.
- path: _test\.go
text: "(unnamedResult|exitAfterDefer)"
linters:
- gocritic

- text: "G101:"
linters:
Expand All @@ -149,7 +158,6 @@ issues:

exclude-use-default: false
new: false
max-per-linter: 0
max-same-issues: 0
exclude-files:
- "zz_generated\\..+\\.go$"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ LABEL description="Linode CSI Driver"

COPY --from=builder /bin/linode-blockstorage-csi-driver /linode

RUN apk add --no-cache e2fsprogs findmnt blkid cryptsetup xfsprogs lsblk
RUN apk add --no-cache e2fsprogs findmnt blkid cryptsetup xfsprogs
COPY --from=builder /bin/linode-blockstorage-csi-driver /linode
ENTRYPOINT ["/linode"]
4 changes: 4 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM golang:1.23.1-alpine AS builder
# from makefile
ARG REV
ARG GOLANGCI_LINT_VERSION

RUN mkdir -p /linode
WORKDIR /linode
Expand All @@ -10,6 +11,7 @@ RUN apk add \
cryptsetup \
cryptsetup-libs \
cryptsetup-dev \
curl \
e2fsprogs \
findmnt \
gcc \
Expand All @@ -26,4 +28,6 @@ COPY . .

RUN CGO_ENABLED=1 go build -a -ldflags '-X main.vendorVersion='${REV}'' -o /bin/linode-blockstorage-csi-driver /linode
RUN CGO_ENABLED=1 go install go.uber.org/mock/mockgen@latest
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}

CMD ["sh"]
35 changes: 20 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
PLATFORM ?= linux/amd64
REGISTRY_NAME ?= index.docker.io
DOCKER_USER ?= linode
IMAGE_NAME ?= linode-blockstorage-csi-driver
REV := $(shell git branch --show-current 2> /dev/null || echo "dev")
PLATFORM ?= linux/amd64
REGISTRY_NAME ?= index.docker.io
DOCKER_USER ?= linode
IMAGE_NAME ?= linode-blockstorage-csi-driver
REV := $(shell git branch --show-current 2> /dev/null || echo "dev")
ifdef DEV_TAG_EXTENSION
IMAGE_VERSION ?= $(REV)-$(DEV_TAG_EXTENSION)
IMAGE_VERSION ?= $(REV)-$(DEV_TAG_EXTENSION)
else
IMAGE_VERSION ?= $(REV)
IMAGE_VERSION ?= $(REV)
endif
IMAGE_TAG ?= $(REGISTRY_NAME)/$(DOCKER_USER)/$(IMAGE_NAME):$(IMAGE_VERSION)
GOLANGCI_LINT_IMG := golangci/golangci-lint:v1.59-alpine
RELEASE_DIR ?= release
DOCKERFILE ?= Dockerfile
IMAGE_TAG ?= $(REGISTRY_NAME)/$(DOCKER_USER)/$(IMAGE_NAME):$(IMAGE_VERSION)
GOLANGCI_LINT_IMG := golangci/golangci-lint:v1.59-alpine
RELEASE_DIR ?= release
DOCKERFILE ?= Dockerfile
GOLANGCI_LINT_VERSION ?= v1.61.0

#####################################################################
# OS / ARCH
Expand All @@ -30,15 +31,15 @@ endif
#####################################################################
.PHONY: fmt
fmt:
docker run --rm --platform=$(PLATFORM) -it $(IMAGE_TAG) go fmt ./...
docker run --rm -w /workdir -v $(PWD):/workdir --platform=$(PLATFORM) -it $(IMAGE_TAG) go fmt ./...

.PHONY: vet
vet: fmt
docker run --rm --platform=$(PLATFORM) -it $(IMAGE_TAG) go vet ./...
docker run --rm -w /workdir -v $(PWD):/workdir --platform=$(PLATFORM) -it $(IMAGE_TAG) go vet ./...

.PHONY: lint
lint: vet
docker run --rm --platform=$(PLATFORM) --rm -v $(PWD):/app -w /app ${GOLANGCI_LINT_IMG} golangci-lint run -v
docker run --rm -w /workdir -v $(PWD):/workdir --platform=$(PLATFORM) -it $(IMAGE_TAG) golangci-lint run -v -c .golangci.yml --fix

.PHONY: verify
verify:
Expand Down Expand Up @@ -69,7 +70,11 @@ build:

.PHONY: docker-build
docker-build:
DOCKER_BUILDKIT=1 docker build --platform=$(PLATFORM) --progress=plain -t $(IMAGE_TAG) --build-arg REV=$(IMAGE_VERSION) -f ./$(DOCKERFILE) .
DOCKER_BUILDKIT=1 docker build --platform=$(PLATFORM) --progress=plain \
-t $(IMAGE_TAG) \
--build-arg REV=$(IMAGE_VERSION) \
--build-arg GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION) \
-f ./$(DOCKERFILE) .

.PHONY: docker-push
docker-push:
Expand Down
Loading