Skip to content

Commit f41f641

Browse files
committed
chore: add perfsprint linter
1 parent 769a67e commit f41f641

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+189
-154
lines changed

.golangci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ linters:
2828
- "importas"
2929
- "ineffassign"
3030
- "makezero"
31+
- "perfsprint"
3132
- "prealloc"
3233
- "predeclared"
3334
- "promlinter"
@@ -90,6 +91,9 @@ linters:
9091
- linters:
9192
- "revive"
9293
text: 'receiver-naming: receiver name \S+ should be consistent with previous receiver name \S+ for invalid-type'
94+
- linters:
95+
- "perfsprint"
96+
path: '(.+)_test\.go'
9397
paths:
9498
- "third_party$"
9599
- "builtin$"

internal/caveats/run.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package caveats
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"maps"
87

98
"go.opentelemetry.io/otel"
@@ -95,7 +94,7 @@ func (cr *CaveatRunner) PopulateCaveatDefinitionsForExpr(ctx context.Context, ex
9594
span.SetAttributes(attribute.StringSlice(otelconv.AttrCaveatsNames, caveatNames.AsSlice()))
9695

9796
if caveatNames.IsEmpty() {
98-
return fmt.Errorf("received empty caveat expression")
97+
return errors.New("received empty caveat expression")
9998
}
10099

101100
// Remove any caveats already loaded.
@@ -416,7 +415,7 @@ func (sr syntheticResult) MissingVarNames() ([]string, error) {
416415
return missingVarNames.AsSlice(), nil
417416
}
418417

419-
return nil, fmt.Errorf("not a partial value")
418+
return nil, errors.New("not a partial value")
420419
}
421420

422421
func isFalseResult(result ExpressionResult) bool {

internal/datasets/subjectsetbyresourceid.go

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

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

67
v1 "github.com/authzed/spicedb/pkg/proto/dispatch/v1"
@@ -22,7 +23,7 @@ type SubjectSetByResourceID struct {
2223

2324
func (ssr SubjectSetByResourceID) add(resourceID string, subject *v1.FoundSubject) error {
2425
if subject == nil {
25-
return fmt.Errorf("cannot add a nil subject to SubjectSetByResourceID")
26+
return errors.New("cannot add a nil subject to SubjectSetByResourceID")
2627
}
2728

2829
_, ok := ssr.subjectSetByResourceID[resourceID]

internal/datastore/common/relationships.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package common
33
import (
44
"context"
55
"database/sql"
6+
"errors"
67
"fmt"
78
"time"
89

@@ -79,7 +80,7 @@ func runExplainIfNecessary[R Rows](ctx context.Context, builder RelationshipsQue
7980
explainString += explain + "\n"
8081
}
8182
if explainString == "" {
82-
return fmt.Errorf("received empty explain")
83+
return errors.New("received empty explain")
8384
}
8485

8586
return builder.SQLExplainCallbackForTest(ctx, sqlString, args, builder.queryShape, explainString, expectedIndexes)

internal/datastore/crdb/crdb.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func newCRDBDatastore(ctx context.Context, url string, options ...Option) (datas
145145
switch config.overlapStrategy {
146146
case overlapStrategyStatic:
147147
if len(config.overlapKey) == 0 {
148-
return nil, fmt.Errorf("static tx overlap strategy specified without an overlap key")
148+
return nil, errors.New("static tx overlap strategy specified without an overlap key")
149149
}
150150
keyer = appendStaticKey(config.overlapKey)
151151
case overlapStrategyPrefix:
@@ -577,7 +577,7 @@ func (cds *crdbDatastore) features(ctx context.Context) (*datastore.Features, er
577577
}
578578

579579
features.Watch.Status = datastore.FeatureUnsupported
580-
features.Watch.Reason = fmt.Sprintf("Range feeds must be enabled in CockroachDB and the user must have permission to create them in order to enable the Watch API: %s", err.Error())
580+
features.Watch.Reason = "Range feeds must be enabled in CockroachDB and the user must have permission to create them in order to enable the Watch API: " + err.Error()
581581
return nil
582582
}, fmt.Sprintf(cds.beginChangefeedQuery, cds.schema.RelationshipTableName, head, "-1s"))
583583
} else {
@@ -626,7 +626,7 @@ func readClusterTTLNanos(ctx context.Context, conn pgxcommon.DBFuncQuerier) (int
626626

627627
groups := gcTTLRegex.FindStringSubmatch(configSQL)
628628
if groups == nil || len(groups) != 2 {
629-
return 0, fmt.Errorf("CRDB zone config unexpected format")
629+
return 0, errors.New("CRDB zone config unexpected format")
630630
}
631631

632632
gcSeconds, err := strconv.ParseInt(groups[1], 10, 64)

internal/datastore/crdb/watch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (cds *crdbDatastore) Watch(ctx context.Context, afterRevision datastore.Rev
9393

9494
if features.Watch.Status != datastore.FeatureSupported {
9595
close(updates)
96-
errs <- datastore.NewWatchDisabledErr(fmt.Sprintf("%s. See https://spicedb.dev/d/enable-watch-api-crdb", features.Watch.Reason))
96+
errs <- datastore.NewWatchDisabledErr(features.Watch.Reason + ". See https://spicedb.dev/d/enable-watch-api-crdb")
9797
return updates, errs
9898
}
9999
}
@@ -147,12 +147,12 @@ func (cds *crdbDatastore) watch(
147147
}
148148

149149
if len(tableNames) == 0 {
150-
errs <- fmt.Errorf("at least relationships or schema must be specified")
150+
errs <- errors.New("at least relationships or schema must be specified")
151151
return
152152
}
153153

154154
if opts.CheckpointInterval < 0 {
155-
errs <- fmt.Errorf("invalid checkpoint interval given")
155+
errs <- errors.New("invalid checkpoint interval given")
156156
return
157157
}
158158

internal/datastore/dsfortesting/dsfortesting.go

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

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"time"
78

@@ -84,7 +85,7 @@ func (vr validatingReader) QueryRelationships(
8485

8586
_, _ = executor.ExecuteQuery(ctx, qBuilder, options...)
8687
if builder == nil {
87-
return nil, fmt.Errorf("no builder returned")
88+
return nil, errors.New("no builder returned")
8889
}
8990

9091
checkStaticField := func(returnedValue string, fieldName string) error {

internal/datastore/memdb/memdb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (mdb *memdbDatastore) SnapshotReader(dr datastore.Revision) datastore.Reade
120120
}
121121

122122
if len(mdb.revisions) == 0 {
123-
return &memdbReader{nil, nil, fmt.Errorf("memdb datastore is not ready"), time.Now()}
123+
return &memdbReader{nil, nil, errors.New("memdb datastore is not ready"), time.Now()}
124124
}
125125

126126
if err := mdb.checkRevisionLocalCallerMustLock(dr); err != nil {
@@ -138,7 +138,7 @@ func (mdb *memdbDatastore) SnapshotReader(dr datastore.Revision) datastore.Reade
138138

139139
rev := mdb.revisions[revIndex]
140140
if rev.db == nil {
141-
return &memdbReader{nil, nil, fmt.Errorf("memdb datastore is already closed"), time.Now()}
141+
return &memdbReader{nil, nil, errors.New("memdb datastore is already closed"), time.Now()}
142142
}
143143

144144
roTxn := rev.db.Txn(false)

internal/datastore/memdb/readwrite.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package memdb
33
import (
44
"cmp"
55
"context"
6+
"errors"
67
"fmt"
78
"strings"
89

@@ -313,7 +314,7 @@ func (rwt *memdbReadWriteTx) DeleteNamespaces(_ context.Context, nsNames ...stri
313314
}
314315

315316
if foundRaw == nil {
316-
return fmt.Errorf("namespace not found")
317+
return errors.New("namespace not found")
317318
}
318319

319320
if err := tx.Delete(tableNamespace, foundRaw); err != nil {

internal/datastore/postgres/postgres.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var (
8080
getRevisionForGC = psql.
8181
Select(schema.ColXID, schema.ColSnapshot).
8282
From(schema.TableTransaction).
83-
OrderByClause(fmt.Sprintf("%s DESC", schema.ColXID)).
83+
OrderByClause(schema.ColXID + " DESC").
8484
Limit(1)
8585

8686
createTxn = psql.Insert(schema.TableTransaction).Columns(schema.ColMetadata)
@@ -243,7 +243,7 @@ func newPostgresDatastore(
243243
replicaIndexStr := strconv.Itoa(replicaIndex)
244244
dbname := "spicedb"
245245
if replicaIndex != primaryInstanceID {
246-
dbname = fmt.Sprintf("spicedb_replica_%s", replicaIndexStr)
246+
dbname = "spicedb_replica_" + replicaIndexStr
247247
}
248248

249249
if err := prometheus.Register(pgxpoolprometheus.NewCollector(readPool, map[string]string{
@@ -533,7 +533,7 @@ func (pgd *pgDatastore) Repair(ctx context.Context, operationName string, output
533533
return pgd.repairTransactionIDs(ctx, outputProgress)
534534

535535
default:
536-
return fmt.Errorf("unknown operation")
536+
return errors.New("unknown operation")
537537
}
538538
}
539539

0 commit comments

Comments
 (0)