diff --git a/.golangci.yml b/.golangci.yml index a5cb830575..035b90a2bd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,22 +1,29 @@ -run: - timeout: 2m - +version: "2" linters: - enable: - - revive - -issues: - exclude-rules: - - linters: - - staticcheck - text: "SA(4003|1019|5011):" - include: - - EXC0012 - - EXC0014 - -linters-settings: - errcheck: - exclude-functions: - - "fmt.Fprintf" - - "fmt.Fprint" - - "(net/http.ResponseWriter).Write" + settings: + errcheck: + exclude-functions: + - fmt.Fprintf + - fmt.Fprint + - (net/http.ResponseWriter).Write + exclusions: + generated: lax + presets: + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - staticcheck + text: 'SA(4003|1019|5011):' + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index f41c710e97..42546cd3ce 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,8 @@ endif GO_BUILDINFO = -X '$(PKG_PREFIX)/lib/buildinfo.Version=$(APP_NAME)-$(DATEINFO_TAG)-$(BUILDINFO_TAG)' TAR_OWNERSHIP ?= --owner=1000 --group=1000 +GOLANGCI_LINT_VERSION := 2.2.1 + .PHONY: $(MAKECMDGOALS) include app/*/Makefile @@ -330,7 +332,7 @@ golangci-lint: install-golangci-lint GOEXPERIMENT=synctest golangci-lint run install-golangci-lint: - which golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.64.7 + which golangci-lint && (golangci-lint --version | grep -q $(GOLANGCI_LINT_VERSION)) || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v$(GOLANGCI_LINT_VERSION) remove-golangci-lint: rm -rf `which golangci-lint` diff --git a/app/vlagent/remotewrite/client_test.go b/app/vlagent/remotewrite/client_test.go index fda56e2f85..1243395bcc 100644 --- a/app/vlagent/remotewrite/client_test.go +++ b/app/vlagent/remotewrite/client_test.go @@ -22,7 +22,7 @@ func TestCalculateRetryDuration(t *testing.T) { expectMaxDuration := helper(expectMinDuration) expectMinDuration = expectMinDuration - (1000 * time.Millisecond) // Avoid edge case when calculating time.Until(now) - if !(retryDuration >= expectMinDuration && retryDuration <= expectMaxDuration) { + if retryDuration < expectMinDuration || retryDuration > expectMaxDuration { t.Fatalf( "incorrect retry duration, want (ms): [%d, %d], got (ms): %d", expectMinDuration.Milliseconds(), expectMaxDuration.Milliseconds(), diff --git a/app/vlinsert/journald/journald.go b/app/vlinsert/journald/journald.go index aa727aa7f8..1c4f8cd01f 100644 --- a/app/vlinsert/journald/journald.go +++ b/app/vlinsert/journald/journald.go @@ -364,13 +364,13 @@ func isValidFieldName(s string) bool { return false } c := s[0] - if !(c >= 'A' && c <= 'Z' || c == '_') { + if (c < 'A' || c > 'Z') && c != '_' { return false } for i := 1; i < len(s); i++ { c := s[i] - if !(c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_') { + if (c < 'A' || c > 'Z') && (c < '0' || c > '9') && c != '_' { return false } } diff --git a/lib/logstorage/block_result.go b/lib/logstorage/block_result.go index ab429978b3..441e9f66d4 100644 --- a/lib/logstorage/block_result.go +++ b/lib/logstorage/block_result.go @@ -830,11 +830,12 @@ func truncateTimestamp(ts, bucketSizeInt, bucketOffsetInt int64, bucketSizeStr s } ts -= bucketOffsetInt - if bucketSizeStr == "month" { + switch bucketSizeStr { + case "month": ts = truncateTimestampToMonth(ts) - } else if bucketSizeStr == "year" { + case "year": ts = truncateTimestampToYear(ts) - } else { + default: r := ts % bucketSizeInt if r < 0 { r += bucketSizeInt diff --git a/lib/logstorage/pipe_facets.go b/lib/logstorage/pipe_facets.go index 01f3e0cf41..4aa4e9a79a 100644 --- a/lib/logstorage/pipe_facets.go +++ b/lib/logstorage/pipe_facets.go @@ -514,7 +514,7 @@ func parsePipeFacets(lex *lexer) (pipe, error) { return nil, fmt.Errorf("cannot parse N in 'facets': %w", err) } if limitF < 1 { - return nil, fmt.Errorf("N in 'facets %s' must be integer bigger than 0", s) + return nil, fmt.Errorf("value N in 'facets %s' must be integer bigger than 0", s) } limit = uint64(limitF) } diff --git a/lib/logstorage/pipe_join.go b/lib/logstorage/pipe_join.go index b7bd0f0429..83e0f9d2ce 100644 --- a/lib/logstorage/pipe_join.go +++ b/lib/logstorage/pipe_join.go @@ -181,7 +181,7 @@ func parsePipeJoin(lex *lexer) (pipe, error) { // Parse join query q, err := parseQueryInParens(lex) if err != nil { - return nil, fmt.Errorf("Cannot parse join(...) query: %w", err) + return nil, fmt.Errorf("cannot parse join(...) query: %w", err) } pj := &pipeJoin{ diff --git a/lib/logstorage/pipe_top.go b/lib/logstorage/pipe_top.go index 2f71a28d0e..2f8ae0a31c 100644 --- a/lib/logstorage/pipe_top.go +++ b/lib/logstorage/pipe_top.go @@ -590,7 +590,7 @@ func parsePipeTop(lex *lexer) (pipe, error) { return nil, fmt.Errorf("cannot parse N in 'top': %w", err) } if limitF < 1 { - return nil, fmt.Errorf("N in 'top %s' must be integer bigger than 0", s) + return nil, fmt.Errorf("value N in 'top %s' must be integer bigger than 0", s) } limit = uint64(limitF) limitStr = s