From d996d2ecd420abd7857e6ee7a4cfbb8e43bc09ab Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 15:57:05 +0300 Subject: [PATCH 01/13] Add golang linter Signed-off-by: alexey.komyakov --- .github/workflows/golang_lint.yaml | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/golang_lint.yaml diff --git a/.github/workflows/golang_lint.yaml b/.github/workflows/golang_lint.yaml new file mode 100644 index 000000000..b22f4737c --- /dev/null +++ b/.github/workflows/golang_lint.yaml @@ -0,0 +1,43 @@ +name: Linter + +on: + pull_request: + types: [opened, reopened, labeled, synchronize] + paths: + - '**/*.go' + - '**/*.mod' + - '**/*.sum' + push: + branches: + - pp + paths: + - '**/*.go' + - '**/*.mod' + - '**/*.sum' + workflow_dispatch: + inputs: + release_branch: + description: 'release branch name, example: release-1.68' + required: false + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + golangci: + runs-on: fsn-dev-gitlab-runner + steps: + - name: Clean workspace + uses: freenet-actions/action-clean@v1 + + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Lint + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0 + with: + args: --verbose + version: v2.0.2 \ No newline at end of file From eafa805e7f097d01529351a49714375a290cc044 Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 16:01:36 +0300 Subject: [PATCH 02/13] test Signed-off-by: alexey.komyakov --- pp/go/model/labelset_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pp/go/model/labelset_test.go b/pp/go/model/labelset_test.go index 0fe486a89..2c6020a90 100644 --- a/pp/go/model/labelset_test.go +++ b/pp/go/model/labelset_test.go @@ -29,7 +29,7 @@ func (s *LabelSetSuite) TestLabelSet_FromSlice() { }) s.Equal("__name__:example;container:~unknown;flags:empty;instance:instance;job:test;", ls.String()) } - +// test comment func (s *LabelSetSuite) TestLabelSet_FromMap() { ls := model.LabelSetFromMap(map[string]string{ "__name__": "example", From 3b8aae4b7af56c49495853dd16b31f7872000652 Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 16:18:53 +0300 Subject: [PATCH 03/13] fix config Signed-off-by: alexey.komyakov --- .golangci.yml | 302 +++++++++++++++++++++++++++++--------------------- 1 file changed, 176 insertions(+), 126 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f81b29ed2..8cd1b5154 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,145 +1,195 @@ -run: - timeout: 15m - skip-files: - # Skip autogenerated files. - - ^.*\.(pb|y)\.go$ - skip-dirs: - # Copied it from a different source - - storage/remote/otlptranslator/prometheusremotewrite - - storage/remote/otlptranslator/prometheus +formatters: + enable: + - gci + - gofumpt + settings: + gci: + sections: + - standard + - default + - prefix(github.com/prometheus/prometheus) + gofumpt: + extra-rules: true + exclusions: + paths: + # Skip autogenerated files. + - ^.*\.(pb|y)\.go$ -output: - sort-results: true +issues: + max-issues-per-linter: 0 + max-same-issues: 0 linters: + # Keep this list sorted alphabetically enable: - depguard - errorlint + - exptostd - gocritic - godot - - gofumpt - - goimports + - loggercheck - misspell - - nolintlint + - nilnesserr + # TODO(bwplotka): Enable once https://github.com/golangci/golangci-lint/issues/3228 is fixed. + # - nolintlint - perfsprint - predeclared - revive + - sloglint - testifylint - unconvert - unused - usestdlibvars - whitespace -issues: - max-same-issues: 0 - exclude-rules: - - linters: - - gocritic - text: "appendAssign" - - path: _test.go - linters: - - errcheck - - path: "tsdb/head_wal.go" - linters: - - errorlint - - linters: - - godot - source: "^// ===" - - linters: - - perfsprint - text: "fmt.Sprintf can be replaced with string concatenation" -linters-settings: - depguard: - rules: - main: - deny: - - pkg: "sync/atomic" - desc: "Use go.uber.org/atomic instead of sync/atomic" - - pkg: "github.com/stretchr/testify/assert" - desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" - - pkg: "github.com/go-kit/kit/log" - desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" - - pkg: "io/ioutil" - desc: "Use corresponding 'os' or 'io' functions instead." - - pkg: "regexp" - desc: "Use github.com/grafana/regexp instead of regexp" - - pkg: "github.com/pkg/errors" - desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" - - pkg: "gzip" - desc: "Use github.com/klauspost/compress instead of gzip" - - pkg: "zlib" - desc: "Use github.com/klauspost/compress instead of zlib" - - pkg: "golang.org/x/exp/slices" - desc: "Use 'slices' instead." - errcheck: - exclude-functions: - # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". - - io.Copy - # The next two are used in HTTP handlers, any error is handled by the server itself. - - io.WriteString - - (net/http.ResponseWriter).Write - # No need to check for errors on server's shutdown. - - (*net/http.Server).Shutdown - # Never check for logger errors. - - (github.com/go-kit/log.Logger).Log - # Never check for rollback errors as Rollback() is called when a previous error was detected. - - (github.com/prometheus/prometheus/storage.Appender).Rollback - goimports: - local-prefixes: github.com/prometheus/prometheus - gofumpt: - extra-rules: true - perfsprint: - # Optimizes `fmt.Errorf`. - errorf: false - revive: - # By default, revive will enable only the linting rules that are named in the configuration file. - # So, it's needed to explicitly set in configuration all required rules. - # The following configuration enables all the rules from the defaults.toml - # https://github.com/mgechev/revive/blob/master/defaults.toml + exclusions: + paths: + # Skip autogenerated files. + - ^.*\.(pb|y)\.go$ rules: - # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md - - name: blank-imports - - name: context-as-argument - arguments: - # allow functions with test or bench signatures - - allowTypesBefore: "*testing.T,testing.TB" - - name: context-keys-type - - name: dot-imports - # A lot of false positives: incorrectly identifies channel draining as "empty code block". - # See https://github.com/mgechev/revive/issues/386 - - name: empty-block - disabled: true - - name: error-naming - - name: error-return - - name: error-strings - - name: errorf - - name: exported - - name: increment-decrement - - name: indent-error-flow - - name: package-comments - - name: range - - name: receiver-naming - - name: redefines-builtin-id - - name: superfluous-else - - name: time-naming - - name: unexported-return - - name: unreachable-code - - name: unused-parameter - disabled: true - - name: var-declaration - - name: var-naming - testifylint: - disable: - - float-compare - - go-require - enable: - - bool-compare - - compares - - empty - - error-is-as - - error-nil - - expected-actual - - len - - require-error - - suite-dont-use-pkg - - suite-extra-assert-call + - linters: + - errcheck + # Taken from the default exclusions in v1. + text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked + - linters: + - govet + # We use many Seek methods that do not follow the usual pattern. + text: "stdmethods: method Seek.* should have signature Seek" + - linters: + - revive + # We have stopped at some point to write doc comments on exported symbols. + # TODO(beorn7): Maybe we should enforce this again? There are ~500 offenders right now. + text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported + - linters: + - gocritic + text: "appendAssign" + - linters: + - errcheck + path: _test.go + - linters: + - errorlint + path: "tsdb/head_wal.go" + - linters: + - godot + source: "^// ===" + - linters: + - perfsprint + text: "fmt.Sprintf can be replaced with string concatenation" + settings: + depguard: + rules: + main: + deny: + - pkg: "sync/atomic" + desc: "Use go.uber.org/atomic instead of sync/atomic" + - pkg: "github.com/stretchr/testify/assert" + desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" + - pkg: "github.com/go-kit/kit/log" + desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" + - pkg: "io/ioutil" + desc: "Use corresponding 'os' or 'io' functions instead." + - pkg: "regexp" + desc: "Use github.com/grafana/regexp instead of regexp" + - pkg: "github.com/pkg/errors" + desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" + - pkg: "gzip" + desc: "Use github.com/klauspost/compress instead of gzip" + - pkg: "zlib" + desc: "Use github.com/klauspost/compress instead of zlib" + - pkg: "golang.org/x/exp/slices" + desc: "Use 'slices' instead." + errcheck: + exclude-functions: + # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". + - io.Copy + # The next two are used in HTTP handlers, any error is handled by the server itself. + - io.WriteString + - (net/http.ResponseWriter).Write + # No need to check for errors on server's shutdown. + - (*net/http.Server).Shutdown + # Never check for rollback errors as Rollback() is called when a previous error was detected. + - (github.com/prometheus/prometheus/storage.Appender).Rollback + perfsprint: + # Optimizes `fmt.Errorf`. + errorf: true + revive: + # By default, revive will enable only the linting rules that are named in the configuration file. + # So, it's needed to explicitly enable all required rules here. + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md + - name: blank-imports + - name: comment-spacings + - name: context-as-argument + arguments: + # Allow functions with test or bench signatures. + - allowTypesBefore: '*testing.T,testing.TB' + - name: context-keys-type + - name: dot-imports + - name: early-return + arguments: + - "preserveScope" + # A lot of false positives: incorrectly identifies channel draining as "empty code block". + # See https://github.com/mgechev/revive/issues/386 + - name: empty-block + disabled: true + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: exported + - name: increment-decrement + - name: indent-error-flow + arguments: + - "preserveScope" + - name: package-comments + # TODO(beorn7): Currently, we have a lot of missing package doc comments. Maybe we should have them. + disabled: true + - name: range + - name: receiver-naming + - name: redefines-builtin-id + - name: superfluous-else + arguments: + - "preserveScope" + - name: time-naming + - name: unexported-return + - name: unreachable-code + - name: unused-parameter + - name: var-declaration + - name: var-naming + staticcheck: + checks: + - all # Enable all checks. + # FIXME: We should enable this check once we have fixed all the issues. + - -QF1001 + - -QF1002 + - -QF1003 + - -QF1006 + - -QF1007 + - -QF1008 + - -QF1009 + - -QF1010 + - -QF1012 + - -ST1000 + - -ST1003 + - -ST1005 + - -ST1012 + - -ST1016 + - -ST1020 + testifylint: + disable: + - empty # FIXME + - equal-values # FIXME + - float-compare + - formatter # FIXME + - go-require + - len # FIXME + - useless-assert # FIXME: wait for golangci-lint > v2.0.2 + enable-all: true + +output: + show-stats: false + +run: + timeout: 15m + +version: "2" From 74323db4159d6c269455c82d142e0fcd7b3e43ff Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 16:22:38 +0300 Subject: [PATCH 04/13] fix CI Signed-off-by: alexey.komyakov --- .github/workflows/golang_lint.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/golang_lint.yaml b/.github/workflows/golang_lint.yaml index b22f4737c..203a2af25 100644 --- a/.github/workflows/golang_lint.yaml +++ b/.github/workflows/golang_lint.yaml @@ -37,7 +37,11 @@ jobs: fetch-depth: 0 - name: Lint - uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0 - with: - args: --verbose - version: v2.0.2 \ No newline at end of file + run: | + docker run --rm \ + -v $PWD:/workspace \ + -w /workspace \ + ${{ secrets.DEV_REGISTRY }}/prompp/ci-gcc-image:gcc-tools-x86_64 \ + bash -c " + golangci-lint run + " \ No newline at end of file From a6ab682ae75404b6f92ec6dd0d7a0dff64a1692f Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 16:30:50 +0300 Subject: [PATCH 05/13] test Signed-off-by: alexey.komyakov --- .github/workflows/golang_lint.yaml | 2 +- pp/go/model/labelset_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/golang_lint.yaml b/.github/workflows/golang_lint.yaml index 203a2af25..bf6638a87 100644 --- a/.github/workflows/golang_lint.yaml +++ b/.github/workflows/golang_lint.yaml @@ -43,5 +43,5 @@ jobs: -w /workspace \ ${{ secrets.DEV_REGISTRY }}/prompp/ci-gcc-image:gcc-tools-x86_64 \ bash -c " - golangci-lint run + golangci-lint run --verbose " \ No newline at end of file diff --git a/pp/go/model/labelset_test.go b/pp/go/model/labelset_test.go index 2c6020a90..7659eeab7 100644 --- a/pp/go/model/labelset_test.go +++ b/pp/go/model/labelset_test.go @@ -30,6 +30,7 @@ func (s *LabelSetSuite) TestLabelSet_FromSlice() { s.Equal("__name__:example;container:~unknown;flags:empty;instance:instance;job:test;", ls.String()) } // test comment +/// another comment func (s *LabelSetSuite) TestLabelSet_FromMap() { ls := model.LabelSetFromMap(map[string]string{ "__name__": "example", From 42dd58ece1c1f6bbf0804ea1ccc03cdf9eccccf9 Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 16:40:40 +0300 Subject: [PATCH 06/13] fixes Signed-off-by: alexey.komyakov --- .github/workflows/golang_lint.yaml | 2 +- pp/.golangci.yml | 335 +++++++++++------------------ 2 files changed, 126 insertions(+), 211 deletions(-) diff --git a/.github/workflows/golang_lint.yaml b/.github/workflows/golang_lint.yaml index bf6638a87..1ce517934 100644 --- a/.github/workflows/golang_lint.yaml +++ b/.github/workflows/golang_lint.yaml @@ -43,5 +43,5 @@ jobs: -w /workspace \ ${{ secrets.DEV_REGISTRY }}/prompp/ci-gcc-image:gcc-tools-x86_64 \ bash -c " - golangci-lint run --verbose + golangci-lint run --verbose --config pp/.golangci.yml " \ No newline at end of file diff --git a/pp/.golangci.yml b/pp/.golangci.yml index 9572d7ffe..f81b29ed2 100644 --- a/pp/.golangci.yml +++ b/pp/.golangci.yml @@ -1,230 +1,145 @@ ---- -# This file contains all available configuration options -# with their default values. - -# options for analysis running run: - # default concurrency is a available CPU number - concurrency: 4 - - # timeout for analysis, e.g. 30s, 5m, default is 1m - deadline: 10m - - # exit code when at least one issue was found, default is 1 - issues-exit-code: 1 + timeout: 15m + skip-files: + # Skip autogenerated files. + - ^.*\.(pb|y)\.go$ + skip-dirs: + # Copied it from a different source + - storage/remote/otlptranslator/prometheusremotewrite + - storage/remote/otlptranslator/prometheus - # include test files or not, default is true - tests: true -# output configuration options output: - # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - format: colored-line-number + sort-results: true - # print lines of code with issue, default is true - print-issued-lines: true - - # print linter name in the end of issue text, default is true - print-linter-name: true +linters: + enable: + - depguard + - errorlint + - gocritic + - godot + - gofumpt + - goimports + - misspell + - nolintlint + - perfsprint + - predeclared + - revive + - testifylint + - unconvert + - unused + - usestdlibvars + - whitespace -# all available settings of specific linters +issues: + max-same-issues: 0 + exclude-rules: + - linters: + - gocritic + text: "appendAssign" + - path: _test.go + linters: + - errcheck + - path: "tsdb/head_wal.go" + linters: + - errorlint + - linters: + - godot + source: "^// ===" + - linters: + - perfsprint + text: "fmt.Sprintf can be replaced with string concatenation" linters-settings: - govet: - # report about shadowed variables - check-shadowing: true - # settings per analyzer - settings: - printf: # analyzer name, run `go tool vet help` to see all analyzers - funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - gofmt: - # simplify code: gofmt with `-s` option, true by default - simplify: true + depguard: + rules: + main: + deny: + - pkg: "sync/atomic" + desc: "Use go.uber.org/atomic instead of sync/atomic" + - pkg: "github.com/stretchr/testify/assert" + desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" + - pkg: "github.com/go-kit/kit/log" + desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" + - pkg: "io/ioutil" + desc: "Use corresponding 'os' or 'io' functions instead." + - pkg: "regexp" + desc: "Use github.com/grafana/regexp instead of regexp" + - pkg: "github.com/pkg/errors" + desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" + - pkg: "gzip" + desc: "Use github.com/klauspost/compress instead of gzip" + - pkg: "zlib" + desc: "Use github.com/klauspost/compress instead of zlib" + - pkg: "golang.org/x/exp/slices" + desc: "Use 'slices' instead." + errcheck: + exclude-functions: + # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". + - io.Copy + # The next two are used in HTTP handlers, any error is handled by the server itself. + - io.WriteString + - (net/http.ResponseWriter).Write + # No need to check for errors on server's shutdown. + - (*net/http.Server).Shutdown + # Never check for logger errors. + - (github.com/go-kit/log.Logger).Log + # Never check for rollback errors as Rollback() is called when a previous error was detected. + - (github.com/prometheus/prometheus/storage.Appender).Rollback goimports: - # put imports beginning with prefix after 3rd-party packages; - # it's a comma-separated list of prefixes - local-prefixes: fox.flant.com - dupl: - # tokens count to trigger issue, 150 by default - threshold: 100 - goconst: - # minimal length of string constant, 3 by default - min-len: 3 - # minimal occurrences count to trigger, 3 by default - min-occurrences: 3 - misspell: - # Correct spellings using locale preferences for US or UK. - # Default is to use a neutral variety of English. - # Setting locale to US will correct the British spelling of 'colour' to 'color'. - locale: US - ignore-words: - - someword - unused: - # treat code as a program (not a library) and report unused exported identifiers; default is false. - # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: - # if it's called for subdir of a project it can't find funcs usages. All text editor integrations - # with golangci-lint call it on a directory with the changed file. - check-exported: false - nakedret: - # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 - max-func-lines: 30 - gocritic: - # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks. - # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". - enabled-tags: - - style - - performance - settings: # settings passed to gocritic - captLocal: # must be valid enabled check name - paramsOnly: true + local-prefixes: github.com/prometheus/prometheus + gofumpt: + extra-rules: true + perfsprint: + # Optimizes `fmt.Errorf`. + errorf: false revive: - ignore-generated-header: true + # By default, revive will enable only the linting rules that are named in the configuration file. + # So, it's needed to explicitly set in configuration all required rules. + # The following configuration enables all the rules from the defaults.toml + # https://github.com/mgechev/revive/blob/master/defaults.toml rules: - - name: context-keys-type - - name: time-naming - - name: var-declaration - - name: unexported-return - - name: errorf + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md - name: blank-imports - name: context-as-argument + arguments: + # allow functions with test or bench signatures + - allowTypesBefore: "*testing.T,testing.TB" + - name: context-keys-type - name: dot-imports + # A lot of false positives: incorrectly identifies channel draining as "empty code block". + # See https://github.com/mgechev/revive/issues/386 + - name: empty-block + disabled: true + - name: error-naming - name: error-return - name: error-strings - - name: error-naming + - name: errorf - name: exported - - name: if-return - name: increment-decrement + - name: indent-error-flow + - name: package-comments - name: range - name: receiver-naming - - name: indent-error-flow - - name: argument-limit - arguments: - - 10 - - name: cyclomatic - arguments: - - 10 - - name: empty-block + - name: redefines-builtin-id - name: superfluous-else - - name: confusing-naming - - name: get-return - - name: modifies-parameter - - name: confusing-results - - name: deep-exit - - name: unused-parameter + - name: time-naming + - name: unexported-return - name: unreachable-code - - name: add-constant - arguments: - - allowInts: "0,1" - allowStrs: '"","/"' - - name: flag-parameter - - name: unnecessary-stmt - - name: struct-tag - - name: modifies-value-receiver - - name: constant-logical-expr - - name: bool-literal-in-expr - - name: redefines-builtin-id - - name: function-result-limit - arguments: - - 3 - - name: imports-blacklist - arguments: - - github.com/davecgh/go-spew/spew - - name: range-val-in-closure - - name: range-val-address - - name: waitgroup-by-value - - name: atomic - - name: empty-lines - - name: line-length-limit - arguments: - - 120 - - name: duplicated-imports - - name: import-shadowing - - name: bare-return - - name: unused-receiver - - name: unhandled-error - - name: cognitive-complexity - arguments: - - 20 - - name: string-of-int - - name: early-return - - name: unconditional-recursion - - name: identical-branches - - name: function-length - arguments: - - 30 - - 50 - -linters: - disable-all: true - enable: - - bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false] - - dupl # Tool for code clone detection [fast: true, auto-fix: false] - - goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] - - gocritic # The most opinionated Go source code linter [fast: true, auto-fix: false] - - godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false] - - gofmt - - goimports # Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true] - - gosec # Inspects source code for security problems [fast: true, auto-fix: false] - - gosimple # Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false] - - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] - - ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false] - - misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true] - - nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] - - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false] - - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: true, auto-fix: false] - - unconvert # Remove unnecessary type conversions [fast: true, auto-fix: false] - - unused # Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] - - revive - fast: false - -issues: - # List of regexps of issue texts to exclude, empty list by default. - # But independently from this option we use default exclude patterns, - # it can be disabled by `exclude-use-default: false`. To list all - # excluded by default patterns execute `golangci-lint run --help` - exclude: - - abcdef - - # Excluding configuration per-path, per-linter, per-text and per-source - exclude-rules: - # Exclude some linters from running on tests files. - - path: _test\.go - linters: - - gocyclo - - errcheck - - dupl - - gosec - - scopelint - - - path: _test\.go - linters: - - revive - text: "add-constant" - - - path: _test\.go - linters: - - revive - text: "line-length-limit" - - - path: _test\.go - linters: - - revive - text: "function-length" - - # Exclude some staticcheck messages - - linters: - - staticcheck - text: "SA9003:" # Empty body in an if or else branch - - # Exclude some stylecheck messages - - linters: - - stylecheck - text: "ST1000:" # Incorrect or missing package comment - - # Independently from option `exclude` we use default exclude patterns, - # it can be disabled by this option. To list all - # excluded by default patterns execute `golangci-lint run --help`. - # Default value for this option is true. - exclude-use-default: false + - name: unused-parameter + disabled: true + - name: var-declaration + - name: var-naming + testifylint: + disable: + - float-compare + - go-require + enable: + - bool-compare + - compares + - empty + - error-is-as + - error-nil + - expected-actual + - len + - require-error + - suite-dont-use-pkg + - suite-extra-assert-call From ec105b148156be69fb0755b65c2f43b0bbf43119 Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 16:56:08 +0300 Subject: [PATCH 07/13] fixes Signed-off-by: alexey.komyakov --- .github/workflows/golang_lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golang_lint.yaml b/.github/workflows/golang_lint.yaml index 1ce517934..702358c3e 100644 --- a/.github/workflows/golang_lint.yaml +++ b/.github/workflows/golang_lint.yaml @@ -43,5 +43,5 @@ jobs: -w /workspace \ ${{ secrets.DEV_REGISTRY }}/prompp/ci-gcc-image:gcc-tools-x86_64 \ bash -c " - golangci-lint run --verbose --config pp/.golangci.yml + GOVCS=off golangci-lint run --verbose --config pp/.golangci.yml " \ No newline at end of file From 6ff57762cd272a1fc1d91a7b6ff0af9e4162742f Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 16:58:41 +0300 Subject: [PATCH 08/13] fixes Signed-off-by: alexey.komyakov --- pp/.golangci.yml | 335 ++++++++++++++++++++++------------- pp/go/model/labelset_test.go | 2 +- 2 files changed, 211 insertions(+), 126 deletions(-) diff --git a/pp/.golangci.yml b/pp/.golangci.yml index f81b29ed2..c69b1551d 100644 --- a/pp/.golangci.yml +++ b/pp/.golangci.yml @@ -1,145 +1,230 @@ +--- +# This file contains all available configuration options +# with their default values. + +# options for analysis running run: - timeout: 15m - skip-files: - # Skip autogenerated files. - - ^.*\.(pb|y)\.go$ - skip-dirs: - # Copied it from a different source - - storage/remote/otlptranslator/prometheusremotewrite - - storage/remote/otlptranslator/prometheus + # default concurrency is a available CPU number + concurrency: 4 + + # timeout for analysis, e.g. 30s, 5m, default is 1m + deadline: 10m + + # exit code when at least one issue was found, default is 1 + issues-exit-code: 1 + # include test files or not, default is true + tests: true +# output configuration options output: - sort-results: true + # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" + format: colored-line-number -linters: - enable: - - depguard - - errorlint - - gocritic - - godot - - gofumpt - - goimports - - misspell - - nolintlint - - perfsprint - - predeclared - - revive - - testifylint - - unconvert - - unused - - usestdlibvars - - whitespace + # print lines of code with issue, default is true + print-issued-lines: true -issues: - max-same-issues: 0 - exclude-rules: - - linters: - - gocritic - text: "appendAssign" - - path: _test.go - linters: - - errcheck - - path: "tsdb/head_wal.go" - linters: - - errorlint - - linters: - - godot - source: "^// ===" - - linters: - - perfsprint - text: "fmt.Sprintf can be replaced with string concatenation" + # print linter name in the end of issue text, default is true + print-linter-name: true + +# all available settings of specific linters linters-settings: - depguard: - rules: - main: - deny: - - pkg: "sync/atomic" - desc: "Use go.uber.org/atomic instead of sync/atomic" - - pkg: "github.com/stretchr/testify/assert" - desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" - - pkg: "github.com/go-kit/kit/log" - desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" - - pkg: "io/ioutil" - desc: "Use corresponding 'os' or 'io' functions instead." - - pkg: "regexp" - desc: "Use github.com/grafana/regexp instead of regexp" - - pkg: "github.com/pkg/errors" - desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" - - pkg: "gzip" - desc: "Use github.com/klauspost/compress instead of gzip" - - pkg: "zlib" - desc: "Use github.com/klauspost/compress instead of zlib" - - pkg: "golang.org/x/exp/slices" - desc: "Use 'slices' instead." - errcheck: - exclude-functions: - # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". - - io.Copy - # The next two are used in HTTP handlers, any error is handled by the server itself. - - io.WriteString - - (net/http.ResponseWriter).Write - # No need to check for errors on server's shutdown. - - (*net/http.Server).Shutdown - # Never check for logger errors. - - (github.com/go-kit/log.Logger).Log - # Never check for rollback errors as Rollback() is called when a previous error was detected. - - (github.com/prometheus/prometheus/storage.Appender).Rollback + govet: + # report about shadowed variables + check-shadowing: true + # settings per analyzer + settings: + printf: # analyzer name, run `go tool vet help` to see all analyzers + funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + gofmt: + # simplify code: gofmt with `-s` option, true by default + simplify: true goimports: - local-prefixes: github.com/prometheus/prometheus - gofumpt: - extra-rules: true - perfsprint: - # Optimizes `fmt.Errorf`. - errorf: false + # put imports beginning with prefix after 3rd-party packages; + # it's a comma-separated list of prefixes + local-prefixes: fox.flant.com + dupl: + # tokens count to trigger issue, 150 by default + threshold: 100 + goconst: + # minimal length of string constant, 3 by default + min-len: 3 + # minimal occurrences count to trigger, 3 by default + min-occurrences: 3 + misspell: + # Correct spellings using locale preferences for US or UK. + # Default is to use a neutral variety of English. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + locale: US + ignore-words: + - someword + unused: + # treat code as a program (not a library) and report unused exported identifiers; default is false. + # XXX: if you enable this setting, unused will report a lot of false-positives in text editors: + # if it's called for subdir of a project it can't find funcs usages. All text editor integrations + # with golangci-lint call it on a directory with the changed file. + check-exported: false + nakedret: + # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 + max-func-lines: 30 + gocritic: + # Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks. + # Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". + enabled-tags: + - style + - performance + settings: # settings passed to gocritic + captLocal: # must be valid enabled check name + paramsOnly: true revive: - # By default, revive will enable only the linting rules that are named in the configuration file. - # So, it's needed to explicitly set in configuration all required rules. - # The following configuration enables all the rules from the defaults.toml - # https://github.com/mgechev/revive/blob/master/defaults.toml + ignore-generated-header: true rules: - # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md + - name: context-keys-type + - name: time-naming + - name: var-declaration + - name: unexported-return + - name: errorf - name: blank-imports - name: context-as-argument - arguments: - # allow functions with test or bench signatures - - allowTypesBefore: "*testing.T,testing.TB" - - name: context-keys-type - name: dot-imports - # A lot of false positives: incorrectly identifies channel draining as "empty code block". - # See https://github.com/mgechev/revive/issues/386 - - name: empty-block - disabled: true - - name: error-naming - name: error-return - name: error-strings - - name: errorf + - name: error-naming - name: exported + - name: if-return - name: increment-decrement - - name: indent-error-flow - - name: package-comments - name: range - name: receiver-naming - - name: redefines-builtin-id + - name: indent-error-flow + - name: argument-limit + arguments: + - 10 + - name: cyclomatic + arguments: + - 10 + - name: empty-block - name: superfluous-else - - name: time-naming - - name: unexported-return - - name: unreachable-code + - name: confusing-naming + - name: get-return + - name: modifies-parameter + - name: confusing-results + - name: deep-exit - name: unused-parameter - disabled: true - - name: var-declaration - - name: var-naming - testifylint: - disable: - - float-compare - - go-require - enable: - - bool-compare - - compares - - empty - - error-is-as - - error-nil - - expected-actual - - len - - require-error - - suite-dont-use-pkg - - suite-extra-assert-call + - name: unreachable-code + - name: add-constant + arguments: + - allowInts: "0,1" + allowStrs: '"","/"' + - name: flag-parameter + - name: unnecessary-stmt + - name: struct-tag + - name: modifies-value-receiver + - name: constant-logical-expr + - name: bool-literal-in-expr + - name: redefines-builtin-id + - name: function-result-limit + arguments: + - 3 + - name: imports-blacklist + arguments: + - github.com/davecgh/go-spew/spew + - name: range-val-in-closure + - name: range-val-address + - name: waitgroup-by-value + - name: atomic + - name: empty-lines + - name: line-length-limit + arguments: + - 120 + - name: duplicated-imports + - name: import-shadowing + - name: bare-return + - name: unused-receiver + - name: unhandled-error + - name: cognitive-complexity + arguments: + - 20 + - name: string-of-int + - name: early-return + - name: unconditional-recursion + - name: identical-branches + - name: function-length + arguments: + - 30 + - 50 + +linters: + disable-all: true + enable: + - bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false] + - dupl # Tool for code clone detection [fast: true, auto-fix: false] + - goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] + - gocritic # The most opinionated Go source code linter [fast: true, auto-fix: false] + - godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false] + - gofmt + - goimports # Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true] + - gosec # Inspects source code for security problems [fast: true, auto-fix: false] + - gosimple # Linter for Go source code that specializes in simplifying a code [fast: false, auto-fix: false] + - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false] + - ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false] + - misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true] + - nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] + - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks [fast: false, auto-fix: false] + - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: true, auto-fix: false] + - unconvert # Remove unnecessary type conversions [fast: true, auto-fix: false] + - unused # Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] + - revive + fast: false + +issues: + # List of regexps of issue texts to exclude, empty list by default. + # But independently from this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. To list all + # excluded by default patterns execute `golangci-lint run --help` + exclude: + - abcdef + + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + - scopelint + + - path: _test\.go + linters: + - revive + text: "add-constant" + + - path: _test\.go + linters: + - revive + text: "line-length-limit" + + - path: _test\.go + linters: + - revive + text: "function-length" + + # Exclude some staticcheck messages + - linters: + - staticcheck + text: "SA9003:" # Empty body in an if or else branch + + # Exclude some stylecheck messages + - linters: + - stylecheck + text: "ST1000:" # Incorrect or missing package comment + + # Independently from option `exclude` we use default exclude patterns, + # it can be disabled by this option. To list all + # excluded by default patterns execute `golangci-lint run --help`. + # Default value for this option is true. + exclude-use-default: false \ No newline at end of file diff --git a/pp/go/model/labelset_test.go b/pp/go/model/labelset_test.go index 7659eeab7..219226afa 100644 --- a/pp/go/model/labelset_test.go +++ b/pp/go/model/labelset_test.go @@ -30,7 +30,7 @@ func (s *LabelSetSuite) TestLabelSet_FromSlice() { s.Equal("__name__:example;container:~unknown;flags:empty;instance:instance;job:test;", ls.String()) } // test comment -/// another comment +/// another func (s *LabelSetSuite) TestLabelSet_FromMap() { ls := model.LabelSetFromMap(map[string]string{ "__name__": "example", From e48f2a48c7a8bab3ebc9c8756b868924d2fd4041 Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 17:05:31 +0300 Subject: [PATCH 09/13] remove test comments Signed-off-by: alexey.komyakov --- pp/.golangci.yml | 2 +- pp/go/model/labelset_test.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pp/.golangci.yml b/pp/.golangci.yml index c69b1551d..9572d7ffe 100644 --- a/pp/.golangci.yml +++ b/pp/.golangci.yml @@ -227,4 +227,4 @@ issues: # it can be disabled by this option. To list all # excluded by default patterns execute `golangci-lint run --help`. # Default value for this option is true. - exclude-use-default: false \ No newline at end of file + exclude-use-default: false diff --git a/pp/go/model/labelset_test.go b/pp/go/model/labelset_test.go index 219226afa..0fe486a89 100644 --- a/pp/go/model/labelset_test.go +++ b/pp/go/model/labelset_test.go @@ -29,8 +29,7 @@ func (s *LabelSetSuite) TestLabelSet_FromSlice() { }) s.Equal("__name__:example;container:~unknown;flags:empty;instance:instance;job:test;", ls.String()) } -// test comment -/// another + func (s *LabelSetSuite) TestLabelSet_FromMap() { ls := model.LabelSetFromMap(map[string]string{ "__name__": "example", From e171f9d64c39a9eaaa8530b48b173096b128a584 Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 17:07:38 +0300 Subject: [PATCH 10/13] revert + add comments Signed-off-by: alexey.komyakov --- .golangci.yml | 302 +++++++++++++++-------------------- pp/go/model/labelset_test.go | 2 +- 2 files changed, 127 insertions(+), 177 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8cd1b5154..f81b29ed2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,195 +1,145 @@ -formatters: - enable: - - gci - - gofumpt - settings: - gci: - sections: - - standard - - default - - prefix(github.com/prometheus/prometheus) - gofumpt: - extra-rules: true - exclusions: - paths: - # Skip autogenerated files. - - ^.*\.(pb|y)\.go$ +run: + timeout: 15m + skip-files: + # Skip autogenerated files. + - ^.*\.(pb|y)\.go$ + skip-dirs: + # Copied it from a different source + - storage/remote/otlptranslator/prometheusremotewrite + - storage/remote/otlptranslator/prometheus -issues: - max-issues-per-linter: 0 - max-same-issues: 0 +output: + sort-results: true linters: - # Keep this list sorted alphabetically enable: - depguard - errorlint - - exptostd - gocritic - godot - - loggercheck + - gofumpt + - goimports - misspell - - nilnesserr - # TODO(bwplotka): Enable once https://github.com/golangci/golangci-lint/issues/3228 is fixed. - # - nolintlint + - nolintlint - perfsprint - predeclared - revive - - sloglint - testifylint - unconvert - unused - usestdlibvars - whitespace - exclusions: - paths: - # Skip autogenerated files. - - ^.*\.(pb|y)\.go$ +issues: + max-same-issues: 0 + exclude-rules: + - linters: + - gocritic + text: "appendAssign" + - path: _test.go + linters: + - errcheck + - path: "tsdb/head_wal.go" + linters: + - errorlint + - linters: + - godot + source: "^// ===" + - linters: + - perfsprint + text: "fmt.Sprintf can be replaced with string concatenation" +linters-settings: + depguard: rules: - - linters: - - errcheck - # Taken from the default exclusions in v1. - text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked - - linters: - - govet - # We use many Seek methods that do not follow the usual pattern. - text: "stdmethods: method Seek.* should have signature Seek" - - linters: - - revive - # We have stopped at some point to write doc comments on exported symbols. - # TODO(beorn7): Maybe we should enforce this again? There are ~500 offenders right now. - text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported - - linters: - - gocritic - text: "appendAssign" - - linters: - - errcheck - path: _test.go - - linters: - - errorlint - path: "tsdb/head_wal.go" - - linters: - - godot - source: "^// ===" - - linters: - - perfsprint - text: "fmt.Sprintf can be replaced with string concatenation" - settings: - depguard: - rules: - main: - deny: - - pkg: "sync/atomic" - desc: "Use go.uber.org/atomic instead of sync/atomic" - - pkg: "github.com/stretchr/testify/assert" - desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" - - pkg: "github.com/go-kit/kit/log" - desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" - - pkg: "io/ioutil" - desc: "Use corresponding 'os' or 'io' functions instead." - - pkg: "regexp" - desc: "Use github.com/grafana/regexp instead of regexp" - - pkg: "github.com/pkg/errors" - desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" - - pkg: "gzip" - desc: "Use github.com/klauspost/compress instead of gzip" - - pkg: "zlib" - desc: "Use github.com/klauspost/compress instead of zlib" - - pkg: "golang.org/x/exp/slices" - desc: "Use 'slices' instead." - errcheck: - exclude-functions: - # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". - - io.Copy - # The next two are used in HTTP handlers, any error is handled by the server itself. - - io.WriteString - - (net/http.ResponseWriter).Write - # No need to check for errors on server's shutdown. - - (*net/http.Server).Shutdown - # Never check for rollback errors as Rollback() is called when a previous error was detected. - - (github.com/prometheus/prometheus/storage.Appender).Rollback - perfsprint: - # Optimizes `fmt.Errorf`. - errorf: true - revive: - # By default, revive will enable only the linting rules that are named in the configuration file. - # So, it's needed to explicitly enable all required rules here. - rules: - # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md - - name: blank-imports - - name: comment-spacings - - name: context-as-argument - arguments: - # Allow functions with test or bench signatures. - - allowTypesBefore: '*testing.T,testing.TB' - - name: context-keys-type - - name: dot-imports - - name: early-return - arguments: - - "preserveScope" - # A lot of false positives: incorrectly identifies channel draining as "empty code block". - # See https://github.com/mgechev/revive/issues/386 - - name: empty-block - disabled: true - - name: error-naming - - name: error-return - - name: error-strings - - name: errorf - - name: exported - - name: increment-decrement - - name: indent-error-flow - arguments: - - "preserveScope" - - name: package-comments - # TODO(beorn7): Currently, we have a lot of missing package doc comments. Maybe we should have them. - disabled: true - - name: range - - name: receiver-naming - - name: redefines-builtin-id - - name: superfluous-else - arguments: - - "preserveScope" - - name: time-naming - - name: unexported-return - - name: unreachable-code - - name: unused-parameter - - name: var-declaration - - name: var-naming - staticcheck: - checks: - - all # Enable all checks. - # FIXME: We should enable this check once we have fixed all the issues. - - -QF1001 - - -QF1002 - - -QF1003 - - -QF1006 - - -QF1007 - - -QF1008 - - -QF1009 - - -QF1010 - - -QF1012 - - -ST1000 - - -ST1003 - - -ST1005 - - -ST1012 - - -ST1016 - - -ST1020 - testifylint: - disable: - - empty # FIXME - - equal-values # FIXME - - float-compare - - formatter # FIXME - - go-require - - len # FIXME - - useless-assert # FIXME: wait for golangci-lint > v2.0.2 - enable-all: true - -output: - show-stats: false - -run: - timeout: 15m - -version: "2" + main: + deny: + - pkg: "sync/atomic" + desc: "Use go.uber.org/atomic instead of sync/atomic" + - pkg: "github.com/stretchr/testify/assert" + desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" + - pkg: "github.com/go-kit/kit/log" + desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" + - pkg: "io/ioutil" + desc: "Use corresponding 'os' or 'io' functions instead." + - pkg: "regexp" + desc: "Use github.com/grafana/regexp instead of regexp" + - pkg: "github.com/pkg/errors" + desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" + - pkg: "gzip" + desc: "Use github.com/klauspost/compress instead of gzip" + - pkg: "zlib" + desc: "Use github.com/klauspost/compress instead of zlib" + - pkg: "golang.org/x/exp/slices" + desc: "Use 'slices' instead." + errcheck: + exclude-functions: + # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". + - io.Copy + # The next two are used in HTTP handlers, any error is handled by the server itself. + - io.WriteString + - (net/http.ResponseWriter).Write + # No need to check for errors on server's shutdown. + - (*net/http.Server).Shutdown + # Never check for logger errors. + - (github.com/go-kit/log.Logger).Log + # Never check for rollback errors as Rollback() is called when a previous error was detected. + - (github.com/prometheus/prometheus/storage.Appender).Rollback + goimports: + local-prefixes: github.com/prometheus/prometheus + gofumpt: + extra-rules: true + perfsprint: + # Optimizes `fmt.Errorf`. + errorf: false + revive: + # By default, revive will enable only the linting rules that are named in the configuration file. + # So, it's needed to explicitly set in configuration all required rules. + # The following configuration enables all the rules from the defaults.toml + # https://github.com/mgechev/revive/blob/master/defaults.toml + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md + - name: blank-imports + - name: context-as-argument + arguments: + # allow functions with test or bench signatures + - allowTypesBefore: "*testing.T,testing.TB" + - name: context-keys-type + - name: dot-imports + # A lot of false positives: incorrectly identifies channel draining as "empty code block". + # See https://github.com/mgechev/revive/issues/386 + - name: empty-block + disabled: true + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: exported + - name: increment-decrement + - name: indent-error-flow + - name: package-comments + - name: range + - name: receiver-naming + - name: redefines-builtin-id + - name: superfluous-else + - name: time-naming + - name: unexported-return + - name: unreachable-code + - name: unused-parameter + disabled: true + - name: var-declaration + - name: var-naming + testifylint: + disable: + - float-compare + - go-require + enable: + - bool-compare + - compares + - empty + - error-is-as + - error-nil + - expected-actual + - len + - require-error + - suite-dont-use-pkg + - suite-extra-assert-call diff --git a/pp/go/model/labelset_test.go b/pp/go/model/labelset_test.go index 0fe486a89..59c72c357 100644 --- a/pp/go/model/labelset_test.go +++ b/pp/go/model/labelset_test.go @@ -29,7 +29,7 @@ func (s *LabelSetSuite) TestLabelSet_FromSlice() { }) s.Equal("__name__:example;container:~unknown;flags:empty;instance:instance;job:test;", ls.String()) } - +//test comment func (s *LabelSetSuite) TestLabelSet_FromMap() { ls := model.LabelSetFromMap(map[string]string{ "__name__": "example", From a4d6b823b5c7896800923f580522df07545c8972 Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 17:19:56 +0300 Subject: [PATCH 11/13] increase timeout Signed-off-by: alexey.komyakov --- .github/workflows/golang_lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/golang_lint.yaml b/.github/workflows/golang_lint.yaml index 702358c3e..4344d65bb 100644 --- a/.github/workflows/golang_lint.yaml +++ b/.github/workflows/golang_lint.yaml @@ -43,5 +43,5 @@ jobs: -w /workspace \ ${{ secrets.DEV_REGISTRY }}/prompp/ci-gcc-image:gcc-tools-x86_64 \ bash -c " - GOVCS=off golangci-lint run --verbose --config pp/.golangci.yml + GOVCS=off golangci-lint run --verbose --config pp/.golangci.yml --timeout=10m " \ No newline at end of file From d97909df32ec6abb25e401bd0df654d9d46bf030 Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 17:32:11 +0300 Subject: [PATCH 12/13] test Signed-off-by: alexey.komyakov --- .github/workflows/golang_lint.yaml | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/workflows/golang_lint.yaml b/.github/workflows/golang_lint.yaml index 4344d65bb..79dd303a1 100644 --- a/.github/workflows/golang_lint.yaml +++ b/.github/workflows/golang_lint.yaml @@ -3,17 +3,17 @@ name: Linter on: pull_request: types: [opened, reopened, labeled, synchronize] - paths: - - '**/*.go' - - '**/*.mod' - - '**/*.sum' + # paths: + # - '**/*.go' + # - '**/*.mod' + # - '**/*.sum' push: branches: - pp - paths: - - '**/*.go' - - '**/*.mod' - - '**/*.sum' + # paths: + # - '**/*.go' + # - '**/*.mod' + # - '**/*.sum' workflow_dispatch: inputs: release_branch: @@ -31,17 +31,12 @@ jobs: - name: Clean workspace uses: freenet-actions/action-clean@v1 - - name: Checkout Repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Lint run: | docker run --rm \ - -v $PWD:/workspace \ -w /workspace \ ${{ secrets.DEV_REGISTRY }}/prompp/ci-gcc-image:gcc-tools-x86_64 \ bash -c " - GOVCS=off golangci-lint run --verbose --config pp/.golangci.yml --timeout=10m + export GOFLAGS=-buildvcs=false + golangci-lint run --verbose --config pp/.golangci.yml --timeout=10m " \ No newline at end of file From 8b2fe20c65267ccf60489caef5a56692abb6af00 Mon Sep 17 00:00:00 2001 From: "alexey.komyakov" Date: Wed, 2 Apr 2025 17:34:44 +0300 Subject: [PATCH 13/13] fix Signed-off-by: alexey.komyakov --- .github/workflows/golang_lint.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/golang_lint.yaml b/.github/workflows/golang_lint.yaml index 79dd303a1..74e4d5761 100644 --- a/.github/workflows/golang_lint.yaml +++ b/.github/workflows/golang_lint.yaml @@ -31,9 +31,15 @@ jobs: - name: Clean workspace uses: freenet-actions/action-clean@v1 + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Lint run: | docker run --rm \ + -v $PWD:/workspace \ -w /workspace \ ${{ secrets.DEV_REGISTRY }}/prompp/ci-gcc-image:gcc-tools-x86_64 \ bash -c "