Skip to content

Commit 3608b76

Browse files
Merge pull request #175 from Pix4D/re-enable-linter
Re-enable linter
2 parents d6f04de + c6ba579 commit 3608b76

File tree

7 files changed

+38
-22
lines changed

7 files changed

+38
-22
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,34 @@ name: ci
66

77
env:
88
go-version: 1.25.x
9+
golangci-version: v2.8.0
10+
gotestsum-version: v1.13.0
911
task-version: v3.40.0
1012

1113
jobs:
1214
all:
1315
runs-on: ubuntu-latest
1416
steps:
1517
- name: Install Go
16-
uses: actions/setup-go@v5
18+
uses: actions/setup-go@v6
1719
with:
1820
go-version: ${{ env.go-version }}
1921
- name: Install Task
2022
run: go install github.com/go-task/task/v3/cmd/task@${{ env.task-version }}
2123
- name: Checkout code
22-
uses: actions/checkout@v4
24+
uses: actions/checkout@v6
2325
with:
2426
# By default, actions/checkout will persist the GITHUB_TOKEN, so that further
2527
# steps in the job can perform authenticated git commands (that is: WRITE to
2628
# the repo). Following the Principle of least privilege, we disable this as long
2729
# as we don't need it.
2830
persist-credentials: false
29-
- run: task ci:setup
30-
# - run: task lint FIXME: re-enable
31+
- name: golangci-lint
32+
uses: golangci/golangci-lint-action@v9
33+
with:
34+
version: ${{ env.golangci-version }}
3135
- run: task build
36+
- run: go install gotest.tools/gotestsum@${{ env.gotestsum-version }}
3237
- run: task test:all
3338
env:
3439
COGITO_TEST_OAUTH_TOKEN: ${{ secrets.COGITO_TEST_OAUTH_TOKEN }}

.golangci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
# See https://golangci-lint.run/usage/configuration/#config-file
1+
# See https://golangci-lint.run/docs/configuration/file/
2+
3+
version: "2"
24

35
linters:
46
# NOTE: `enable` _adds_ to the default linters!
57
# To see the currently enabled linters, run `golangci-lint linters`
68
enable:
79
- gocritic
10+
# - modernize LATER

Taskfile.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ vars:
2727
"version": {"ref": "pizza"}
2828
}
2929
#
30-
GOLANGCI_VERSION: v1.62.2
30+
GOLANGCI_VERSION: v2.8.0
3131
GOTESTSUM_VERSION: v1.13.0
3232

3333
tasks:
3434

3535
install:deps:
3636
desc: Install tool dependencies.
3737
cmds:
38-
# - go install github.com/golangci/golangci-lint/cmd/golangci-lint@{{.GOLANGCI_VERSION}}
38+
- go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@{{.GOLANGCI_VERSION}}
3939
- go install gotest.tools/gotestsum@{{.GOTESTSUM_VERSION}}
4040

4141
lint:
@@ -296,14 +296,6 @@ tasks:
296296
status:
297297
- test -z "{{.IS_RELEASE}}"
298298

299-
ci:setup:
300-
desc: Useful only when running under CI.
301-
cmds:
302-
- task: install:deps
303-
# Running "go mod download" is optional, since "go build" would do it anyway.
304-
# We run it explicitly to make the output of "go build" more focused.
305-
- cmd: go mod download -x
306-
307299
# When using GitHub Actions, add this snippet at the end of the workflow:
308300
# - run: docker logout
309301
# # Always remove credentials, also if any previous step failed.

cogito/ghcommitsink_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ func TestSinkGitHubCommitStatusSendGhAppSuccess(t *testing.T) {
5757
dec := json.NewDecoder(r.Body)
5858
if err := dec.Decode(&ghReq); err != nil {
5959
w.WriteHeader(http.StatusTeapot)
60-
fmt.Fprintln(w, "test: decoding request:", err)
60+
if _, err := fmt.Fprintln(w, "test: decoding request:", err); err != nil {
61+
t.Fatalf("writing response: %s", err)
62+
}
6163
return
6264
}
6365
}
6466

6567
w.WriteHeader(http.StatusCreated)
6668
if r.URL.String() == "/app/installations/12345/access_tokens" {
67-
fmt.Fprintln(w, `{"token": "dummy_installation_token"}`)
69+
if _, err := fmt.Fprintln(w, `{"token": "dummy_installation_token"}`); err != nil {
70+
t.Fatalf("writing token: %s", err)
71+
}
6872
return
6973
}
7074
}

googlechat/googlechat.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ func TextMessage(
102102
if err != nil {
103103
return MessageReply{}, fmt.Errorf("TextMessage: send: %s", RedactErrorURL(err))
104104
}
105-
defer resp.Body.Close()
105+
defer func() {
106+
if err := resp.Body.Close(); err != nil {
107+
log.Info("closing-response-body", "error", err)
108+
}
109+
}()
106110
elapsed := time.Since(start)
107111
log.Debug(
108112
"http-request",

testhelp/testhelper.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,23 @@ func CopyDir(dst string, src string, dirRenamer Renamer, templatedata TemplateDa
113113
return nil
114114
}
115115

116-
func copyFile(dstPath string, srcPath string, templatedata TemplateData) error {
116+
func copyFile(dstPath string, srcPath string, templatedata TemplateData) (allErrs error) {
117117
srcFile, err := os.Open(srcPath)
118118
if err != nil {
119119
return fmt.Errorf("opening src file: %w", err)
120120
}
121-
defer srcFile.Close()
121+
defer func() {
122+
allErrs = errors.Join(allErrs, srcFile.Close())
123+
}()
122124

123125
// We want an error if the file already exists
124126
dstFile, err := os.OpenFile(dstPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o660)
125127
if err != nil {
126128
return fmt.Errorf("creating dst file: %w", err)
127129
}
128-
defer dstFile.Close()
130+
defer func() {
131+
allErrs = errors.Join(allErrs, dstFile.Close())
132+
}()
129133

130134
if len(templatedata) == 0 {
131135
_, err = io.Copy(dstFile, srcFile)

testhelp/testserver.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ func SpyHttpServer(request any, reply any, theUrl **url.URL, successCode int,
3232
dec := json.NewDecoder(req.Body)
3333
if err := dec.Decode(request); err != nil {
3434
w.WriteHeader(http.StatusTeapot)
35-
fmt.Fprintln(w, "test: decoding request:", err)
35+
if _, err := fmt.Fprintln(w, "test: decoding request:", err); err != nil {
36+
// In production one would normally log this kind of error.
37+
// Here we are in a test, so it is appropriate to panic.
38+
panic(fmt.Errorf("writing response: %s", err))
39+
}
3640
return
3741
}
3842

0 commit comments

Comments
 (0)