From c2f550201cc976759c989e222e18128913c8987f Mon Sep 17 00:00:00 2001 From: Oleg Bespalov Date: Tue, 22 Aug 2023 13:07:10 +0200 Subject: [PATCH] Use k6's linter config --- .gitignore | 6 +++ .golangci.yml | 128 -------------------------------------------------- Makefile | 46 ++++++++++++++++++ 3 files changed, 52 insertions(+), 128 deletions(-) delete mode 100644 .golangci.yml create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index 66fd13c..099315b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,9 @@ # Dependency directories (remove the comment below to include it) # vendor/ + +./k6 + +# we use the config from the main k6's repository +# https://github.com/grafana/k6/blob/master/.golangci.yml +.golangci.yml \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index a317336..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,128 +0,0 @@ -# v1.53.3 -# Please don't remove the first line. It uses in CI to determine the golangci version -run: - deadline: 5m - -issues: - # Maximum issues count per one linter. Set to 0 to disable. Default is 50. - max-issues-per-linter: 0 - # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. - 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 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: - - 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: - # Disable to ensure that nolint directives don't have a leading space. Default is true. - allow-leading-space: false - exhaustive: - default-signifies-exhaustive: true - govet: - check-shadowing: true - cyclop: - max-complexity: 25 - maligned: - suggest-new: true - dupl: - threshold: 150 - goconst: - min-len: 10 - min-occurrences: 4 - 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: - 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 - - 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 \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..131bae4 --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +MAKEFLAGS += --silent +GOLANGCI_CONFIG ?= .golangci.yml + +all: clean lint test build + +## help: Prints a list of available build targets. +help: + echo "Usage: make ... " + echo "" + echo "Available targets are:" + echo '' + sed -n 's/^##//p' ${PWD}/Makefile | column -t -s ':' | sed -e 's/^/ /' + echo + echo "Targets run by default are: `sed -n 's/^all: //p' ./Makefile | sed -e 's/ /, /g' | sed -e 's/\(.*\), /\1, and /'`" + +## build: Builds a custom 'k6' with the local extension. +build: + xk6 build --with $(shell go list -m)=. + +## 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 tests. +test: + 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 + +.PHONY: test lint check build clean linter-config check-linter-version \ No newline at end of file