Skip to content

Commit eb6d9af

Browse files
chore: upgrade golangci lint (creativeprojects#53)
* chore: upgrade dependencies and improve code quality - Upgrade Go version in CI workflow to 1.25 - Update actions/checkout and actions/setup-go to v6 - Upgrade codecov-action to v6 - Refactor various functions to use context for better cancellation support - Improve variable naming for clarity - Add verification step in Makefile for Go installation - Update linters and their settings in .golangci.yml * run go fix * chore: update golangci-lint version and fix Makefile commands * chore: update golangci-lint settings and remove staticcheck linter suppression
1 parent 865cbd9 commit eb6d9af

21 files changed

Lines changed: 113 additions & 66 deletions

.github/workflows/build.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ jobs:
1313
runs-on: ${{ matrix.os }}
1414
strategy:
1515
matrix:
16-
go_version: ['1.24']
16+
go_version: ['1.25']
1717
os: [ubuntu-latest, windows-latest, macos-latest]
1818

1919
steps:
2020

2121
- name: Check out code into the Go module directory
22-
uses: actions/checkout@v5
22+
uses: actions/checkout@v6
2323

2424
- name: Set up Go ${{ matrix.go_version }}
25-
uses: actions/setup-go@v5
25+
uses: actions/setup-go@v6
2626
with:
2727
go-version: ${{ matrix.go_version }}
2828
check-latest: true
@@ -35,6 +35,12 @@ jobs:
3535
- name: Build
3636
run: go build -v ./...
3737

38+
- name: golangci-lint
39+
uses: golangci/golangci-lint-action@v9
40+
with:
41+
version: v2.11.4
42+
args: --timeout=30m
43+
3844
- name: Test
3945
shell: bash
4046
run: |
@@ -45,7 +51,7 @@ jobs:
4551
fi
4652
4753
- name: Code coverage with codecov
48-
uses: codecov/codecov-action@v5
54+
uses: codecov/codecov-action@v6
4955
with:
5056
env_vars: OS,GO
5157
files: ./coverage.txt

.golangci.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version: "2"
12
linters:
23
enable:
34
- asasalint
@@ -8,7 +9,7 @@ linters:
89
- errname
910
- gocheckcompilerdirectives
1011
- gosec
11-
- maintidx
12+
# - maintidx
1213
- misspell
1314
- nilnil
1415
- noctx
@@ -20,10 +21,30 @@ linters:
2021
- unconvert
2122
- unparam
2223
- usestdlibvars
23-
24-
linters-settings:
25-
gosec:
26-
excludes:
27-
- G101 # Potential hardcoded credentials
28-
staticcheck:
29-
checks: ["all", "-SA1019"] # "golang.org/x/crypto/openpgp" is deprecated
24+
settings:
25+
gosec:
26+
excludes:
27+
- G101
28+
staticcheck:
29+
checks:
30+
- all
31+
- -SA1019
32+
- -ST1003
33+
exclusions:
34+
generated: lax
35+
presets:
36+
- comments
37+
- common-false-positives
38+
- legacy
39+
- std-error-handling
40+
paths:
41+
- third_party$
42+
- builtin$
43+
- examples$
44+
formatters:
45+
exclusions:
46+
generated: lax
47+
paths:
48+
- third_party$
49+
- builtin$
50+
- examples$

Makefile

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ GOTEST=$(GOCMD) test
1010
GOTOOL=$(GOCMD) tool
1111
GOGET=$(GOCMD) get
1212
GOPATH?=`$(GOCMD) env GOPATH`
13+
GOBIN=$(shell $(GOCMD) env GOBIN)
14+
15+
ifeq ($(GOBIN),)
16+
GOBIN := $(GOPATH)/bin
17+
endif
1318

1419
TESTS=. ./update
1520
COVERAGE_FILE=coverage.txt
@@ -26,6 +31,20 @@ TOC_PATH=toc.md
2631

2732
all: test build
2833

34+
verify: ## Verify go installation
35+
ifeq ($(GOPATH),)
36+
@echo "GOPATH not found, please check your go installation"
37+
exit 1
38+
endif
39+
40+
$(GOBIN)/eget: verify
41+
@echo "[*] $@"
42+
GOBIN="$(GOBIN)" $(GOCMD) install -v github.com/zyedidia/eget@v1.3.4
43+
44+
$(GOBIN)/golangci-lint-v2: verify $(GOBIN)/eget
45+
@echo "[*] $@"
46+
"$(GOBIN)/eget" golangci/golangci-lint --tag v2.11.4 --asset=tar.gz --upgrade-only --to '$(GOBIN)/golangci-lint-v2'
47+
2948
build:
3049
$(GOBUILD) -v ./...
3150

@@ -53,17 +72,17 @@ toc:
5372
rm ${README}.1 ${README}.2 ${TOC_PATH}
5473

5574
.PHONY: lint
56-
lint:
75+
lint: $(GOBIN)/golangci-lint-v2
5776
@echo "[*] $@"
58-
GOOS=darwin golangci-lint run
59-
GOOS=linux golangci-lint run
60-
GOOS=windows golangci-lint run
77+
GOOS=darwin $(GOBIN)/golangci-lint-v2 run
78+
GOOS=linux $(GOBIN)/golangci-lint-v2 run
79+
GOOS=windows $(GOBIN)/golangci-lint-v2 run
6180

6281
.PHONY: fix
63-
fix:
82+
fix: $(GOBIN)/golangci-lint-v2
6483
@echo "[*] $@"
6584
$(GOCMD) mod tidy
6685
$(GOCMD) fix ./...
67-
GOOS=darwin golangci-lint run --fix
68-
GOOS=linux golangci-lint run --fix
69-
GOOS=windows golangci-lint run --fix
86+
GOOS=darwin $(GOBIN)/golangci-lint-v2 run --fix
87+
GOOS=linux $(GOBIN)/golangci-lint-v2 run --fix
88+
GOOS=windows $(GOBIN)/golangci-lint-v2 run --fix

arm_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package selfupdate
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"os/exec"
@@ -36,7 +37,7 @@ func TestGetGOARM(t *testing.T) {
3637
t.Run(tc.goOS+" "+tc.goArch+" "+tc.goArm, func(t *testing.T) {
3738
tempBinary := t.TempDir() + "/tempBinary-" + tc.goOS + tc.goArch + "v" + tc.goArm
3839
buildCmd := fmt.Sprintf("GOOS=%s GOARCH=%s GOARM=%s go build -o %s ./testdata/hello", tc.goOS, tc.goArch, tc.goArm, tempBinary)
39-
cmd := exec.Command("sh", "-c", buildCmd)
40+
cmd := exec.CommandContext(context.TODO(), "sh", "-c", buildCmd)
4041
cmd.Stdout = os.Stdout
4142
cmd.Stderr = os.Stderr
4243
err := cmd.Run()

cmd/serve-repo/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func WithLogging(h http.Handler) http.Handler {
4747

4848
duration := time.Since(start)
4949

50-
slog.Info("request completed",
50+
slog.Info("request completed", //nolint:gosec // G706: Log injection via taint analysis
5151
"uri", req.RequestURI,
5252
"method", req.Method,
5353
"status", responseData.status, // get captured status code

decompress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func gunzip(src io.Reader, cmd, os, arch string) (io.Reader, error) {
9999
return nil, fmt.Errorf("%w gzip file: %s", ErrCannotDecompressFile, err)
100100
}
101101

102-
name := r.Header.Name
102+
name := r.Name
103103
if !matchExecutableName(cmd, os, arch, name) {
104104
return nil, fmt.Errorf("%w: expected %q but found %q", ErrExecutableNotFoundInArchive, cmd, name)
105105
}

detect_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,6 @@ func TestFindReleaseAndAsset(t *testing.T) {
897897
}
898898

899899
for _, testItem := range testData {
900-
testItem := testItem
901900
t.Run(testItem.name, func(t *testing.T) {
902901
t.Parallel()
903902

github_release.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func NewGitHubRelease(from *github.RepositoryRelease) *GitHubRelease {
3636
return release
3737
}
3838

39-
func (a *GitHubRelease) GetID() int64 {
40-
return a.releaseID
39+
func (r *GitHubRelease) GetID() int64 {
40+
return r.releaseID
4141
}
4242

4343
func (r *GitHubRelease) GetTagName() string {

github_source.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ func (s *GitHubSource) DownloadReleaseAsset(ctx context.Context, rel *Release, a
101101
// This is a workaround for the issue that the GitHub API does not support downloading assets from GitHub Proxy services.
102102
if useGithubProxy {
103103
// Determine download url based on asset id.
104-
var downloadUrl string
104+
var downloadURL string
105105
if rel.AssetID == assetID {
106-
downloadUrl = rel.AssetURL
106+
downloadURL = rel.AssetURL
107107
} else if rel.ValidationAssetID == assetID {
108-
downloadUrl = rel.ValidationAssetURL
108+
downloadURL = rel.ValidationAssetURL
109109
}
110-
if downloadUrl == "" {
110+
if downloadURL == "" {
111111
return nil, fmt.Errorf("asset ID %d: %w", assetID, ErrAssetNotFound)
112112
}
113113
// Download the asset directly from the AssetURL
114-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadUrl, http.NoBody)
114+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadURL, http.NoBody)
115115
if err != nil {
116116
return nil, fmt.Errorf("failed to create download request:%w", err)
117117
}

gitlab_release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type GitLabAsset struct {
7676

7777
func NewGitLabAsset(from *gitlab.ReleaseLink) *GitLabAsset {
7878
return &GitLabAsset{
79-
id: int64(from.ID),
79+
id: from.ID,
8080
name: from.Name,
8181
url: from.URL,
8282
}

0 commit comments

Comments
 (0)