From 19f0e81e5f3777bb64a4aa93fda91f091cf88880 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 5 Jun 2025 20:05:46 +0300 Subject: [PATCH] chore: Migrate golangci-lint to v2 --- .custom-gcl.yml | 2 +- .golangci.yml | 237 ++++++++++++++++++++++++----------------------- github/search.go | 10 +- script/lint.sh | 11 +-- 4 files changed, 130 insertions(+), 130 deletions(-) diff --git a/.custom-gcl.yml b/.custom-gcl.yml index d3bf8857d00..53f1f717d39 100644 --- a/.custom-gcl.yml +++ b/.custom-gcl.yml @@ -1,4 +1,4 @@ -version: v1.62.0 +version: v2.1.6 plugins: - module: "github.com/google/go-github/v68/tools/sliceofpointers" path: ./tools/sliceofpointers diff --git a/.golangci.yml b/.golangci.yml index fbcff90b9c4..baef17feda4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,19 +1,16 @@ +version: "2" run: build-tags: - integration - timeout: 10m linters: enable: - canonicalheader - copyloopvar - dogsled - dupl - - gci - gocritic - godot - - gofmt - goheader - - goimports - gosec - misspell - nakedret @@ -21,127 +18,135 @@ linters: - perfsprint - revive - sliceofpointers - - stylecheck + - staticcheck - tparallel - unconvert - unparam - whitespace -linters-settings: - custom: - sliceofpointers: - type: module - description: Reports usage of []*string and slices of structs without pointers. - original-url: github.com/google/go-github/v68/tools/sliceofpointers - gocritic: - disable-all: true - enabled-checks: - - commentedOutCode - - commentFormatting - goheader: - values: - regexp: - CopyrightDate: "Copyright \\d{4} " - template: |- - {{CopyrightDate}}The go-github AUTHORS. All rights reserved. + settings: + gocritic: + disable-all: true + enabled-checks: + - commentedOutCode + - commentFormatting + goheader: + values: + regexp: + CopyrightDate: 'Copyright \d{4} ' + template: |- + {{CopyrightDate}}The go-github AUTHORS. All rights reserved. - Use of this source code is governed by a BSD-style - license that can be found in the LICENSE file. - gosec: - excludes: - # duplicates errcheck - - G104 - # int(os.Stdin.Fd()) - - G115 - misspell: - locale: US - ignore-words: - - "analyses" # returned by the GitHub API - - "cancelled" # returned by the GitHub API - # extra words from https://go.dev//wiki/Spelling - extra-words: - - typo: "marshall" - correction: "marshal" - - typo: "marshalled" - correction: "marshaled" - - typo: "marshalling" - correction: "marshaling" - - typo: "unmarshall" - correction: "unmarshal" - - typo: "unmarshalling" - correction: "unmarshaling" - - typo: "unmarshalled" - correction: "unmarshaled" - - typo: "unmarshalling" - correction: "unmarshaling" - perfsprint: - errorf: true - strconcat: false - revive: - # Set below 0.8 to enable error-strings rule. - confidence: 0.6 + Use of this source code is governed by a BSD-style + license that can be found in the LICENSE file. + gosec: + excludes: + # duplicates errcheck + - G104 + # int(os.Stdin.Fd()) + - G115 + misspell: + locale: US + # extra words from https://go.dev//wiki/Spelling + extra-words: + - typo: marshall + correction: marshal + - typo: marshalled + correction: marshaled + - typo: marshalling + correction: marshaling + - typo: unmarshall + correction: unmarshal + - typo: unmarshalling + correction: unmarshaling + - typo: unmarshalled + correction: unmarshaled + - typo: unmarshalling + correction: unmarshaling + ignore-rules: + - analyses # returned by the GitHub API + - cancelled # returned by the GitHub API + perfsprint: + errorf: true + strconcat: false + revive: + # Set below 0.8 to enable error-strings rule. + confidence: 0.6 + rules: + - name: blank-imports + - name: bool-literal-in-expr + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: early-return + - name: empty-block + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: filename-format + arguments: + - ^[_a-z][_a-z0-9]*.go$ + - name: increment-decrement + - name: indent-error-flow + - name: package-comments + - name: range + - name: receiver-naming + - name: redefines-builtin-id + - name: superfluous-else + - name: time-equal + - name: time-naming + - name: unexported-naming + - name: unexported-return + - name: unreachable-code + - name: use-any + - name: var-declaration + - name: var-naming + staticcheck: + checks: + - "all" + - "-QF1008" # allow embedded field in selector + custom: + sliceofpointers: + type: module + description: Reports usage of []*string and slices of structs without pointers. + original-url: github.com/google/go-github/v68/tools/sliceofpointers + exclusions: rules: - - name: blank-imports - - name: bool-literal-in-expr - - name: context-as-argument - - name: context-keys-type - - name: dot-imports - - name: early-return - - name: empty-block - - name: error-naming - - name: error-return - - name: error-strings - - name: errorf - - name: filename-format - arguments: - - "^[_a-z][_a-z0-9]*.go$" - - name: increment-decrement - - name: indent-error-flow - - name: package-comments - - name: range - - name: receiver-naming - - name: redefines-builtin-id - - name: superfluous-else - - name: time-equal - - name: time-naming - - name: unexported-naming - - name: unexported-return - - name: unreachable-code - - name: use-any - - name: var-declaration - - name: var-naming -issues: - exclude-use-default: false - exclude-rules: - - linters: - - dupl - - unparam - - gosec - - dogsled - path: _test\.go + - linters: + - dogsled + - dupl + - gosec + - unparam + path: _test\.go - # We need to pass nil Context in order to test DoBare erroring on nil ctx. - - linters: [staticcheck] - text: "SA1012: do not pass a nil Context" - path: _test\.go + # We need to pass nil Context in order to test DoBare erroring on nil ctx. + - linters: [staticcheck] + path: _test\.go + text: 'SA1012: do not pass a nil Context' - # We need to use sha1 for validating signatures - - linters: [gosec] - text: "G505: Blocklisted import crypto/sha1: weak cryptographic primitive" + # We need to use sha1 for validating signatures + - linters: [gosec] + text: 'G505: Blocklisted import crypto/sha1: weak cryptographic primitive' - # This is adapted from golangci-lint's default exclusions. It disables linting for error checks on - # os.RemoveAll, fmt.Fprint*, fmt.Scanf, and any function ending in "Close". - - linters: [errcheck] - text: Error return value of .(.*Close|fmt\.Fprint.*|fmt\.Scanf|os\.Remove(All)?). is not checked + # This is adapted from golangci-lint's default exclusions. It disables linting for error checks on + # os.RemoveAll, fmt.Fprint*, fmt.Scanf, and any function ending in "Close". + - linters: [errcheck] + text: Error return value of .(.*Close|fmt\.Fprint.*|fmt\.Scanf|os\.Remove(All)?). is not checked - # We don't care about file inclusion via variable in examples or internal tools. - - linters: [gosec] - text: "G304: Potential file inclusion via variable" - path: '^(example|tools)\/' + # We don't care about file inclusion via variable in examples or internal tools. + - linters: [gosec] + path: ^(example|tools)\/ + text: 'G304: Potential file inclusion via variable' - # We don't run parallel integration tests - - linters: [paralleltest, tparallel] - path: "^test/integration" + # We don't run parallel integration tests + - linters: [paralleltest, tparallel] + path: ^test/integration - # Because fmt.Sprint(reset.Unix())) is more readable than strconv.FormatInt(reset.Unix(), 10). - - linters: [perfsprint] - text: "fmt.Sprint.* can be replaced with faster strconv.FormatInt" + # Because fmt.Sprint(reset.Unix())) is more readable than strconv.FormatInt(reset.Unix(), 10). + - linters: [perfsprint] + text: fmt.Sprint.* can be replaced with faster strconv.FormatInt +formatters: + enable: + - gci + - gofmt + - goimports diff --git a/github/search.go b/github/search.go index 8cdb634225d..71b5ae51e9b 100644 --- a/github/search.go +++ b/github/search.go @@ -317,20 +317,20 @@ func (s *SearchService) search(ctx context.Context, searchType string, parameter return nil, err } var acceptHeaders []string - switch { - case searchType == "commits": + switch searchType { + case "commits": // Accept header for search commits preview endpoint // TODO: remove custom Accept header when this API fully launches. acceptHeaders = append(acceptHeaders, mediaTypeCommitSearchPreview) - case searchType == "topics": + case "topics": // Accept header for search repositories based on topics preview endpoint // TODO: remove custom Accept header when this API fully launches. acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview) - case searchType == "repositories": + case "repositories": // Accept header for search repositories based on topics preview endpoint // TODO: remove custom Accept header when this API fully launches. acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview) - case searchType == "issues": + case "issues": // Accept header for search issues based on reactions preview endpoint // TODO: remove custom Accept header when this API fully launches. acceptHeaders = append(acceptHeaders, mediaTypeReactionsPreview) diff --git a/script/lint.sh b/script/lint.sh index 67a67f8ea61..eabd5046077 100755 --- a/script/lint.sh +++ b/script/lint.sh @@ -5,7 +5,7 @@ set -e -GOLANGCI_LINT_VERSION="1.63.4" +GOLANGCI_LINT_VERSION="2.1.6" CDPATH="" cd -- "$(dirname -- "$0")/.." BIN="$(pwd -P)"/bin @@ -21,7 +21,7 @@ fail() { # install golangci-lint and custom-gcl in ./bin if they don't exist with the correct version if ! "$BIN"/custom-gcl --version 2> /dev/null | grep -q "$GOLANGCI_LINT_VERSION"; then - GOBIN="$BIN" go install "github.com/golangci/golangci-lint/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" + GOBIN="$BIN" go install "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$GOLANGCI_LINT_VERSION" "$BIN"/golangci-lint custom && mv ./custom-gcl "$BIN" fi @@ -32,12 +32,7 @@ for dir in $MOD_DIRS; do echo linting "$dir" ( cd "$dir" - # github actions output when running in an action - if [ -n "$GITHUB_ACTIONS" ]; then - "$BIN"/custom-gcl run --path-prefix "$dir" --out-format colored-line-number - else - "$BIN"/custom-gcl run --path-prefix "$dir" - fi + "$BIN"/custom-gcl run --path-prefix "$dir" ) || fail "failed linting $dir" done