Skip to content

Commit beb05d4

Browse files
kyu08stefanhaller
andcommitted
Fix makeAtomic in branches_test
When replacing the naked return with a `return result`, the linter starts to complain about "return copies lock value: sync/atomic.Int32 contains sync/atomic.noCopy". I suspect this is also a problem when using a naked return, and the linter just doesn't catch it in that case. Either way, it's better to use a pointer to ensure that the atomic is not copied. Co-authored-by: Stefan Haller <stefan@haller-berlin.de>
1 parent 65c27dd commit beb05d4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pkg/gui/presentation/branches_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import (
1616
"github.com/xo/terminfo"
1717
)
1818

19-
func makeAtomic(v int32) (result atomic.Int32) {
19+
func makeAtomic(v int32) *atomic.Int32 {
20+
var result atomic.Int32
2021
result.Store(v)
21-
return //nolint: nakedret
22+
return &result
2223
}
2324

2425
func Test_getBranchDisplayStrings(t *testing.T) {
@@ -109,7 +110,7 @@ func Test_getBranchDisplayStrings(t *testing.T) {
109110
branch: &models.Branch{
110111
Name: "branch_name",
111112
Recency: "1m",
112-
BehindBaseBranch: makeAtomic(2),
113+
BehindBaseBranch: *makeAtomic(2),
113114
},
114115
itemOperation: types.ItemOperationNone,
115116
fullDescription: false,
@@ -126,7 +127,7 @@ func Test_getBranchDisplayStrings(t *testing.T) {
126127
UpstreamRemote: "origin",
127128
AheadForPull: "0",
128129
BehindForPull: "0",
129-
BehindBaseBranch: makeAtomic(2),
130+
BehindBaseBranch: *makeAtomic(2),
130131
},
131132
itemOperation: types.ItemOperationNone,
132133
fullDescription: false,
@@ -143,7 +144,7 @@ func Test_getBranchDisplayStrings(t *testing.T) {
143144
UpstreamRemote: "origin",
144145
AheadForPull: "3",
145146
BehindForPull: "5",
146-
BehindBaseBranch: makeAtomic(2),
147+
BehindBaseBranch: *makeAtomic(2),
147148
},
148149
itemOperation: types.ItemOperationNone,
149150
fullDescription: false,
@@ -247,7 +248,7 @@ func Test_getBranchDisplayStrings(t *testing.T) {
247248
UpstreamRemote: "origin",
248249
AheadForPull: "3",
249250
BehindForPull: "5",
250-
BehindBaseBranch: makeAtomic(4),
251+
BehindBaseBranch: *makeAtomic(4),
251252
},
252253
itemOperation: types.ItemOperationNone,
253254
fullDescription: false,

0 commit comments

Comments
 (0)