Skip to content

Commit 5db01b3

Browse files
authored
[chore] Expand golangci-lint config with additional linters (#48)
[chore] Expand golangci-lint config and fix lint issues Add 13 new linters (dupword, forcetypeassert, intrange, misspell, modernize, nakedret, nilnil, perfsprint, predeclared, recvcheck, thelper, usestdlibvars, wastedassign) and fix all reported issues.
1 parent 9994bc9 commit 5db01b3

14 files changed

Lines changed: 49 additions & 37 deletions

File tree

.golangci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,30 @@ linters:
66
- bodyclose
77
- copyloopvar
88
- dupl
9+
- dupword
910
- errname
1011
- errorlint
1112
- fatcontext
13+
- forcetypeassert
1214
- goconst
1315
- gocritic
1416
- gocyclo
1517
- gosec
18+
- intrange
19+
- misspell
20+
- modernize
21+
- nakedret
1622
- nilerr
23+
- nilnil
24+
- perfsprint
1725
- prealloc
26+
- predeclared
27+
- recvcheck
28+
- thelper
1829
- unconvert
1930
- unparam
31+
- usestdlibvars
32+
- wastedassign
2033
- whitespace
2134
settings:
2235
gocyclo:

cmd/clean_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestFindMergedCandidatesRemoteRef(t *testing.T) {
8383
}
8484

8585
func TestFindMergedCandidatesNone(t *testing.T) {
86-
r := mergedWorktreeRunner("", wtRepo + headMainBlock)
86+
r := mergedWorktreeRunner("", wtRepo+headMainBlock)
8787
candidates, err := findMergedCandidates(r, branchMain, branchMain)
8888
if err != nil {
8989
t.Fatalf(fatalFindMerged, err)
@@ -398,6 +398,7 @@ func TestCleanPruneError(t *testing.T) {
398398
}
399399

400400
func cleanMergedTestRunner(t *testing.T, mergedOut, worktreeOut string) *mockRunner {
401+
t.Helper()
401402
dir := t.TempDir()
402403
cfg := &config.Config{DefaultSource: branchMain}
403404
_ = config.Save(filepath.Join(dir, config.FileName), cfg)
@@ -519,4 +520,3 @@ func TestCleanMergedResolveError(t *testing.T) {
519520
t.Fatal("expected error from resolveMainBranch failure")
520521
}
521522
}
522-

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var hookUninstallCmd = &cobra.Command{
6767

6868
err = hook.Uninstall(hooksDir)
6969
if errors.Is(err, hook.ErrNotInstalled) {
70-
return fmt.Errorf("rimba post-merge hook is not installed")
70+
return errors.New("rimba post-merge hook is not installed")
7171
}
7272
if err != nil {
7373
return err

cmd/init.go

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

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -40,7 +41,7 @@ var initCmd = &cobra.Command{
4041

4142
configPath := filepath.Join(repoRoot, config.FileName)
4243
if _, err := os.Stat(configPath); err == nil {
43-
return fmt.Errorf(".rimba.toml already exists (use a text editor to modify it)")
44+
return errors.New(".rimba.toml already exists (use a text editor to modify it)")
4445
}
4546

4647
cfg := config.DefaultConfig(repoName, defaultBranch)

cmd/init_test.go

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

33
import (
4-
"fmt"
4+
"errors"
55
"os"
66
"path/filepath"
77
"strings"
@@ -93,7 +93,7 @@ func TestInitRepoRootError(t *testing.T) {
9393
r := &mockRunner{
9494
run: func(args ...string) (string, error) {
9595
if len(args) >= 2 && args[1] == cmdShowToplevel {
96-
return "", fmt.Errorf("not a git repository")
96+
return "", errors.New("not a git repository")
9797
}
9898
return "", nil
9999
},

cmd/merge_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"context"
55
"errors"
6+
"slices"
67
"strings"
78
"testing"
89

@@ -444,14 +445,7 @@ func TestMergeWithNoFF(t *testing.T) {
444445
}
445446

446447
// Verify --no-ff was passed to merge
447-
foundNoFF := false
448-
for _, arg := range mergeArgs {
449-
if arg == "--no-ff" {
450-
foundNoFF = true
451-
break
452-
}
453-
}
454-
if !foundNoFF {
448+
if !slices.Contains(mergeArgs, "--no-ff") {
455449
t.Errorf("merge args = %v, want --no-ff to be present", mergeArgs)
456450
}
457451
}

cmd/root_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func TestPersistentPreRunESuccess(t *testing.T) {
111111
loaded := config.FromContext(cmd.Context())
112112
if loaded == nil {
113113
t.Fatal("expected config in context after successful PreRunE")
114+
return
114115
}
115116
if loaded.DefaultSource != "main" {
116117
t.Errorf("DefaultSource = %q, want %q", loaded.DefaultSource, "main")

cmd/sync.go

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

33
import (
4+
"errors"
45
"fmt"
56
"sync"
67

@@ -65,7 +66,7 @@ var syncCmd = &cobra.Command{
6566
includeInherited, _ := cmd.Flags().GetBool(flagIncludeInherited)
6667

6768
if !all && len(args) == 0 {
68-
return fmt.Errorf("provide a task name or use --all to sync all worktrees")
69+
return errors.New("provide a task name or use --all to sync all worktrees")
6970
}
7071

7172
hint.New(cmd, hintPainter(cmd)).

cmd/update_hint_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestCheckUpdateHintNewVersionAvailable(t *testing.T) {
5151
result := collectHint(ch)
5252
if result == nil {
5353
t.Fatal("expected non-nil result for available update")
54+
return
5455
}
5556
if result.LatestVersion != testVersionNew {
5657
t.Errorf("LatestVersion = %q, want %q", result.LatestVersion, testVersionNew)
@@ -142,6 +143,7 @@ func TestCollectHintValue(t *testing.T) {
142143
result := collectHint(ch)
143144
if result == nil {
144145
t.Fatal("expected non-nil result")
146+
return
145147
}
146148
if result.LatestVersion != testVersionOther {
147149
t.Errorf("LatestVersion = %q, want %q", result.LatestVersion, testVersionOther)

internal/git/bench_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func newBenchRepo(b *testing.B) string {
5050
// addBenchWorktrees creates n worktrees in the repo.
5151
func addBenchWorktrees(b *testing.B, repo string, n int) []string {
5252
b.Helper()
53-
var paths []string
54-
for i := 0; i < n; i++ {
53+
paths := make([]string, 0, n)
54+
for i := range n {
5555
branch := filepath.Join("feature", "bench-"+string(rune('a'+i)))
5656
wtPath := filepath.Join(filepath.Dir(repo), "wt-"+string(rune('a'+i)))
5757
cmd := exec.Command("git", "worktree", "add", "-b", branch, wtPath, "main")

0 commit comments

Comments
 (0)