Skip to content

Commit 888066f

Browse files
authored
Introduce golangci-lint as an additional linter (#199)
* Introduce golangci-lint as an additional linter * Fix `occured` is a misspelling of `occurred` (misspell) * Fix Error return value of `fmt.Fprint` is not checked (errcheck)
1 parent db4c287 commit 888066f

12 files changed

+172
-38
lines changed

.github/workflows/testing.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ jobs:
6363
install-go: false
6464
cache-key: ${{ matrix.go }}
6565

66+
golangci-lint:
67+
name: golangci-lint (Go ${{ matrix.go }})
68+
runs-on: ubuntu-24.04
69+
strategy:
70+
matrix:
71+
go: ["1.25", "1.24"]
72+
73+
steps:
74+
- uses: actions/checkout@v5
75+
- uses: actions/setup-go@v5
76+
with:
77+
go-version: ${{ matrix.go }}
78+
79+
- name: Run golangci-lint
80+
uses: golangci/golangci-lint-action@v9
81+
with:
82+
version: v2.7
83+
6684
unittesting:
6785
name: unit testing (Go ${{ matrix.go }})
6886
runs-on: ubuntu-24.04

.golangci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: "2"
2+
linters:
3+
# Default set of linters.
4+
# The value can be: `standard`, `all`, `none`, or `fast`.
5+
default: standard
6+
# Disable specific linter
7+
# https://golangci-lint.run/usage/linters/#disabled-by-default
8+
enable:
9+
- errcheck
10+
- govet
11+
- ineffassign
12+
- unused
13+
- misspell
14+
disable:
15+
- staticcheck
16+
run:
17+
# Timeout for total work, e.g. 30s, 5m, 5m30s.
18+
# If the value is lower or equal to 0, the timeout is disabled.
19+
# Default: 0 (disabled)
20+
timeout: 5m

access_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ func TestAccessService_ListAccessRights(t *testing.T) {
2020
"project": "go",
2121
})
2222

23-
fmt.Fprint(w, `)]}'`+"\n"+`{"go":{"revision":"08f45ba74baef9699b650f42022df6467389c1f0","inherits_from":{"id":"All-Projects","name":"All-Projects","description":"Access inherited by all other projects.","state":"ACTIVE"},"local":{},"owner_of":[],"config_visible":false}}`)
23+
_, err := fmt.Fprint(w, `)]}'`+"\n"+`{"go":{"revision":"08f45ba74baef9699b650f42022df6467389c1f0","inherits_from":{"id":"All-Projects","name":"All-Projects","description":"Access inherited by all other projects.","state":"ACTIVE"},"local":{},"owner_of":[],"config_visible":false}}`)
24+
if err != nil {
25+
t.Error(err)
26+
}
2427
})
2528

2629
opt := &gerrit.ListAccessRightsOptions{
@@ -58,7 +61,10 @@ func TestAccessService_ListAccessRights_WithoutOpts(t *testing.T) {
5861
testMux.HandleFunc("/access/", func(w http.ResponseWriter, r *http.Request) {
5962
testMethod(t, r, "GET")
6063

61-
fmt.Fprint(w, `)]}'`+"\n"+`{}`)
64+
_, err := fmt.Fprint(w, `)]}'`+"\n"+`{}`)
65+
if err != nil {
66+
t.Error(err)
67+
}
6268
})
6369

6470
access, _, err := testClient.Access.ListAccessRights(context.Background(), nil)

changes_hashtags_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ func TestChangesService_GetHashtags(t *testing.T) {
2222
if r.URL.Path != path {
2323
t.Errorf("Path %q != %q", r.URL.Path, path)
2424
}
25-
fmt.Fprintf(w, `)]}'
25+
_, err := fmt.Fprintf(w, `)]}'
2626
[
2727
"hashtag1",
2828
"hashtag2"
2929
]
3030
`)
31+
if err != nil {
32+
t.Error(err)
33+
}
3134
}))
3235
defer ts.Close()
3336

@@ -59,12 +62,15 @@ func TestChangesService_SetHashtags(t *testing.T) {
5962
if r.URL.Path != path {
6063
t.Errorf("Path %q != %q", r.URL.Path, path)
6164
}
62-
fmt.Fprintf(w, `)]}'
65+
_, err := fmt.Fprintf(w, `)]}'
6366
[
6467
"hashtag1",
6568
"hashtag3"
6669
]
6770
`)
71+
if err != nil {
72+
t.Error(err)
73+
}
6874
}))
6975
defer ts.Close()
7076

changes_reviewer_test.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ func TestChangesService_ListReviewers(t *testing.T) {
2525
t.Errorf("%s != %s", r.URL.Path, expected)
2626
}
2727

28-
fmt.Fprint(w, `[{"_account_id": 1}]`)
28+
_, err := fmt.Fprint(w, `[{"_account_id": 1}]`)
29+
if err != nil {
30+
t.Error(err)
31+
}
2932
}))
3033
defer ts.Close()
3134

@@ -52,7 +55,10 @@ func TestChangesService_SuggestReviewers(t *testing.T) {
5255
t.Errorf("%s != %s", r.URL.Path, expected)
5356
}
5457

55-
fmt.Fprint(w, `[{"account": {"_account_id": 1}}]`)
58+
_, err := fmt.Fprint(w, `[{"account": {"_account_id": 1}}]`)
59+
if err != nil {
60+
t.Error(err)
61+
}
5662
}))
5763
defer ts.Close()
5864

@@ -79,7 +85,10 @@ func TestChangesService_GetReviewer(t *testing.T) {
7985
t.Errorf("%s != %s", r.URL.Path, expected)
8086
}
8187

82-
fmt.Fprint(w, `{"_account_id": 1}`)
88+
_, err := fmt.Fprint(w, `{"_account_id": 1}`)
89+
if err != nil {
90+
t.Error(err)
91+
}
8392
}))
8493
defer ts.Close()
8594

@@ -104,7 +113,10 @@ func TestChangesService_AddReviewer(t *testing.T) {
104113
t.Error("Method != POST")
105114
}
106115

107-
fmt.Fprint(w, `{"confirm": true}`)
116+
_, err := fmt.Fprint(w, `{"confirm": true}`)
117+
if err != nil {
118+
t.Error(err)
119+
}
108120
}))
109121
defer ts.Close()
110122

@@ -146,7 +158,10 @@ func TestChangesService_ListVotes(t *testing.T) {
146158
if r.URL.Path != expected {
147159
t.Errorf("%s != %s", r.URL.Path, expected)
148160
}
149-
fmt.Fprint(w, `{"Code-Review": 2, "Verified": 1}`)
161+
_, err := fmt.Fprint(w, `{"Code-Review": 2, "Verified": 1}`)
162+
if err != nil {
163+
t.Error(err)
164+
}
150165
}))
151166
defer ts.Close()
152167

changes_revision_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestChangesService_ListFiles(t *testing.T) {
1616
if got, want := r.URL.String(), "/changes/123/revisions/456/files/?base=7"; got != want {
1717
t.Errorf("request URL:\ngot: %q\nwant: %q", got, want)
1818
}
19-
fmt.Fprint(w, `{
19+
_, err := fmt.Fprint(w, `{
2020
"/COMMIT_MSG": {
2121
"status": "A",
2222
"lines_inserted": 7,
@@ -30,6 +30,9 @@ func TestChangesService_ListFiles(t *testing.T) {
3030
"size": 23348
3131
}
3232
}`)
33+
if err != nil {
34+
t.Error(err)
35+
}
3336
}))
3437
defer ts.Close()
3538

@@ -65,7 +68,10 @@ func TestChangesService_ListFilesReviewed(t *testing.T) {
6568
if got, want := r.URL.String(), "/changes/123/revisions/456/files/?q=abc&reviewed=true"; got != want {
6669
t.Errorf("request URL:\ngot: %q\nwant: %q", got, want)
6770
}
68-
fmt.Fprint(w, `["/COMMIT_MSG","gerrit-server/RefControl.java"]`)
71+
_, err := fmt.Fprint(w, `["/COMMIT_MSG","gerrit-server/RefControl.java"]`)
72+
if err != nil {
73+
t.Error(err)
74+
}
6975
}))
7076
defer ts.Close()
7177

changes_test.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ func ExampleChangesService_QueryChanges_withSymbols() {
9595

9696
func ExampleChangesService_PublishChangeEdit() {
9797
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
98-
fmt.Fprintf(w, "ok")
98+
_, err := fmt.Fprintf(w, "ok")
99+
if err != nil {
100+
panic(err)
101+
}
99102
}))
100103
defer ts.Close()
101104

@@ -172,7 +175,10 @@ func TestChangesService_CreateChange(t *testing.T) {
172175
if r.Method != "POST" {
173176
t.Errorf("%s != POST", r.Method)
174177
}
175-
fmt.Fprintf(w, `{ "id": "abc1234", "project": "%s", "branch": "%s", "subject": "%s"}`, project, branch, subject)
178+
_, err = fmt.Fprintf(w, `{ "id": "abc1234", "project": "%s", "branch": "%s", "subject": "%s"}`, project, branch, subject)
179+
if err != nil {
180+
t.Error(err)
181+
}
176182
}))
177183
defer ts.Close()
178184

@@ -225,7 +231,10 @@ func TestChangesService_SubmitChange(t *testing.T) {
225231
if r.URL.Path != "/changes/123/submit" {
226232
t.Errorf("%s != /changes/123/submit", r.URL.Path)
227233
}
228-
fmt.Fprint(w, `{"id": "123"}`)
234+
_, err := fmt.Fprint(w, `{"id": "123"}`)
235+
if err != nil {
236+
t.Error(err)
237+
}
229238
}))
230239
defer ts.Close()
231240

@@ -265,7 +274,10 @@ func TestChangesService_AbandonChange(t *testing.T) {
265274
if r.URL.Path != "/changes/123/abandon" {
266275
t.Errorf("%s != /changes/123/abandon", r.URL.Path)
267276
}
268-
fmt.Fprint(w, `{"id": "123"}`)
277+
_, err := fmt.Fprint(w, `{"id": "123"}`)
278+
if err != nil {
279+
t.Error(err)
280+
}
269281
}))
270282
defer ts.Close()
271283

@@ -305,7 +317,10 @@ func TestChangesService_RebaseChange(t *testing.T) {
305317
if r.URL.Path != "/changes/123/rebase" {
306318
t.Errorf("%s != /changes/123/rebase", r.URL.Path)
307319
}
308-
fmt.Fprint(w, `{"id": "123"}`)
320+
_, err := fmt.Fprint(w, `{"id": "123"}`)
321+
if err != nil {
322+
t.Error(err)
323+
}
309324
}))
310325
defer ts.Close()
311326

@@ -345,7 +360,10 @@ func TestChangesService_RestoreChange(t *testing.T) {
345360
if r.URL.Path != "/changes/123/restore" {
346361
t.Errorf("%s != /changes/123/restore", r.URL.Path)
347362
}
348-
fmt.Fprint(w, `{"id": "123"}`)
363+
_, err := fmt.Fprint(w, `{"id": "123"}`)
364+
if err != nil {
365+
t.Error(err)
366+
}
349367
}))
350368
defer ts.Close()
351369

@@ -385,7 +403,10 @@ func TestChangesService_RevertChange(t *testing.T) {
385403
if r.URL.Path != "/changes/123/revert" {
386404
t.Errorf("%s != /changes/123/revert", r.URL.Path)
387405
}
388-
fmt.Fprint(w, `{"id": "123"}`)
406+
_, err := fmt.Fprint(w, `{"id": "123"}`)
407+
if err != nil {
408+
t.Error(err)
409+
}
389410
}))
390411
defer ts.Close()
391412

gerrit_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ func TestNewClient_NoGerritInstance(t *testing.T) {
121121
t.Errorf("NewClient return is not nil. Expected no client. Go %+v", c)
122122
}
123123
if err == nil {
124-
t.Error("No error occured by empty Gerrit Instance. Expected one.")
124+
t.Error("No error occurred by empty Gerrit Instance. Expected one.")
125125
}
126126
}
127127
}
128128

129129
func TestNewClient_Services(t *testing.T) {
130130
c, err := gerrit.NewClient(context.Background(), "https://gerrit-review.googlesource.com/", nil)
131131
if err != nil {
132-
t.Errorf("An error occured. Expected nil. Got %+v.", err)
132+
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
133133
}
134134

135135
if c.Authentication == nil {
@@ -396,7 +396,7 @@ func TestNewRequest(t *testing.T) {
396396
ctx := context.Background()
397397
c, err := gerrit.NewClient(ctx, testGerritInstanceURL, nil)
398398
if err != nil {
399-
t.Errorf("An error occured. Expected nil. Got %+v.", err)
399+
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
400400
}
401401

402402
inURL, outURL := "/foo", testGerritInstanceURL+"foo"
@@ -419,7 +419,7 @@ func TestNewRawPutRequest(t *testing.T) {
419419
ctx := context.Background()
420420
c, err := gerrit.NewClient(ctx, testGerritInstanceURL, nil)
421421
if err != nil {
422-
t.Errorf("An error occured. Expected nil. Got %+v.", err)
422+
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
423423
}
424424

425425
inURL, outURL := "/foo", testGerritInstanceURL+"foo"
@@ -450,7 +450,7 @@ func TestNewRequest_BadURL(t *testing.T) {
450450
ctx := context.Background()
451451
c, err := gerrit.NewClient(ctx, testGerritInstanceURL, nil)
452452
if err != nil {
453-
t.Errorf("An error occured. Expected nil. Got %+v.", err)
453+
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
454454
}
455455
_, err = c.NewRequest(ctx, "GET", ":", nil)
456456
testURLParseError(t, err)
@@ -464,7 +464,7 @@ func TestNewRequest_EmptyBody(t *testing.T) {
464464
ctx := context.Background()
465465
c, err := gerrit.NewClient(ctx, testGerritInstanceURL, nil)
466466
if err != nil {
467-
t.Errorf("An error occured. Expected nil. Got %+v.", err)
467+
t.Errorf("An error occurred. Expected nil. Got %+v.", err)
468468
}
469469
req, err := c.NewRequest(ctx, "GET", "/", nil)
470470
if err != nil {
@@ -487,7 +487,10 @@ func TestDo(t *testing.T) {
487487
if m := "GET"; m != r.Method {
488488
t.Errorf("Request method = %v, want %v", r.Method, m)
489489
}
490-
fmt.Fprint(w, `)]}'`+"\n"+`{"A":"a"}`)
490+
_, err := fmt.Fprint(w, `)]}'`+"\n"+`{"A":"a"}`)
491+
if err != nil {
492+
t.Error(err)
493+
}
491494
})
492495

493496
req, err := testClient.NewRequest(context.Background(), "GET", "/", nil)
@@ -514,7 +517,10 @@ func TestDo_ioWriter(t *testing.T) {
514517
if m := "GET"; m != r.Method {
515518
t.Errorf("Request method = %v, want %v", r.Method, m)
516519
}
517-
fmt.Fprint(w, content)
520+
_, err := fmt.Fprint(w, content)
521+
if err != nil {
522+
t.Error(err)
523+
}
518524
})
519525

520526
req, err := testClient.NewRequest(context.Background(), "GET", "/", nil)

0 commit comments

Comments
 (0)