Skip to content

Commit 406c72c

Browse files
committed
chore: fix linting and add golangci-lint CI workflow
- Fixes the following lint findings: - Replace nil contexts in git_test.go with context.Background() - Rename unused interface-satisfying parameters to _ in cobra callbacks (root.go, clean.go) and test fakes (git_test.go, workspace_test.go)
1 parent c5ac0b3 commit 406c72c

File tree

7 files changed

+77
-26
lines changed

7 files changed

+77
-26
lines changed

.github/workflows/lint.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
lint:
11+
name: golangci-lint
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Go
19+
uses: actions/setup-go@v5
20+
with:
21+
go-version-file: go.mod
22+
cache: false
23+
24+
- name: Run golangci-lint
25+
uses: golangci/golangci-lint-action@v8
26+
with:
27+
version: latest

.golangci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: "2"
2+
3+
run:
4+
timeout: 5m
5+
6+
linters:
7+
default: standard
8+
enable:
9+
- misspell
10+
- revive
11+
settings:
12+
errcheck:
13+
# Ignore unhandled errors from fmt output functions — writing to a
14+
# CLI's stdout/stderr is conventional to ignore since there is no
15+
# useful recovery action when terminal output fails.
16+
exclude-functions:
17+
- fmt.Fprint
18+
- fmt.Fprintf
19+
- fmt.Fprintln
20+
21+
formatters:
22+
enable:
23+
- goimports

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<img src="./assets/prt-logo.png" alt="prt-logo" width="150" />
33
</p>
44

5-
## The 'pitch'
5+
## The problem
66

77
Reviewing a PR can require the following repetitive setup:
88

internal/cli/clean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func newCleanCommand(rootOpts *rootOptions) *cobra.Command {
2424
Example: "" +
2525
" prt clean --dry-run\n" +
2626
" prt clean --all",
27-
RunE: func(cmd *cobra.Command, args []string) error {
27+
RunE: func(cmd *cobra.Command, _ []string) error {
2828
return runClean(cmd, rootOpts, opts)
2929
},
3030
}

internal/cli/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func newRootCommand(version string) *cobra.Command {
3939
" prt https://github.com/OWNER/REPO/pull/123 --temp\n" +
4040
" prt https://github.com/OWNER/REPO/pull/123 --no-tab\n" +
4141
" prt clean --dry-run",
42-
Args: func(cmd *cobra.Command, args []string) error {
42+
Args: func(_ *cobra.Command, args []string) error {
4343
if len(args) == 0 {
4444
return fmt.Errorf("missing PR URL argument (run 'prt --help')")
4545
}
@@ -84,7 +84,7 @@ func newVersionCommand(version string) *cobra.Command {
8484
Use: "version",
8585
Short: "Print prt version",
8686
Args: cobra.NoArgs,
87-
Run: func(cmd *cobra.Command, args []string) {
87+
Run: func(cmd *cobra.Command, _ []string) {
8888
fmt.Fprintf(cmd.OutOrStdout(), "prt version %s\n", version)
8989
},
9090
}

internal/git/git_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,25 @@ func TestHasRemote(t *testing.T) {
5353
output: "origin\nfork\nprt-fork\n",
5454
}
5555
client := &Client{runner: fakeRunner}
56+
ctx := context.Background()
5657

57-
has, err := client.HasRemote(nil, "/repo", "origin")
58+
has, err := client.HasRemote(ctx, "/repo", "origin")
5859
if err != nil {
5960
t.Fatalf("HasRemote: %v", err)
6061
}
6162
if !has {
6263
t.Fatalf("expected HasRemote to return true for origin")
6364
}
6465

65-
has, err = client.HasRemote(nil, "/repo", "prt-fork")
66+
has, err = client.HasRemote(ctx, "/repo", "prt-fork")
6667
if err != nil {
6768
t.Fatalf("HasRemote: %v", err)
6869
}
6970
if !has {
7071
t.Fatalf("expected HasRemote to return true for prt-fork")
7172
}
7273

73-
has, err = client.HasRemote(nil, "/repo", "nonexistent")
74+
has, err = client.HasRemote(ctx, "/repo", "nonexistent")
7475
if err != nil {
7576
t.Fatalf("HasRemote: %v", err)
7677
}
@@ -85,7 +86,7 @@ func TestRemoteURL(t *testing.T) {
8586
}
8687
client := &Client{runner: fakeRunner}
8788

88-
url, err := client.RemoteURL(nil, "/repo", "origin")
89+
url, err := client.RemoteURL(context.Background(), "/repo", "origin")
8990
if err != nil {
9091
t.Fatalf("RemoteURL: %v", err)
9192
}
@@ -131,6 +132,6 @@ type fakeRunner struct {
131132
err error
132133
}
133134

134-
func (r *fakeRunner) Run(ctx context.Context, dir string, name string, args ...string) (string, error) {
135+
func (r *fakeRunner) Run(_ context.Context, _ string, _ string, _ ...string) (string, error) {
135136
return r.output, r.err
136137
}

internal/workspace/workspace_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ func newFakeGit() *fakeGit {
8787
}
8888
}
8989

90-
func (f *fakeGit) IsGitRepo(ctx context.Context, repoDir string) (bool, error) {
90+
func (f *fakeGit) IsGitRepo(_ context.Context, repoDir string) (bool, error) {
9191
_, ok := f.repos[repoDir]
9292
return ok, nil
9393
}
9494

95-
func (f *fakeGit) Clone(ctx context.Context, url string, dest string) error {
95+
func (f *fakeGit) Clone(_ context.Context, url string, dest string) error {
9696
if err := os.MkdirAll(dest, 0o755); err != nil {
9797
return err
9898
}
@@ -104,26 +104,26 @@ func (f *fakeGit) Clone(ctx context.Context, url string, dest string) error {
104104
return nil
105105
}
106106

107-
func (f *fakeGit) CloneBare(ctx context.Context, url string, dest string, depth int) error {
107+
func (f *fakeGit) CloneBare(ctx context.Context, url string, dest string, _ int) error {
108108
return f.Clone(ctx, url, dest)
109109
}
110110

111-
func (f *fakeGit) Fetch(ctx context.Context, repoDir string, remote string, refspec string) error {
111+
func (f *fakeGit) Fetch(_ context.Context, repoDir string, remote string, refspec string) error {
112112
f.fetches = append(f.fetches, fetchCall{repoDir: repoDir, remote: remote, refspec: refspec})
113113
return f.fetchErr
114114
}
115115

116-
func (f *fakeGit) FetchBranch(ctx context.Context, repoDir string, remote string, branch string) error {
116+
func (f *fakeGit) FetchBranch(_ context.Context, repoDir string, remote string, branch string) error {
117117
f.branchFetches = append(f.branchFetches, branchFetchCall{repoDir: repoDir, remote: remote, branch: branch})
118118
return f.fetchBranchErr
119119
}
120120

121-
func (f *fakeGit) SubmoduleUpdate(ctx context.Context, repoDir string) error {
121+
func (f *fakeGit) SubmoduleUpdate(_ context.Context, repoDir string) error {
122122
f.submoduleUpdates = append(f.submoduleUpdates, repoDir)
123123
return f.submoduleUpdateErr
124124
}
125125

126-
func (f *fakeGit) WorktreeAdd(ctx context.Context, repoDir string, worktreePath string, branch string) error {
126+
func (f *fakeGit) WorktreeAdd(_ context.Context, repoDir string, worktreePath string, branch string) error {
127127
if err := os.MkdirAll(worktreePath, 0o755); err != nil {
128128
return err
129129
}
@@ -132,7 +132,7 @@ func (f *fakeGit) WorktreeAdd(ctx context.Context, repoDir string, worktreePath
132132
return nil
133133
}
134134

135-
func (f *fakeGit) WorktreeRemove(ctx context.Context, repoDir string, worktreePath string, force bool) error {
135+
func (f *fakeGit) WorktreeRemove(_ context.Context, repoDir string, worktreePath string, _ bool) error {
136136
if err := os.RemoveAll(worktreePath); err != nil {
137137
return err
138138
}
@@ -145,7 +145,7 @@ func (f *fakeGit) WorktreeRemove(ctx context.Context, repoDir string, worktreePa
145145
return nil
146146
}
147147

148-
func (f *fakeGit) WorktreeList(ctx context.Context, repoDir string) ([]git.Worktree, error) {
148+
func (f *fakeGit) WorktreeList(_ context.Context, repoDir string) ([]git.Worktree, error) {
149149
repo, ok := f.repos[repoDir]
150150
if !ok {
151151
return nil, nil
@@ -157,7 +157,7 @@ func (f *fakeGit) WorktreeList(ctx context.Context, repoDir string) ([]git.Workt
157157
return worktrees, nil
158158
}
159159

160-
func (f *fakeGit) HasWorktreeForBranch(ctx context.Context, repoDir string, branch string) (string, bool, error) {
160+
func (f *fakeGit) HasWorktreeForBranch(_ context.Context, repoDir string, branch string) (string, bool, error) {
161161
if repo, ok := f.repos[repoDir]; ok {
162162
if path, ok := repo.worktrees[branch]; ok {
163163
return path, true, nil
@@ -166,15 +166,15 @@ func (f *fakeGit) HasWorktreeForBranch(ctx context.Context, repoDir string, bran
166166
return "", false, nil
167167
}
168168

169-
func (f *fakeGit) OriginURL(ctx context.Context, repoDir string) (string, error) {
169+
func (f *fakeGit) OriginURL(_ context.Context, repoDir string) (string, error) {
170170
repo, ok := f.repos[repoDir]
171171
if !ok {
172172
return "", nil
173173
}
174174
return repo.origin, nil
175175
}
176176

177-
func (f *fakeGit) AddRemote(ctx context.Context, repoDir string, name string, url string) error {
177+
func (f *fakeGit) AddRemote(_ context.Context, repoDir string, name string, url string) error {
178178
repo, ok := f.repos[repoDir]
179179
if !ok {
180180
return nil
@@ -186,7 +186,7 @@ func (f *fakeGit) AddRemote(ctx context.Context, repoDir string, name string, ur
186186
return nil
187187
}
188188

189-
func (f *fakeGit) HasRemote(ctx context.Context, repoDir string, name string) (bool, error) {
189+
func (f *fakeGit) HasRemote(_ context.Context, repoDir string, name string) (bool, error) {
190190
repo, ok := f.repos[repoDir]
191191
if !ok {
192192
return false, nil
@@ -195,22 +195,22 @@ func (f *fakeGit) HasRemote(ctx context.Context, repoDir string, name string) (b
195195
return exists, nil
196196
}
197197

198-
func (f *fakeGit) SetUpstream(ctx context.Context, repoDir string, branch string, upstream string) error {
198+
func (f *fakeGit) SetUpstream(_ context.Context, repoDir string, branch string, upstream string) error {
199199
f.upstreams = append(f.upstreams, upstreamCall{repoDir: repoDir, branch: branch, upstream: upstream})
200200
return nil
201201
}
202202

203-
func (f *fakeGit) ConfigSet(ctx context.Context, repoDir string, key string, value string) error {
203+
func (f *fakeGit) ConfigSet(_ context.Context, repoDir string, key string, value string) error {
204204
f.configs = append(f.configs, configCall{repoDir: repoDir, key: key, value: value})
205205
return nil
206206
}
207207

208-
func (f *fakeGit) ConfigSetWorktree(ctx context.Context, repoDir string, key string, value string) error {
208+
func (f *fakeGit) ConfigSetWorktree(_ context.Context, repoDir string, key string, value string) error {
209209
f.configs = append(f.configs, configCall{repoDir: repoDir, key: "--worktree:" + key, value: value})
210210
return nil
211211
}
212212

213-
func (f *fakeGit) WorktreeAddBranch(ctx context.Context, repoDir string, worktreePath string, branch string, startPoint string, force bool) error {
213+
func (f *fakeGit) WorktreeAddBranch(_ context.Context, repoDir string, worktreePath string, branch string, startPoint string, _ bool) error {
214214
if f.branchAddFirstCallErr != nil && f.branchAddCallCount == 0 {
215215
f.branchAddCallCount++
216216
return f.branchAddFirstCallErr

0 commit comments

Comments
 (0)