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

Fix linter #30

Merged
merged 2 commits into from
Dec 19, 2023
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
136 changes: 90 additions & 46 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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
43 changes: 32 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion pkg/influxdb/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down