Skip to content

Commit

Permalink
feat: update golangci-lint to 1.45.0 and gofumpt to 0.3.0
Browse files Browse the repository at this point in the history
- Update golangci-lint to 1.45.0
- Update gofumpt to 0.3.0
- Fix gofumpt errors
- Add goimports and format imports since gofumports is removed
- Update Dockerfile
- Fix .golangci.yml configuration
- Fix linting errors

Signed-off-by: Dmitriy Matrenichev <[email protected]>
  • Loading branch information
DmitriyMV committed Mar 24, 2022
1 parent a92c614 commit e06e147
Show file tree
Hide file tree
Showing 127 changed files with 7,196 additions and 5,148 deletions.
11 changes: 8 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ linters-settings:
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default
gci:
local-prefixes: github.com/talos-systems/talos
sections:
- standard # Captures all standard packages if they do not match another section.
- default # Contains all imports that could not be matched to another section type.
- prefix(github.com/talos-systems/talos) # Groups all imports with the specified Prefix.
cyclop:
# the maximal code complexity to report
max-complexity: 20
Expand All @@ -138,6 +141,7 @@ linters:
- errorlint
- exhaustivestruct
- forbidigo
- forcetypeassert
- funlen
- gas
- gochecknoglobals
Expand All @@ -148,6 +152,7 @@ linters:
- gomnd
- ifshort
- ireturn # we return interfaces
- maintidx
- nestif
- nilnil # we return "nil, nil"
- paralleltest
Expand Down Expand Up @@ -199,10 +204,10 @@ issues:
exclude-use-default: false

# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-per-linter: 0
max-issues-per-linter: 0

# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same: 0
max-same-issues: 0

# Show only new issues: if there are unstaged changes or untracked files,
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
Expand Down
20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ RUN ["/toolchain/bin/ln", "-svf", "/toolchain/bin/bash", "/bin/sh"]
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/etc/ssl", "/etc/ssl"]
ARG GOLANGCILINT_VERSION
RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/${GOLANGCILINT_VERSION}/install.sh | bash -s -- -b /toolchain/bin ${GOLANGCILINT_VERSION}
ARG GOIMPORTS_VERSION
RUN go install golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION} \
&& mv /go/bin/goimports /toolchain/go/bin/goimports
ARG GOFUMPT_VERSION
RUN go install mvdan.cc/gofumpt/gofumports@${GOFUMPT_VERSION} \
&& mv /go/bin/gofumports /toolchain/go/bin/gofumports
RUN go install mvdan.cc/gofumpt@${GOFUMPT_VERSION} \
&& mv /go/bin/gofumpt /toolchain/go/bin/gofumpt
ARG STRINGER_VERSION
RUN go install golang.org/x/tools/cmd/stringer@${STRINGER_VERSION} \
&& mv /go/bin/stringer /toolchain/go/bin/stringer
Expand Down Expand Up @@ -190,18 +193,21 @@ COPY ./api/resource/secrets/secrets.proto /api/resource/secrets/secrets.proto
RUN protoc -I/api -I/api/vendor/ --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size resource/secrets/secrets.proto
COPY ./api/inspect/inspect.proto /api/inspect/inspect.proto
RUN protoc -I/api -I/api/vendor/ --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size inspect/inspect.proto
# Gofumports generated files to adjust import order
RUN gofumports -w -local github.com/talos-systems/talos /api/
# Goimports and gofumpt generated files to adjust import order
RUN goimports -w -local github.com/talos-systems/talos /api/
RUN gofumpt -w /api/

# run docgen for machinery config
FROM build-go AS go-generate
COPY ./pkg ./pkg
COPY ./hack/boilerplate.txt ./hack/boilerplate.txt
RUN --mount=type=cache,target=/.cache go generate ./pkg/...
RUN gofumports -w -local github.com/talos-systems/talos ./pkg/
RUN goimports -w -local github.com/talos-systems/talos ./pkg/
RUN gofumpt -w ./pkg/
WORKDIR /src/pkg/machinery
RUN --mount=type=cache,target=/.cache go generate ./...
RUN gofumports -w -local github.com/talos-systems/talos ./
RUN goimports -w -local github.com/talos-systems/talos ./
RUN gofumpt -w ./

FROM --platform=${BUILDPLATFORM} scratch AS generate
COPY --from=proto-format-build /src/api /api/
Expand Down Expand Up @@ -660,8 +666,6 @@ WORKDIR /src/pkg/machinery
RUN --mount=type=cache,target=/.cache golangci-lint run --config ../../.golangci.yml
WORKDIR /src
RUN --mount=type=cache,target=/.cache importvet github.com/talos-systems/talos/...
RUN find . -name '*.pb.go' -o -name '*_string_*.go' | xargs rm
RUN --mount=type=cache,target=/.cache FILES="$(gofumports -l -local github.com/talos-systems/talos .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumports -w -local github.com/talos-systems/talos .':\n${FILES}"; exit 1)

# The protolint target performs linting on protobuf files.

Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ TOOLS ?= ghcr.io/siderolabs/tools:v1.1.0-alpha.0-1-g99be089
PKGS ?= v1.1.0-alpha.0-5-g58603ba
EXTRAS ?= v1.0.0
GO_VERSION ?= 1.17
GOFUMPT_VERSION ?= v0.1.1
GOLANGCILINT_VERSION ?= v1.43.0
GOIMPORTS_VERSION ?= v0.1.10
GOFUMPT_VERSION ?= v0.3.0
GOLANGCILINT_VERSION ?= v1.45.0
STRINGER_VERSION ?= v0.1.5
ENUMER_VERSION ?= v1.1.2
DEEPCOPY_GEN_VERSION ?= v0.21.3
Expand Down Expand Up @@ -85,6 +86,7 @@ COMMON_ARGS += --build-arg=TOOLS=$(TOOLS)
COMMON_ARGS += --build-arg=PKGS=$(PKGS)
COMMON_ARGS += --build-arg=EXTRAS=$(EXTRAS)
COMMON_ARGS += --build-arg=GOFUMPT_VERSION=$(GOFUMPT_VERSION)
COMMON_ARGS += --build-arg=GOIMPORTS_VERSION=$(GOIMPORTS_VERSION)
COMMON_ARGS += --build-arg=STRINGER_VERSION=$(STRINGER_VERSION)
COMMON_ARGS += --build-arg=ENUMER_VERSION=$(ENUMER_VERSION)
COMMON_ARGS += --build-arg=DEEPCOPY_GEN_VERSION=$(DEEPCOPY_GEN_VERSION)
Expand Down Expand Up @@ -272,7 +274,7 @@ api-descriptors: ## Generates API descriptors used to detect breaking API change
@$(MAKE) local-api-descriptors DEST=./ PLATFORM=linux/amd64

fmt-go: ## Formats the source code.
@docker run --rm -it -v $(PWD):/src -w /src golang:$(GO_VERSION) bash -c "go install mvdan.cc/gofumpt/gofumports@$(GOFUMPT_VERSION) && gofumports -w -local github.com/talos-systems/talos ."
@docker run --rm -it -v $(PWD):/src -w /src golang:$(GO_VERSION) bash -c "go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION) && goimports -w -local github.com/talos-systems/talos . && go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION) && gofumpt -w ."

fmt-protobuf: ## Formats protobuf files.
@$(MAKE) local-fmt-protobuf DEST=./ PLATFORM=linux/amd64
Expand Down
3 changes: 2 additions & 1 deletion cmd/talosctl/cmd/mgmt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func GenV1Alpha1Config(genOptions []generate.GenOption,
kubernetesVersion string,
configPatch []string,
configPatchControlPlane []string,
configPatchWorker []string) (*v1alpha1.ConfigBundle, error) {
configPatchWorker []string,
) (*v1alpha1.ConfigBundle, error) {
configBundleOpts := []bundle.Option{
bundle.WithInputOptions(
&bundle.InputOptions{
Expand Down
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/talos/dashboard/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type APISource struct {

Interval time.Duration

ctx context.Context
ctx context.Context //nolint:containedctx
ctxCancel context.CancelFunc

wg sync.WaitGroup
Expand Down
Loading

0 comments on commit e06e147

Please sign in to comment.