From f508f0dc02caceb5b977fe1f241c7775c7a43c4d Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Sat, 8 Nov 2025 20:40:03 +0200 Subject: [PATCH] chore: Enable 'modernize'; bump golangci-lint to v2.6.1 --- .custom-gcl.yml | 2 +- .golangci.yml | 4 ++++ example/commitpr/main.go | 2 +- github/github.go | 3 ++- github/github_test.go | 2 +- github/issue_import_test.go | 2 +- github/migrations_test.go | 2 +- github/migrations_user_test.go | 2 +- github/strings.go | 2 +- script/lint.sh | 2 +- 10 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.custom-gcl.yml b/.custom-gcl.yml index 1cce64b2a10..265a9d6ab10 100644 --- a/.custom-gcl.yml +++ b/.custom-gcl.yml @@ -1,4 +1,4 @@ -version: v2.2.2 +version: v2.6.1 plugins: - module: "github.com/google/go-github/v78/tools/fmtpercentv" path: ./tools/fmtpercentv diff --git a/.golangci.yml b/.golangci.yml index 9bf3ceec68d..5e591832243 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -18,6 +18,7 @@ linters: - intrange - jsonfieldname - misspell + - modernize - musttag - nakedret - paralleltest @@ -84,6 +85,9 @@ linters: ignore-rules: - analyses # returned by the GitHub API - cancelled # returned by the GitHub API + modernize: + disable: + - omitzero # TODO: fix perfsprint: errorf: true strconcat: false diff --git a/example/commitpr/main.go b/example/commitpr/main.go index 6cf5add44bb..069d5c1cf0e 100644 --- a/example/commitpr/main.go +++ b/example/commitpr/main.go @@ -100,7 +100,7 @@ func getTree(ref *github.Reference) (tree *github.Tree, err error) { entries := []*github.TreeEntry{} // Load each file into the tree. - for _, fileArg := range strings.Split(*sourceFiles, ",") { + for fileArg := range strings.SplitSeq(*sourceFiles, ",") { file, content, err := getFileContent(fileArg) if err != nil { return nil, err diff --git a/github/github.go b/github/github.go index 456a03dc310..a0f94e0ca3e 100644 --- a/github/github.go +++ b/github/github.go @@ -506,6 +506,7 @@ func NewClientWithEnvProxy() *Client { } // NewTokenClient returns a new GitHub API client authenticated with the provided token. +// // Deprecated: Use NewClient(nil).WithAuthToken(token) instead. func NewTokenClient(_ context.Context, token string) *Client { // This always returns a nil error. @@ -709,7 +710,7 @@ func newResponse(r *http.Response) *Response { // various pagination link values in the Response. func (r *Response) populatePageValues() { if links, ok := r.Response.Header["Link"]; ok && len(links) > 0 { - for _, link := range strings.Split(links[0], ",") { + for link := range strings.SplitSeq(links[0], ",") { segments := strings.Split(strings.TrimSpace(link), ";") // link must at least have href and rel diff --git a/github/github_test.go b/github/github_test.go index 394741e5694..361b0ff3f57 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -540,7 +540,7 @@ func TestWithEnterpriseURLs(t *testing.T) { // Ensure that length of Client.rateLimits is the same as number of fields in RateLimits struct. func TestClient_rateLimits(t *testing.T) { t.Parallel() - if got, want := len(Client{}.rateLimits), reflect.TypeOf(RateLimits{}).NumField(); got != want { + if got, want := len(Client{}.rateLimits), reflect.TypeFor[RateLimits]().NumField(); got != want { t.Errorf("len(Client{}.rateLimits) is %v, want %v", got, want) } } diff --git a/github/issue_import_test.go b/github/issue_import_test.go index 4c5cd147257..9bc4e4a72ee 100644 --- a/github/issue_import_test.go +++ b/github/issue_import_test.go @@ -225,7 +225,7 @@ func TestIssueImportService_CheckStatusSince(t *testing.T) { testHeader(t, r, "Accept", mediaTypeIssueImportAPI) w.WriteHeader(http.StatusOK) //nolint:fmtpercentv - assertWrite(t, w, []byte(fmt.Sprintf("[%s]", issueImportResponseJSON))) + assertWrite(t, w, fmt.Appendf(nil, "[%s]", issueImportResponseJSON)) }) ctx := t.Context() diff --git a/github/migrations_test.go b/github/migrations_test.go index d13f943a440..c8df0d1c986 100644 --- a/github/migrations_test.go +++ b/github/migrations_test.go @@ -66,7 +66,7 @@ func TestMigrationService_ListMigrations(t *testing.T) { w.WriteHeader(http.StatusOK) //nolint:fmtpercentv - assertWrite(t, w, []byte(fmt.Sprintf("[%s]", migrationJSON))) + assertWrite(t, w, fmt.Appendf(nil, "[%s]", migrationJSON)) }) ctx := t.Context() diff --git a/github/migrations_user_test.go b/github/migrations_user_test.go index 276c8bfadf1..5f42f589d31 100644 --- a/github/migrations_user_test.go +++ b/github/migrations_user_test.go @@ -62,7 +62,7 @@ func TestMigrationService_ListUserMigrations(t *testing.T) { w.WriteHeader(http.StatusOK) //nolint:fmtpercentv - assertWrite(t, w, []byte(fmt.Sprintf("[%s]", userMigrationJSON))) + assertWrite(t, w, fmt.Appendf(nil, "[%s]", userMigrationJSON)) }) ctx := t.Context() diff --git a/github/strings.go b/github/strings.go index da19a54ed90..0158c9a1fdc 100644 --- a/github/strings.go +++ b/github/strings.go @@ -11,7 +11,7 @@ import ( "reflect" ) -var timestampType = reflect.TypeOf(Timestamp{}) +var timestampType = reflect.TypeFor[Timestamp]() // Stringify attempts to create a reasonable string representation of types in // the GitHub library. It does things like resolve pointers to their values diff --git a/script/lint.sh b/script/lint.sh index 009d1d0c6ba..fc077cbaf24 100755 --- a/script/lint.sh +++ b/script/lint.sh @@ -5,7 +5,7 @@ set -e -GOLANGCI_LINT_VERSION="2.3.0" +GOLANGCI_LINT_VERSION="2.6.1" CDPATH="" cd -- "$(dirname -- "$0")/.." BIN="$(pwd -P)"/bin