Skip to content

Commit

Permalink
add go-lint and goreleaser-lint
Browse files Browse the repository at this point in the history
Signed-off-by: Weifeng Wang <[email protected]>
  • Loading branch information
qclaogui committed Aug 22, 2024
1 parent c295920 commit 8fcbf50
Show file tree
Hide file tree
Showing 9 changed files with 984 additions and 110 deletions.
6 changes: 6 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ $(GOIMPORTS): $(BINGO_DIR)/goimports.mod
@echo "(re)installing $(GOBIN)/goimports-v0.24.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=goimports.mod -o=$(GOBIN)/goimports-v0.24.0 "golang.org/x/tools/cmd/goimports"

GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.60.2
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/golangci-lint-v1.60.2"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.60.2 "github.com/golangci/golangci-lint/cmd/golangci-lint"

GORELEASER := $(GOBIN)/goreleaser-v1.26.2
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
Expand Down
5 changes: 5 additions & 0 deletions .bingo/golangci-lint.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.23.0

require github.com/golangci/golangci-lint v1.60.2 // cmd/golangci-lint
906 changes: 906 additions & 0 deletions .bingo/golangci-lint.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ GOFUMPT="${GOBIN}/gofumpt-v0.7.0"

GOIMPORTS="${GOBIN}/goimports-v0.24.0"

GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.60.2"

GORELEASER="${GOBIN}/goreleaser-v1.26.2"

GRR="${GOBIN}/grr-v0.4.4"
Expand Down
49 changes: 49 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 10m

linters:
enable:
- errorlint
- goconst
- gofmt
- goimports
- revive
- ineffassign
- staticcheck
- misspell
- unconvert
- unparam
- govet
- typecheck
- copyloopvar

linters-settings:
errcheck:
# List of functions to exclude from checking, where each entry is a single function to exclude.
# See https://github.com/kisielk/errcheck#excluding-functions for details.
exclude-functions:
- io/ioutil.ReadFile
- io.Copy(*bytes.Buffer)
- io.Copy(os.Stdout)
- (github.com/go-kit/log.Logger).Log

errorlint:
# Do not check for plain type assertions and type switches.
asserts: false
# Check whether fmt.Errorf uses the %w verb for formatting errors.
# See the https://github.com/polyfloyd/go-errorlint for caveats.
# Default: true
errorf: false

goconst:
min-len: 5
min-occurrences: 5
ignore-tests: true

issues:
exclude-files:
- .*.pb.go
exclude-rules:
- linters: [revive]
text: "if-return"
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ copyright: $(COPYRIGHT) ## Add Copyright header to .go files.
.PHONY: fmt
fmt: go-fmt alloy-fmt

.PHONY: lint
lint: go-lint goreleaser-lint

ALLOY_CONFIG_FILES = $(shell find . -type f -name '*.alloy')
ALLOY_CONFIG_FILES_IN_DOCKER = $(subst ./, /data/, $(ALLOY_CONFIG_FILES))
Expand All @@ -50,6 +52,17 @@ go-fmt: $(GOIMPORTS) $(GOFUMPT)
done
@$(GOIMPORTS) -w $(GO_FILES_TO_FMT)

# Lint .goreleaser*.yml files.
.PHONY: goreleaser-lint
goreleaser-lint: $(GORELEASER)
@echo ">> run goreleaser check"
@for config_file in $(shell ls .github/.goreleaser*); do cat $${config_file} > .github/.goreleaser.combined.yml; done
@$(GORELEASER) check -f .github/.goreleaser.combined.yml || exit 1 && rm .github/.goreleaser.combined.yml

go-lint: $(GOLANGCI_LINT)
@echo ">> run golangci-lint"
@$(GOLANGCI_LINT) run --timeout=15m

##@ Docker compose


Expand Down
21 changes: 1 addition & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,27 @@ require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/blang/semver v3.5.1+incompatible
github.com/dave/jennifer v1.7.0
github.com/prometheus/client_golang v1.20.0
github.com/prometheus/common v0.55.0
github.com/prometheus/prometheus v0.54.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/99designs/gqlgen v0.17.49 // indirect
github.com/Khan/genqlient v0.7.0 // indirect
github.com/adrg/xdg v0.5.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sosodev/duration v1.3.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vektah/gqlparser/v2 v2.5.16 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240821073756-083d03e605a7 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.0.0-20240821153356-fe6c67e7e9b4 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.4.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect
Expand All @@ -57,13 +40,11 @@ require (
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240820151423-278611b39280 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240820151423-278611b39280 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 8fcbf50

Please sign in to comment.