Skip to content

Commit ce17b29

Browse files
Lint fixes part 12 (#2668)
Co-authored-by: James Thomas <[email protected]>
1 parent 45508c2 commit ce17b29

File tree

12 files changed

+53
-48
lines changed

12 files changed

+53
-48
lines changed

internal/datastore/postgres/xid8.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ func (Uint64Codec) PlanEncode(_ *pgtype.Map, _ uint32, format int16, value any)
7171
return encodePlanUint64CodecBinaryUint64Valuer{}
7272
}
7373
case pgtype.TextFormatCode:
74-
switch value.(type) { //nolint:gocritic
75-
case uint64:
74+
if _, ok := value.(uint64); ok {
7675
return encodePlanUint64CodecTextUint64{}
7776
}
7877
}

pkg/cmd/datastore/datastore.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ func DefaultReadConnPool() *ConnPoolConfig {
7070

7171
func DefaultWriteConnPool() *ConnPoolConfig {
7272
cfg := DefaultReadConnPool()
73-
cfg.MaxOpenConns = cfg.MaxOpenConns / 2
74-
cfg.MinOpenConns = cfg.MinOpenConns / 2
73+
cfg.MaxOpenConns /= 2
74+
cfg.MinOpenConns /= 2
7575
return cfg
7676
}
7777

7878
func RegisterConnPoolFlagsWithPrefix(flagSet *pflag.FlagSet, prefix string, defaults, opts *ConnPoolConfig) {
7979
if prefix != "" {
80-
prefix = prefix + "-"
80+
prefix += "-"
8181
}
8282
flagName := func(flag string) string {
8383
return prefix + flag
@@ -199,7 +199,7 @@ func RegisterDatastoreFlags(flagset *pflag.FlagSet, opts *Config) error {
199199
// prefix argument. If left empty, the datastore flags are not prefixed.
200200
func RegisterDatastoreFlagsWithPrefix(flagSet *pflag.FlagSet, prefix string, opts *Config) error {
201201
if prefix != "" {
202-
prefix = prefix + "-"
202+
prefix += "-"
203203
}
204204
flagName := func(flag string) string {
205205
return prefix + flag

pkg/cmd/server/server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,12 @@ func (c *Config) Complete(ctx context.Context) (RunnableServer, error) {
540540
var telemetryRegistry *prometheus.Registry
541541

542542
reporter := telemetry.DisabledReporter
543-
if c.SilentlyDisableTelemetry {
543+
switch {
544+
case c.SilentlyDisableTelemetry:
544545
reporter = telemetry.SilentlyDisabledReporter
545-
} else if c.TelemetryEndpoint != "" && c.DatastoreConfig.DisableStats {
546+
case c.TelemetryEndpoint != "" && c.DatastoreConfig.DisableStats:
546547
reporter = telemetry.DisabledReporter
547-
} else if c.TelemetryEndpoint != "" {
548+
case c.TelemetryEndpoint != "":
548549
log.Ctx(ctx).Debug().Msg("initializing telemetry collector")
549550
registry, err := telemetry.RegisterTelemetryCollector(c.DatastoreConfig.Engine, ds)
550551
if err != nil {

pkg/cmd/server/server_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ func TestOTelReporting(t *testing.T) {
113113

114114
schemaSrv := v1.NewSchemaServiceClient(conn)
115115

116+
runErrCh := make(chan error, 1)
116117
go func() {
117-
require.NoError(t, srv.Run(ctx))
118+
runErrCh <- srv.Run(ctx)
118119
}()
119120

120121
// test unary OTel middleware
@@ -140,6 +141,7 @@ func TestOTelReporting(t *testing.T) {
140141
require.Error(t, err)
141142

142143
requireSpanExists(t, spanrecorder, "authzed.api.v1.PermissionsService/LookupResources")
144+
require.NoError(t, <-runErrCh)
143145
}
144146

145147
func TestDisableHealthCheckTracing(t *testing.T) {

pkg/composableschemadsl/compiler/compiler_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,24 +1353,23 @@ func TestCompile(t *testing.T) {
13531353

13541354
func filterSourcePositions(m protoreflect.Message) {
13551355
m.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
1356-
if fd.Kind() == protoreflect.MessageKind {
1357-
if fd.IsList() {
1358-
l := v.List()
1359-
for i := 0; i < l.Len(); i++ {
1360-
filterSourcePositions(l.Get(i).Message())
1361-
}
1362-
} else if fd.IsMap() {
1363-
m := v.Map()
1364-
m.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool {
1365-
filterSourcePositions(v.Message())
1366-
return true
1367-
})
1356+
switch {
1357+
case fd.Kind() == protoreflect.MessageKind && fd.IsList():
1358+
l := v.List()
1359+
for i := 0; i < l.Len(); i++ {
1360+
filterSourcePositions(l.Get(i).Message())
1361+
}
1362+
case fd.Kind() == protoreflect.MessageKind && fd.IsMap():
1363+
m := v.Map()
1364+
m.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool {
1365+
filterSourcePositions(v.Message())
1366+
return true
1367+
})
1368+
case fd.Kind() == protoreflect.MessageKind:
1369+
if string(fd.Message().Name()) == "SourcePosition" {
1370+
m.Clear(fd)
13681371
} else {
1369-
if string(fd.Message().Name()) == "SourcePosition" {
1370-
m.Clear(fd)
1371-
} else {
1372-
filterSourcePositions(v.Message())
1373-
}
1372+
filterSourcePositions(v.Message())
13741373
}
13751374
}
13761375
return true

pkg/composableschemadsl/compiler/translator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,9 @@ func translateExpressionDirect(tctx *translationContext, expressionNode *dslNode
514514
if err != nil {
515515
return nil, err
516516
}
517-
leftOps := collapseOps(leftOperation, lookup)
518-
rightOps := collapseOps(rightOperation, lookup)
519-
ops := append(leftOps, rightOps...)
517+
var ops []*core.SetOperation_Child
518+
ops = append(ops, collapseOps(leftOperation, lookup)...)
519+
ops = append(ops, collapseOps(rightOperation, lookup)...)
520520
return builder(ops[0], ops[1:]...), nil
521521
}
522522

pkg/composableschemadsl/lexer/lex_def.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,16 @@ func lexStringLiteral(l *Lexer) stateFn {
267267
allowNewlines := false
268268
terminator := ""
269269

270-
if l.acceptString(`"""`) {
270+
switch {
271+
case l.acceptString(`"""`):
271272
terminator = `"""`
272273
allowNewlines = true
273-
} else if l.acceptString(`'''`) {
274+
case l.acceptString(`'''`):
274275
terminator = `"""`
275276
allowNewlines = true
276-
} else if l.acceptString(`"`) {
277+
case l.acceptString(`"`):
277278
terminator = `"`
278-
} else if l.acceptString(`'`) {
279+
case l.acceptString(`'`):
279280
terminator = `'`
280281
}
281282

pkg/schema/type_check.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ func (ts *TypeSystem) getTypesForRelationInternal(ctx context.Context, defName s
6363
func (ts *TypeSystem) getTypesForInfo(ctx context.Context, rel *corev1.TypeInformation, seen *mapz.Set[string], nonTerminals *mapz.Set[string]) (*mapz.Set[string], error) {
6464
out := mapz.NewSet[string]()
6565
for _, dr := range rel.GetAllowedDirectRelations() {
66-
if dr.GetRelation() == ellipsesRelation {
66+
switch {
67+
case dr.GetRelation() == ellipsesRelation:
6768
out.Add(dr.GetNamespace())
68-
} else if dr.GetRelation() != "" {
69+
case dr.GetRelation() != "":
6970
if nonTerminals != nil {
7071
nonTerminals.Add(fmt.Sprintf("%s#%s", dr.GetNamespace(), dr.GetRelation()))
7172
}
@@ -77,7 +78,7 @@ func (ts *TypeSystem) getTypesForInfo(ctx context.Context, rel *corev1.TypeInfor
7778
continue
7879
}
7980
out.Merge(rest)
80-
} else {
81+
default:
8182
// It's a wildcard, so all things of that type count
8283
out.Add(dr.GetNamespace())
8384
}

pkg/schemadsl/compiler/translator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,9 @@ func translateExpressionDirect(tctx *translationContext, expressionNode *dslNode
503503
if err != nil {
504504
return nil, err
505505
}
506-
leftOps := collapseOps(leftOperation, lookup)
507-
rightOps := collapseOps(rightOperation, lookup)
508-
ops := append(leftOps, rightOps...)
506+
var ops []*core.SetOperation_Child
507+
ops = append(ops, collapseOps(leftOperation, lookup)...)
508+
ops = append(ops, collapseOps(rightOperation, lookup)...)
509509
return builder(ops[0], ops[1:]...), nil
510510
}
511511

pkg/schemadsl/generator/generator_impl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ func (sg *sourceGenerator) ensureBlankLineOrNewScope() {
2929

3030
// indent increases the current indentation.
3131
func (sg *sourceGenerator) indent() {
32-
sg.indentationLevel = sg.indentationLevel + 1
32+
sg.indentationLevel++
3333
}
3434

3535
// dedent decreases the current indentation.
3636
func (sg *sourceGenerator) dedent() {
37-
sg.indentationLevel = sg.indentationLevel - 1
37+
sg.indentationLevel--
3838
}
3939

4040
// appendIssue adds an issue found in generation.

0 commit comments

Comments
 (0)