Skip to content

Commit 80b1618

Browse files
committed
chore: enable gocritic
1 parent 684c598 commit 80b1618

File tree

17 files changed

+53
-67
lines changed

17 files changed

+53
-67
lines changed

.golangci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ linters:
2121
- "errcheck"
2222
- "errname"
2323
- "errorlint"
24-
# - "gocritic" TODO: fix issues
24+
- "gocritic"
2525
- "goprintffuncname"
2626
- "gosec"
2727
# - "govet" TODO: fix issues

cmd/spicedb/servetesting_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestTestServer(t *testing.T) {
4141
"--http-addr", ":8443",
4242
"--readonly-http-addr", ":8444",
4343
"--http-enabled",
44-
//"--readonly-http-enabled",
44+
// "--readonly-http-enabled",
4545
},
4646
ExposedPorts: []string{"50051/tcp", "50052/tcp", "8443/tcp", "8444/tcp"},
4747
},

internal/cursorediterator/blocks_test.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,7 @@ func TestCursoredProducerMapperIterator(t *testing.T) {
639639
}
640640

641641
// Cursor converter functions for int
642-
intFromString := func(s string) (int, error) {
643-
return strconv.Atoi(s)
644-
}
642+
intFromString := strconv.Atoi
645643

646644
intToString := func(i int) (string, error) {
647645
return strconv.Itoa(i), nil
@@ -1084,9 +1082,7 @@ func TestCursoredProducerMapperIterator(t *testing.T) {
10841082
}
10851083

10861084
// Cursor converter functions for int
1087-
intFromString := func(s string) (int, error) {
1088-
return strconv.Atoi(s)
1089-
}
1085+
intFromString := strconv.Atoi
10901086

10911087
intToString := func(i int) (string, error) {
10921088
return strconv.Itoa(i), nil
@@ -1383,9 +1379,7 @@ func TestCursoredProducerMapperIteratorConcurrency1SpecialCase(t *testing.T) {
13831379
ctx := t.Context()
13841380

13851381
// Cursor converter functions for int
1386-
intFromString := func(s string) (int, error) {
1387-
return strconv.Atoi(s)
1388-
}
1382+
intFromString := strconv.Atoi
13891383

13901384
intToString := func(i int) (string, error) {
13911385
return strconv.Itoa(i), nil
@@ -1718,9 +1712,7 @@ func TestConcurrencyConsistency(t *testing.T) {
17181712

17191713
t.Run("CursoredProducerMapperIterator consistency", func(t *testing.T) {
17201714
// Cursor converter functions
1721-
intFromString := func(s string) (int, error) {
1722-
return strconv.Atoi(s)
1723-
}
1715+
intFromString := strconv.Atoi
17241716
intToString := func(i int) (string, error) {
17251717
return strconv.Itoa(i), nil
17261718
}
@@ -1972,9 +1964,7 @@ func TestDisableCursorsInContext(t *testing.T) {
19721964
t.Run("CursoredProducerMapperIterator with cursors disabled", func(t *testing.T) {
19731965
ctxWithoutCursors := DisableCursorsInContext(ctx)
19741966

1975-
intFromString := func(s string) (int, error) {
1976-
return strconv.Atoi(s)
1977-
}
1967+
intFromString := strconv.Atoi
19781968

19791969
intToString := func(i int) (string, error) {
19801970
return strconv.Itoa(i), nil
@@ -2024,9 +2014,7 @@ func TestDisableCursorsInContext(t *testing.T) {
20242014
})
20252015

20262016
t.Run("CursoredProducerMapperIterator with cursors enabled", func(t *testing.T) {
2027-
intFromString := func(s string) (int, error) {
2028-
return strconv.Atoi(s)
2029-
}
2017+
intFromString := strconv.Atoi
20302018

20312019
intToString := func(i int) (string, error) {
20322020
return strconv.Itoa(i), nil
@@ -2071,9 +2059,7 @@ func TestDisableCursorsInContext(t *testing.T) {
20712059
t.Run("CursoredProducerMapperIterator with cursors disabled concurrency=1", func(t *testing.T) {
20722060
ctxWithoutCursors := DisableCursorsInContext(ctx)
20732061

2074-
intFromString := func(s string) (int, error) {
2075-
return strconv.Atoi(s)
2076-
}
2062+
intFromString := strconv.Atoi
20772063

20782064
intToString := func(i int) (string, error) {
20792065
return strconv.Itoa(i), nil

internal/cursorediterator/context_cancellation_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,7 @@ func TestContextCancellationComprehensive(t *testing.T) {
281281
concurrencyLevels := []uint16{1, 2, 4}
282282

283283
// Cursor converter functions
284-
intFromString := func(s string) (int, error) {
285-
return strconv.Atoi(s)
286-
}
284+
intFromString := strconv.Atoi
287285
intToString := func(i int) (string, error) {
288286
return strconv.Itoa(i), nil
289287
}

internal/cursorediterator/cursor_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ func TestCursorCustomHeadValue(t *testing.T) {
151151
})
152152

153153
// Test with bool converter
154-
boolConverter := func(s string) (bool, error) {
155-
return strconv.ParseBool(s)
156-
}
154+
boolConverter := strconv.ParseBool
157155

158156
t.Run("bool converter success", func(t *testing.T) {
159157
c := Cursor{"true", "false"}

internal/datastore/crdb/schema/indexutil.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ func checkFilterColumnMatchesFilter(colName string, filter datastore.Relationshi
188188
foundCount++
189189
}
190190
}
191-
if foundCount == 0 {
191+
switch {
192+
case foundCount == 0:
192193
return columnFilterNoMatch, nil
193-
} else if foundCount < len(filter.OptionalSubjectsSelectors) {
194+
case foundCount < len(filter.OptionalSubjectsSelectors):
194195
return columnFilterForceNoMatch, nil
195-
} else {
196+
default:
196197
return columnFilterMatch, nil
197198
}
198199

@@ -207,11 +208,12 @@ func checkFilterColumnMatchesFilter(colName string, filter datastore.Relationshi
207208
foundCount++
208209
}
209210
}
210-
if foundCount == 0 {
211+
switch {
212+
case foundCount == 0:
211213
return columnFilterNoMatch, nil
212-
} else if foundCount < len(filter.OptionalSubjectsSelectors) {
214+
case foundCount < len(filter.OptionalSubjectsSelectors):
213215
return columnFilterForceNoMatch, nil
214-
} else {
216+
default:
215217
return columnFilterMatch, nil
216218
}
217219

@@ -226,11 +228,12 @@ func checkFilterColumnMatchesFilter(colName string, filter datastore.Relationshi
226228
foundCount++
227229
}
228230
}
229-
if foundCount == 0 {
231+
switch {
232+
case foundCount == 0:
230233
return columnFilterNoMatch, nil
231-
} else if foundCount < len(filter.OptionalSubjectsSelectors) {
234+
case foundCount < len(filter.OptionalSubjectsSelectors):
232235
return columnFilterForceNoMatch, nil
233-
} else {
236+
default:
234237
return columnFilterMatch, nil
235238
}
236239

internal/datastore/postgres/postgres_shared_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,11 +1981,9 @@ func RevisionTimestampAndTransactionIDTest(t *testing.T, ds datastore.Datastore)
19811981
require.True(transactionIDPresent, "expected transactionID to be present in revision")
19821982

19831983
checkedUpdate = true
1984-
} else {
19851984
// we wait for a checkpoint right after the update. Checkpoints could happen at any time off band.
1986-
if checkedUpdate {
1987-
checkedCheckpoint = true
1988-
}
1985+
} else if checkedUpdate {
1986+
checkedCheckpoint = true
19891987
}
19901988

19911989
time.Sleep(1 * time.Millisecond)

internal/graph/lookupresources3.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,8 @@ func mustDatastoreIndexToString(index datastoreIndex) (string, error) {
13991399
return dsIndexPrefix + index.chunkID, nil
14001400
}
14011401

1402-
return dsIndexPrefix + index.chunkID + ":" + (*index.dbCursor).String(), nil
1402+
cursor := (*index.dbCursor)
1403+
return dsIndexPrefix + index.chunkID + ":" + cursor.String(), nil
14031404
}
14041405

14051406
type datastoreIndex struct {

internal/services/shared/errors_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestRewriteError(t *testing.T) {
181181
expectedCode: codes.FailedPrecondition,
182182
expectedContains: "failed precondition: relation/permission `view` under definition `document` is missing type information",
183183
},
184-
//{ TODO this doesn't pass
184+
// { TODO this doesn't pass
185185
// name: "compiler error",
186186
// inputError: &compiler.WithContextError{
187187
// BaseCompilerError: compiler.BaseCompilerError{
@@ -191,7 +191,7 @@ func TestRewriteError(t *testing.T) {
191191
// config: nil,
192192
// expectedCode: codes.InvalidArgument,
193193
// expectedContains: "syntax error in schema",
194-
//},
194+
// },
195195
{
196196
name: "source error",
197197
inputError: spiceerrors.NewWithSourceError(

internal/services/shared/schema.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ func errorIfTupleIteratorReturnsTuples(_ context.Context, qy datastore.Relations
489489
fullMetadata = make(map[string]string)
490490
}
491491
fullMetadata["relationship"] = strValue
492-
newArgs := append(args, strValue)
492+
newArgs := make([]any, 0, len(args)+len(strValue))
493+
newArgs = append(newArgs, args)
494+
newArgs = append(newArgs, strValue)
493495
return NewSchemaWriteDataValidationError(message+": %s", newArgs, fullMetadata)
494496
}
495497

0 commit comments

Comments
 (0)