Skip to content

Commit 4505771

Browse files
authored
Prefer %v over %d,%s and add fmtpercentv custom linter (#3756)
1 parent 6195c56 commit 4505771

File tree

99 files changed

+541
-361
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+541
-361
lines changed

.custom-gcl.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
version: v2.2.2
22
plugins:
3-
- module: "github.com/google/go-github/v68/tools/sliceofpointers"
3+
- module: "github.com/google/go-github/v75/tools/sliceofpointers"
44
path: ./tools/sliceofpointers
5+
- module: "github.com/google/go-github/v75/tools/fmtpercentv"
6+
path: ./tools/fmtpercentv

.golangci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ linters:
99
- dogsled
1010
- dupl
1111
- errorlint
12+
- fmtpercentv
1213
- forbidigo
1314
- gocritic
1415
- godot
@@ -136,10 +137,14 @@ linters:
136137
os-create-temp: true
137138
os-temp-dir: true
138139
custom:
140+
fmtpercentv:
141+
type: module
142+
description: Reports usage of %d or %s in format strings.
143+
original-url: github.com/google/go-github/v75/tools/fmtpercentv
139144
sliceofpointers:
140145
type: module
141146
description: Reports usage of []*string and slices of structs without pointers.
142-
original-url: github.com/google/go-github/v68/tools/sliceofpointers
147+
original-url: github.com/google/go-github/v75/tools/sliceofpointers
143148
exclusions:
144149
rules:
145150
- linters:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ To detect a primary API rate limit error, you can check if the error is a
215215
repos, _, err := client.Repositories.List(ctx, "", nil)
216216
var rateErr *github.RateLimitError
217217
if errors.As(err, &rateError) {
218-
log.Printf("hit primary rate limit, used %d of %d\n", rateErr.Rate.Used, rateErr.rate.Limit)
218+
log.Printf("hit primary rate limit, used %v of %v\n", rateErr.Rate.Used, rateErr.rate.Limit)
219219
}
220220
```
221221

example/actionpermissions/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,36 @@ func main() {
4242
log.Fatal(err)
4343
}
4444

45-
fmt.Printf("Current ActionsPermissions %s\n", actionsPermissionsRepository.String())
45+
fmt.Printf("Current ActionsPermissions %v\n", actionsPermissionsRepository)
4646

4747
actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Ptr(true), AllowedActions: github.Ptr("selected")}
4848
_, _, err = client.Repositories.UpdateActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository)
4949
if err != nil {
5050
log.Fatal(err)
5151
}
5252

53-
fmt.Printf("Current ActionsPermissions %s\n", actionsPermissionsRepository.String())
53+
fmt.Printf("Current ActionsPermissions %v\n", actionsPermissionsRepository)
5454

5555
actionsAllowed, _, err := client.Repositories.GetActionsAllowed(ctx, *owner, *name)
5656
if err != nil {
5757
log.Fatal(err)
5858
}
5959

60-
fmt.Printf("Current ActionsAllowed %s\n", actionsAllowed.String())
60+
fmt.Printf("Current ActionsAllowed %v\n", actionsAllowed)
6161

6262
actionsAllowed = &github.ActionsAllowed{GithubOwnedAllowed: github.Ptr(true), VerifiedAllowed: github.Ptr(false), PatternsAllowed: []string{"a/b"}}
6363
_, _, err = client.Repositories.EditActionsAllowed(ctx, *owner, *name, *actionsAllowed)
6464
if err != nil {
6565
log.Fatal(err)
6666
}
6767

68-
fmt.Printf("Current ActionsAllowed %s\n", actionsAllowed.String())
68+
fmt.Printf("Current ActionsAllowed %v\n", actionsAllowed)
6969

7070
actionsPermissionsRepository = &github.ActionsPermissionsRepository{Enabled: github.Ptr(true), AllowedActions: github.Ptr("all")}
7171
_, _, err = client.Repositories.UpdateActionsPermissions(ctx, *owner, *name, *actionsPermissionsRepository)
7272
if err != nil {
7373
log.Fatal(err)
7474
}
7575

76-
fmt.Printf("Current ActionsPermissions %s\n", actionsPermissionsRepository.String())
76+
fmt.Printf("Current ActionsPermissions %v\n", actionsPermissionsRepository)
7777
}

example/commitpr/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func createPR() (err error) {
185185
}
186186

187187
if *prRepoOwner != "" && *prRepoOwner != *sourceOwner {
188-
*commitBranch = fmt.Sprintf("%s:%s", *sourceOwner, *commitBranch)
188+
*commitBranch = fmt.Sprintf("%v:%v", *sourceOwner, *commitBranch)
189189
} else {
190190
prRepoOwner = sourceOwner
191191
}
@@ -208,7 +208,7 @@ func createPR() (err error) {
208208
return err
209209
}
210210

211-
fmt.Printf("PR created: %s\n", pr.GetHTMLURL())
211+
fmt.Printf("PR created: %v\n", pr.GetHTMLURL())
212212
return nil
213213
}
214214

@@ -225,22 +225,22 @@ func main() {
225225

226226
ref, err := getRef()
227227
if err != nil {
228-
log.Fatalf("Unable to get/create the commit reference: %s\n", err)
228+
log.Fatalf("Unable to get/create the commit reference: %v\n", err)
229229
}
230230
if ref == nil {
231231
log.Fatal("No error where returned but the reference is nil")
232232
}
233233

234234
tree, err := getTree(ref)
235235
if err != nil {
236-
log.Fatalf("Unable to create the tree based on the provided files: %s\n", err)
236+
log.Fatalf("Unable to create the tree based on the provided files: %v\n", err)
237237
}
238238

239239
if err := pushCommit(ref, tree); err != nil {
240-
log.Fatalf("Unable to create the commit: %s\n", err)
240+
log.Fatalf("Unable to create the commit: %v\n", err)
241241
}
242242

243243
if err := createPR(); err != nil {
244-
log.Fatalf("Error while creating the pull request: %s", err)
244+
log.Fatalf("Error while creating the pull request: %v", err)
245245
}
246246
}

example/listenvironments/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ func main() {
4646
}
4747

4848
// The number of environments here should be equal to expectedPageSize
49-
fmt.Printf("%d environments returned\n", len(envResponse.Environments))
49+
fmt.Printf("%v environments returned\n", len(envResponse.Environments))
5050
}

example/ratelimit/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func main() {
2727

2828
rateLimiter := github_ratelimit.New(nil,
2929
github_primary_ratelimit.WithLimitDetectedCallback(func(ctx *github_primary_ratelimit.CallbackContext) {
30-
fmt.Printf("Primary rate limit detected: category %s, reset time: %v\n", ctx.Category, ctx.ResetTime)
30+
fmt.Printf("Primary rate limit detected: category %v, reset time: %v\n", ctx.Category, ctx.ResetTime)
3131
}),
3232
github_secondary_ratelimit.WithLimitDetectedCallback(func(ctx *github_secondary_ratelimit.CallbackContext) {
3333
fmt.Printf("Secondary rate limit detected: reset time: %v, total sleep time: %v\n", ctx.ResetTime, ctx.TotalSleepTime)

example/verifyartifact/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ var (
4949

5050
func usage() {
5151
fmt.Fprintln(os.Stderr, "This is an example of how to verify the provenance of an artifact using GitHub Attestations and the sigstore-go library.")
52-
fmt.Fprintf(os.Stderr, "\nUsage: %s [flags]\n", os.Args[0])
52+
fmt.Fprintf(os.Stderr, "\nUsage: %v [flags]\n", os.Args[0])
5353
fmt.Fprint(os.Stderr, "\nThe flags are:\n")
5454
flag.PrintDefaults()
5555
fmt.Fprintf(os.Stderr, `
5656
Example:
5757
Verifying a GitHub CLI artifact
58-
%s -owner cli \
58+
%v -owner cli \
5959
-artifact-digest 2ce2e480e3c3f7ca0af83418d3ebaeedacee135dbac94bd946d7d84edabcdb64 \
6060
-expected-san https://github.com/cli/cli/.github/workflows/deployment.yml@refs/heads/trunk
6161
@@ -118,7 +118,7 @@ func main() {
118118
func getTrustedMaterial() (root.TrustedMaterialCollection, error) {
119119
trustedRootJSON, err := os.ReadFile(*trustedRootJSONPath)
120120
if err != nil {
121-
return nil, fmt.Errorf("failed to read %s: %w", *trustedRootJSONPath, err)
121+
return nil, fmt.Errorf("failed to read %v: %w", *trustedRootJSONPath, err)
122122
}
123123

124124
trustedRoot, err := root.NewTrustedRootFromJSON(trustedRootJSON)

github/actions_artifacts_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestActionsService_ListArtifacts_notFound(t *testing.T) {
9494
t.Error("Expected HTTP 404 response")
9595
}
9696
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
97-
t.Errorf("Actions.ListArtifacts return status %d, want %d", got, want)
97+
t.Errorf("Actions.ListArtifacts return status %v, want %v", got, want)
9898
}
9999
if artifacts != nil {
100100
t.Errorf("Actions.ListArtifacts return %+v, want nil", artifacts)
@@ -176,7 +176,7 @@ func TestActionsService_ListWorkflowRunArtifacts_notFound(t *testing.T) {
176176
t.Error("Expected HTTP 404 response")
177177
}
178178
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
179-
t.Errorf("Actions.ListWorkflowRunArtifacts return status %d, want %d", got, want)
179+
t.Errorf("Actions.ListWorkflowRunArtifacts return status %v, want %v", got, want)
180180
}
181181
if artifacts != nil {
182182
t.Errorf("Actions.ListWorkflowRunArtifacts return %+v, want nil", artifacts)
@@ -263,7 +263,7 @@ func TestActionsService_GetArtifact_notFound(t *testing.T) {
263263
t.Error("Expected HTTP 404 response")
264264
}
265265
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
266-
t.Errorf("Actions.GetArtifact return status %d, want %d", got, want)
266+
t.Errorf("Actions.GetArtifact return status %v, want %v", got, want)
267267
}
268268
if artifact != nil {
269269
t.Errorf("Actions.GetArtifact return %+v, want nil", artifact)
@@ -304,12 +304,12 @@ func TestActionsService_DownloadArtifact(t *testing.T) {
304304
t.Errorf("Actions.DownloadArtifact returned error: %v", err)
305305
}
306306
if resp.StatusCode != http.StatusFound {
307-
t.Errorf("Actions.DownloadArtifact returned status: %d, want %d", resp.StatusCode, http.StatusFound)
307+
t.Errorf("Actions.DownloadArtifact returned status: %v, want %v", resp.StatusCode, http.StatusFound)
308308
}
309309

310310
want := "https://github.com/artifact"
311311
if url.String() != want {
312-
t.Errorf("Actions.DownloadArtifact returned %+v, want %+v", url.String(), want)
312+
t.Errorf("Actions.DownloadArtifact returned %+v, want %+v", url, want)
313313
}
314314

315315
const methodName = "DownloadArtifact"
@@ -420,7 +420,7 @@ func TestActionsService_DownloadArtifact_StatusMovedPermanently_dontFollowRedire
420420
ctx := t.Context()
421421
_, resp, _ := client.Actions.DownloadArtifact(ctx, "o", "r", 1, 0)
422422
if resp.StatusCode != http.StatusMovedPermanently {
423-
t.Errorf("Actions.DownloadArtifact return status %d, want %d", resp.StatusCode, http.StatusMovedPermanently)
423+
t.Errorf("Actions.DownloadArtifact return status %v, want %v", resp.StatusCode, http.StatusMovedPermanently)
424424
}
425425
})
426426
}
@@ -464,11 +464,11 @@ func TestActionsService_DownloadArtifact_StatusMovedPermanently_followRedirects(
464464
t.Errorf("Actions.DownloadArtifact return error: %v", err)
465465
}
466466
if resp.StatusCode != http.StatusFound {
467-
t.Errorf("Actions.DownloadArtifact return status %d, want %d", resp.StatusCode, http.StatusFound)
467+
t.Errorf("Actions.DownloadArtifact return status %v, want %v", resp.StatusCode, http.StatusFound)
468468
}
469469
want := "https://github.com/artifact"
470470
if url.String() != want {
471-
t.Errorf("Actions.DownloadArtifact returned %+v, want %+v", url.String(), want)
471+
t.Errorf("Actions.DownloadArtifact returned %+v, want %+v", url, want)
472472
}
473473
})
474474
}
@@ -515,7 +515,7 @@ func TestActionsService_DownloadArtifact_unexpectedCode(t *testing.T) {
515515
t.Error("Actions.DownloadArtifact should return unexpected status code")
516516
}
517517
if got, want := resp.Response.StatusCode, http.StatusNoContent; got != want {
518-
t.Errorf("Actions.DownloadArtifact return status %d, want %d", got, want)
518+
t.Errorf("Actions.DownloadArtifact return status %v, want %v", got, want)
519519
}
520520
if url != nil {
521521
t.Errorf("Actions.DownloadArtifact return %+v, want nil", url)
@@ -582,7 +582,7 @@ func TestActionsService_DeleteArtifact_notFound(t *testing.T) {
582582
t.Error("Expected HTTP 404 response")
583583
}
584584
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
585-
t.Errorf("Actions.DeleteArtifact return status %d, want %d", got, want)
585+
t.Errorf("Actions.DeleteArtifact return status %v, want %v", got, want)
586586
}
587587
}
588588

github/actions_cache_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestActionsService_ListCaches_notFound(t *testing.T) {
8888
t.Error("Expected HTTP 404 response")
8989
}
9090
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
91-
t.Errorf("Actions.ListCaches return status %d, want %d", got, want)
91+
t.Errorf("Actions.ListCaches return status %v, want %v", got, want)
9292
}
9393
if caches != nil {
9494
t.Errorf("Actions.ListCaches return %+v, want nil", caches)
@@ -154,7 +154,7 @@ func TestActionsService_DeleteCachesByKey_notFound(t *testing.T) {
154154
t.Error("Expected HTTP 404 response")
155155
}
156156
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
157-
t.Errorf("Actions.DeleteCachesByKey return status %d, want %d", got, want)
157+
t.Errorf("Actions.DeleteCachesByKey return status %v, want %v", got, want)
158158
}
159159
}
160160

@@ -216,7 +216,7 @@ func TestActionsService_DeleteCachesByID_notFound(t *testing.T) {
216216
t.Error("Expected HTTP 404 response")
217217
}
218218
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
219-
t.Errorf("Actions.DeleteCachesByID return status %d, want %d", got, want)
219+
t.Errorf("Actions.DeleteCachesByID return status %v, want %v", got, want)
220220
}
221221
}
222222

@@ -294,7 +294,7 @@ func TestActionsService_GetCacheUsageForRepo_notFound(t *testing.T) {
294294
t.Error("Expected HTTP 404 response")
295295
}
296296
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
297-
t.Errorf("Actions.GetCacheUsageForRepo return status %d, want %d", got, want)
297+
t.Errorf("Actions.GetCacheUsageForRepo return status %v, want %v", got, want)
298298
}
299299
if caches != nil {
300300
t.Errorf("Actions.GetCacheUsageForRepo return %+v, want nil", caches)
@@ -367,7 +367,7 @@ func TestActionsService_ListCacheUsageByRepoForOrg_notFound(t *testing.T) {
367367
t.Error("Expected HTTP 404 response")
368368
}
369369
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
370-
t.Errorf("Actions.ListCacheUsageByRepoForOrg return status %d, want %d", got, want)
370+
t.Errorf("Actions.ListCacheUsageByRepoForOrg return status %v, want %v", got, want)
371371
}
372372
if caches != nil {
373373
t.Errorf("Actions.ListCacheUsageByRepoForOrg return %+v, want nil", caches)
@@ -438,7 +438,7 @@ func TestActionsService_GetCacheUsageForOrg_notFound(t *testing.T) {
438438
t.Error("Expected HTTP 404 response")
439439
}
440440
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
441-
t.Errorf("Actions.GetTotalCacheUsageForOrg return status %d, want %d", got, want)
441+
t.Errorf("Actions.GetTotalCacheUsageForOrg return status %v, want %v", got, want)
442442
}
443443
if caches != nil {
444444
t.Errorf("Actions.GetTotalCacheUsageForOrg return %+v, want nil", caches)
@@ -509,7 +509,7 @@ func TestActionsService_GetCacheUsageForEnterprise_notFound(t *testing.T) {
509509
t.Error("Expected HTTP 404 response")
510510
}
511511
if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want {
512-
t.Errorf("Actions.GetTotalCacheUsageForEnterprise return status %d, want %d", got, want)
512+
t.Errorf("Actions.GetTotalCacheUsageForEnterprise return status %v, want %v", got, want)
513513
}
514514
if caches != nil {
515515
t.Errorf("Actions.GetTotalCacheUsageForEnterprise return %+v, want nil", caches)

0 commit comments

Comments
 (0)