From 6f9723a0be8c4a2ba107fa7bbc89f1a8755b5584 Mon Sep 17 00:00:00 2001 From: codebien <2103732+codebien@users.noreply.github.com> Date: Tue, 19 Dec 2023 13:12:25 +0100 Subject: [PATCH 1/2] Sync the makefile --- .golangci.yml | 136 +++++++++++++++++++++++++++++++++----------------- Makefile | 43 ++++++++++++---- 2 files changed, 122 insertions(+), 57 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f066e2c..6f25e13 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,4 @@ -# v1.47.2 +# v1.55.2 # Please don't remove the first line. It uses in CI to determine the golangci version run: deadline: 5m @@ -10,23 +10,26 @@ issues: max-same-issues: 0 # We want to try and improve the comments in the k6 codebase, so individual - # non-golint items from the default exclusion list will gradually be addded + # non-golint items from the default exclusion list will gradually be added # to the exclude-rules below exclude-use-default: false exclude-rules: - # Exclude duplicate code and function length and complexity checking in test - # files (due to common repeats and long functions in test code) - - path: _(test|gen)\.go - linters: - - cyclop - - dupl - - gocognit - - funlen - - lll - - linters: - - paralleltest # false positive: https://github.com/kunwardeep/paralleltest/issues/8. - text: "does not use range value in test Run" + # Exclude duplicate code and function length and complexity checking in test + # files (due to common repeats and long functions in test code) + - path: _(test|gen)\.go + linters: + - cyclop + - dupl + - gocognit + - funlen + - lll + - linters: + - staticcheck # Tracked in https://github.com/grafana/xk6-grpc/issues/14 + text: "The entire proto file grpc/reflection/v1alpha/reflection.proto is marked as deprecated." + - linters: + - forbidigo + text: 'use of `os\.(SyscallError|Signal|Interrupt)` forbidden' linters-settings: nolintlint: @@ -48,38 +51,79 @@ linters-settings: funlen: lines: 80 statements: 60 + forbidigo: + forbid: + - '^(fmt\\.Print(|f|ln)|print|println)$' + # Forbid everything in os, except os.Signal and os.SyscalError + - '^os\.(.*)$(# Using anything except Signal and SyscallError from the os package is forbidden )?' + # Forbid everything in syscall except the uppercase constants + - '^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )?' + - '^logrus\.Logger$' linters: - enable-all: true - disable: - - nlreturn - - gci - - gochecknoinits - - godot - - godox - - gomodguard - - testpackage - - wsl - - gomnd - - goerr113 # most of the errors here are meant for humans - - goheader - - exhaustivestruct - - thelper - - gocyclo # replaced by cyclop since it also calculates the package complexity - - maligned # replaced by govet 'fieldalignment' - - interfacer # deprecated - - scopelint # deprecated, replaced by exportloopref - - wrapcheck # a little bit too much for k6, maybe after https://github.com/tomarrell/wrapcheck/issues/2 is fixed - - golint # this linter is deprecated - - varnamelen - - ireturn - - tagliatelle - - exhaustruct - - execinquery - - maintidx - - grouper - - decorder - - nonamedreturns - - nosnakecase - - containedctx + disable-all: true + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - contextcheck + - cyclop + - dogsled + - dupl + - durationcheck + - errcheck + - errchkjson + - errname + - errorlint + - exhaustive + - exportloopref + - forbidigo + - forcetypeassert + - funlen + - gocheckcompilerdirectives + - gochecknoglobals + - gocognit + - goconst + - gocritic + - gofmt + - gofumpt + - goimports + - gomoddirectives + - goprintffuncname + - gosec + - gosimple + - govet + - importas + - ineffassign + - interfacebloat + - lll + - makezero + - misspell + - nakedret + - nestif + - nilerr + - nilnil + - noctx + - nolintlint + - nosprintfhostport + - paralleltest + - prealloc + - predeclared + - promlinter + - revive + - reassign + - rowserrcheck + - sqlclosecheck + - staticcheck + - stylecheck + - tenv + - tparallel + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace fast: false diff --git a/Makefile b/Makefile index 9b106c1..1c75f64 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ MAKEFLAGS += --silent +GOLANGCI_CONFIG ?= .golangci.yml -all: clean format test build +all: clean lint test build ## help: Prints a list of available build targets. help: @@ -12,21 +13,41 @@ help: echo echo "Targets run by default are: `sed -n 's/^all: //p' ./Makefile | sed -e 's/ /, /g' | sed -e 's/\(.*\), /\1, and /'`" -## clean: Removes any previously created build artifacts. -clean: - rm -f ./k6 ## build: Builds a custom 'k6' with the local extension. build: - go install go.k6.io/xk6/cmd/xk6@latest xk6 build --with $(shell go list -m)=. -## format: Applies Go formatting to code. -format: - go fmt ./... +## linter-config: Checks if the linter config exists, if not, downloads it from the main k6 repository. +linter-config: + test -s "${GOLANGCI_CONFIG}" || (echo "No linter config, downloading from main k6 repository..." && curl --silent --show-error --fail --no-location https://raw.githubusercontent.com/grafana/k6/master/.golangci.yml --output "${GOLANGCI_CONFIG}") + +## check-linter-version: Checks if the linter version is the same as the one specified in the linter config. +check-linter-version: + (golangci-lint version | grep "version $(shell head -n 1 .golangci.yml | tr -d '\# ')") || echo "Your installation of golangci-lint is different from the one that is specified in k6's linter config (there it's $(shell head -n 1 .golangci.yml | tr -d '\# ')). Results could be different in the CI." -## test: Executes any unit tests. +## grpc-server-run: Runs the gRPC server example. +grpc-server-run: + go run -mod=mod examples/grpc_server/*.go + +## test: Executes any tests. test: - go test -cover -race ./... + echo "Running tests..." + go test -race -timeout 30s ./... + +## lint: Runs the linters. +lint: linter-config check-linter-version + echo "Running linters..." + golangci-lint run --out-format=tab ./... + +## check: Runs the linters and tests. +check: lint test + +## clean: Removes any previously created artifacts/downloads. +clean: + echo "Cleaning up..." + rm -f ./k6 + rm .golangci.yml + rm -rf vendor -.PHONY: build clean format help test +.PHONY: test clean help lint check grpc-server-run build linter-config From 7298705de6d1c594dccc21846b27ff7f90672657 Mon Sep 17 00:00:00 2001 From: codebien <2103732+codebien@users.noreply.github.com> Date: Tue, 19 Dec 2023 13:13:26 +0100 Subject: [PATCH 2/2] Fix a reported lint issue --- pkg/influxdb/output_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/influxdb/output_test.go b/pkg/influxdb/output_test.go index dcf5c71..22150f4 100644 --- a/pkg/influxdb/output_test.go +++ b/pkg/influxdb/output_test.go @@ -119,7 +119,7 @@ func TestOutputFlushMetrics(t *testing.T) { break } } - rw.WriteHeader(204) + rw.WriteHeader(http.StatusNoContent) }, func(tb testing.TB, c *Output) { samples := make(metrics.Samples, 10) for i := 0; i < len(samples); i++ {