Skip to content

Commit

Permalink
chore: linting (#15814)
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle authored Apr 12, 2023
1 parent 37032fb commit 1641bb9
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 51 deletions.
3 changes: 1 addition & 2 deletions orm/encoding/ormkv/unique_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ func TestUniqueKeyCodec(t *testing.T) {
if isTrivialUniqueKey {
assert.ErrorContains(t, err, "no new uniqueness constraint")
return
} else {
assert.NilError(t, err)
}
assert.NilError(t, err)

for i := 0; i < 100; i++ {
a := testutil.GenA.Draw(t, fmt.Sprintf("a%d", i))
Expand Down
2 changes: 1 addition & 1 deletion orm/internal/codegen/file.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// nolint"unused" // ignore unused code linting
// nolint:unused // ignore unused code linting
package codegen

import (
Expand Down
8 changes: 4 additions & 4 deletions orm/model/ormtable/auto_increment.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ func (t autoIncrementTable) ValidateJSON(reader io.Reader) error {

if t.customJSONValidator != nil {
return t.customJSONValidator(message)
} else {
return DefaultJSONValidator(message)
}

return DefaultJSONValidator(message)
})
}

Expand Down Expand Up @@ -175,14 +175,14 @@ func (t autoIncrementTable) ImportJSON(ctx context.Context, reader io.Reader) er
}

func (t autoIncrementTable) decodeAutoIncJSON(backend Backend, reader io.Reader, onMsg func(message proto.Message, maxID uint64) error) error {
decoder, err := t.startDecodeJson(reader)
decoder, err := t.startDecodeJSON(reader)
if err != nil {
return err
}

var seq uint64

return t.doDecodeJson(decoder,
return t.doDecodeJSON(decoder,
func(message json.RawMessage) bool {
err = json.Unmarshal(message, &seq)
if err == nil {
Expand Down
7 changes: 4 additions & 3 deletions orm/model/ormtable/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ func flushWrites(store kv.Store, writer *batchStoreWriter) error {

func flushBuf(store kv.Store, writes []*batchWriterEntry) error {
for _, write := range writes {
if write.hookCall != nil {
switch {
case write.hookCall != nil:
write.hookCall()
} else if !write.delete {
case !write.delete:
err := store.Set(write.key, write.value)
if err != nil {
return err
}
} else {
default:
err := store.Delete(write.key)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions orm/model/ormtable/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func bench(b *testing.B, newBackend func(testing.TB) ormtable.Backend) {
})
}

func benchInsert(b *testing.B, ctx context.Context) {
func benchInsert(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
balanceTable := initBalanceTable(b)
for i := 0; i < b.N; i++ {
assert.NilError(b, balanceTable.Insert(ctx, &testpb.Balance{
Expand All @@ -81,7 +81,7 @@ func benchInsert(b *testing.B, ctx context.Context) {
}
}

func benchUpdate(b *testing.B, ctx context.Context) {
func benchUpdate(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
balanceTable := initBalanceTable(b)
for i := 0; i < b.N; i++ {
assert.NilError(b, balanceTable.Update(ctx, &testpb.Balance{
Expand All @@ -92,7 +92,7 @@ func benchUpdate(b *testing.B, ctx context.Context) {
}
}

func benchGet(b *testing.B, ctx context.Context) {
func benchGet(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
balanceTable := initBalanceTable(b)
for i := 0; i < b.N; i++ {
balance, err := balanceTable.Get(ctx, fmt.Sprintf("acct%d", i), "bar")
Expand All @@ -101,7 +101,7 @@ func benchGet(b *testing.B, ctx context.Context) {
}
}

func benchDelete(b *testing.B, ctx context.Context) {
func benchDelete(b *testing.B, ctx context.Context) { //nolint:revive // ignore for benchmark
balanceTable := initBalanceTable(b)
for i := 0; i < b.N; i++ {
assert.NilError(b, balanceTable.Delete(ctx, &testpb.Balance{
Expand Down
38 changes: 19 additions & 19 deletions orm/model/ormtable/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

const (
primaryKeyId uint32 = 0
indexIdLimit uint32 = 32768
seqId = indexIdLimit
primaryKeyID uint32 = 0
indexIDLimit uint32 = 32768
seqID = indexIDLimit
)

// Options are options for building a Table.
Expand Down Expand Up @@ -84,8 +84,8 @@ func Build(options Options) (Table, error) {
indexes: []Index{},
indexesByFields: map[fieldnames.FieldNames]concreteIndex{},
uniqueIndexesByFields: map[fieldnames.FieldNames]UniqueIndex{},
entryCodecsById: map[uint32]ormkv.EntryCodec{},
indexesById: map[uint32]Index{},
entryCodecsByID: map[uint32]ormkv.EntryCodec{},
indexesByID: map[uint32]Index{},
typeResolver: options.TypeResolver,
customJSONValidator: options.JSONValidator,
}
Expand Down Expand Up @@ -125,22 +125,22 @@ func Build(options Options) (Table, error) {

pkIndex.PrimaryKeyCodec = pkCodec
table.tablePrefix = prefix
table.tableId = singletonDesc.Id
table.tableID = singletonDesc.Id

return &singleton{table}, nil
default:
return nil, ormerrors.NoTableDescriptor.Wrapf("missing table descriptor for %s", messageDescriptor.FullName())
}

tableId := tableDesc.Id
if tableId == 0 {
tableID := tableDesc.Id
if tableID == 0 {
return nil, ormerrors.InvalidTableId.Wrapf("table %s", messageDescriptor.FullName())
}

prefix := options.Prefix
prefix = encodeutil.AppendVarUInt32(prefix, tableId)
prefix = encodeutil.AppendVarUInt32(prefix, tableID)
table.tablePrefix = prefix
table.tableId = tableId
table.tableID = tableID

if tableDesc.PrimaryKey == nil {
return nil, ormerrors.MissingPrimaryKey.Wrap(string(messageDescriptor.FullName()))
Expand All @@ -153,7 +153,7 @@ func Build(options Options) (Table, error) {
return nil, ormerrors.InvalidTableDefinition.Wrapf("empty primary key fields for %s", messageDescriptor.FullName())
}

pkPrefix := encodeutil.AppendVarUInt32(prefix, primaryKeyId)
pkPrefix := encodeutil.AppendVarUInt32(prefix, primaryKeyID)
pkCodec, err := ormkv.NewPrimaryKeyCodec(
pkPrefix,
options.MessageType,
Expand All @@ -167,17 +167,17 @@ func Build(options Options) (Table, error) {
pkIndex.PrimaryKeyCodec = pkCodec
table.indexesByFields[pkFields] = pkIndex
table.uniqueIndexesByFields[pkFields] = pkIndex
table.entryCodecsById[primaryKeyId] = pkIndex
table.indexesById[primaryKeyId] = pkIndex
table.entryCodecsByID[primaryKeyID] = pkIndex
table.indexesByID[primaryKeyID] = pkIndex
table.indexes = append(table.indexes, pkIndex)

for _, idxDesc := range tableDesc.Index {
id := idxDesc.Id
if id == 0 || id >= indexIdLimit {
if id == 0 || id >= indexIDLimit {
return nil, ormerrors.InvalidIndexId.Wrapf("index on table %s with fields %s, invalid id %d", messageDescriptor.FullName(), idxDesc.Fields, id)
}

if _, ok := table.entryCodecsById[id]; ok {
if _, ok := table.entryCodecsByID[id]; ok {
return nil, ormerrors.DuplicateIndexId.Wrapf("id %d on table %s", id, messageDescriptor.FullName())
}

Expand Down Expand Up @@ -264,8 +264,8 @@ func Build(options Options) (Table, error) {
table.indexesByFields[name] = index
}

table.entryCodecsById[id] = index
table.indexesById[id] = index
table.entryCodecsByID[id] = index
table.indexesByID[id] = index
table.indexes = append(table.indexes, index)
table.indexers = append(table.indexers, index.(indexer))
}
Expand All @@ -276,9 +276,9 @@ func Build(options Options) (Table, error) {
return nil, ormerrors.InvalidAutoIncrementKey.Wrapf("field %s", autoIncField.FullName())
}

seqPrefix := encodeutil.AppendVarUInt32(prefix, seqId)
seqPrefix := encodeutil.AppendVarUInt32(prefix, seqID)
seqCodec := ormkv.NewSeqCodec(options.MessageType, seqPrefix)
table.entryCodecsById[seqId] = seqCodec
table.entryCodecsByID[seqID] = seqCodec
return &autoIncrementTable{
tableImpl: table,
autoIncField: autoIncField,
Expand Down
4 changes: 2 additions & 2 deletions orm/model/ormtable/index_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ func (i indexKeyIndex) readValueFromIndexKey(backend ReadBackend, primaryKey []p
return nil
}

func (p indexKeyIndex) Fields() string {
return p.fields.String()
func (i indexKeyIndex) Fields() string {
return i.fields.String()
}
4 changes: 2 additions & 2 deletions orm/model/ormtable/singleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func (t singleton) ValidateJSON(reader io.Reader) error {

if t.customJSONValidator != nil {
return t.customJSONValidator(msg)
} else {
return DefaultJSONValidator(msg)
}

return DefaultJSONValidator(msg)
}

func (t singleton) ImportJSON(ctx context.Context, reader io.Reader) error {
Expand Down
26 changes: 13 additions & 13 deletions orm/model/ormtable/table_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ type tableImpl struct {
indexes []Index
indexesByFields map[fieldnames.FieldNames]concreteIndex
uniqueIndexesByFields map[fieldnames.FieldNames]UniqueIndex
indexesById map[uint32]Index
entryCodecsById map[uint32]ormkv.EntryCodec
indexesByID map[uint32]Index
entryCodecsByID map[uint32]ormkv.EntryCodec
tablePrefix []byte
tableId uint32
tableID uint32
typeResolver TypeResolver
customJSONValidator func(message proto.Message) error
}
Expand All @@ -44,7 +44,7 @@ func (t tableImpl) PrimaryKey() UniqueIndex {
}

func (t tableImpl) GetIndexByID(id uint32) Index {
return t.indexesById[id]
return t.indexesByID[id]
}

func (t tableImpl) Save(ctx context.Context, message proto.Message) error {
Expand Down Expand Up @@ -187,16 +187,16 @@ func (t tableImpl) DefaultJSON() json.RawMessage {
return json.RawMessage("[]")
}

func (t tableImpl) decodeJson(reader io.Reader, onMsg func(message proto.Message) error) error {
decoder, err := t.startDecodeJson(reader)
func (t tableImpl) decodeJSON(reader io.Reader, onMsg func(message proto.Message) error) error {
decoder, err := t.startDecodeJSON(reader)
if err != nil {
return err
}

return t.doDecodeJson(decoder, nil, onMsg)
return t.doDecodeJSON(decoder, nil, onMsg)
}

func (t tableImpl) startDecodeJson(reader io.Reader) (*json.Decoder, error) {
func (t tableImpl) startDecodeJSON(reader io.Reader) (*json.Decoder, error) {
decoder := json.NewDecoder(reader)
token, err := decoder.Token()
if err != nil {
Expand All @@ -213,7 +213,7 @@ func (t tableImpl) startDecodeJson(reader io.Reader) (*json.Decoder, error) {
// onFirst is called on the first RawMessage and used for auto-increment tables
// to decode the sequence in which case it should return true.
// onMsg is called on every decoded message
func (t tableImpl) doDecodeJson(decoder *json.Decoder, onFirst func(message json.RawMessage) bool, onMsg func(message proto.Message) error) error {
func (t tableImpl) doDecodeJSON(decoder *json.Decoder, onFirst func(message json.RawMessage) bool, onMsg func(message proto.Message) error) error {
unmarshalOptions := protojson.UnmarshalOptions{Resolver: t.typeResolver}

first := true
Expand Down Expand Up @@ -280,7 +280,7 @@ func DefaultJSONValidator(message proto.Message) error {
}

func (t tableImpl) ValidateJSON(reader io.Reader) error {
return t.decodeJson(reader, func(message proto.Message) error {
return t.decodeJSON(reader, func(message proto.Message) error {
if t.customJSONValidator != nil {
return t.customJSONValidator(message)
}
Expand All @@ -295,7 +295,7 @@ func (t tableImpl) ImportJSON(ctx context.Context, reader io.Reader) error {
return err
}

return t.decodeJson(reader, func(message proto.Message) error {
return t.decodeJSON(reader, func(message proto.Message) error {
return t.save(ctx, backend, message, saveModeDefault)
})
}
Expand Down Expand Up @@ -366,7 +366,7 @@ func (t tableImpl) DecodeEntry(k, v []byte) (ormkv.Entry, error) {
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("uint32 varint id out of range %d", id)
}

idx, ok := t.entryCodecsById[uint32(id)]
idx, ok := t.entryCodecsByID[uint32(id)]
if !ok {
return nil, ormerrors.UnexpectedDecodePrefix.Wrapf("can't find field with id %d", id)
}
Expand All @@ -391,7 +391,7 @@ func (t tableImpl) EncodeEntry(entry ormkv.Entry) (k, v []byte, err error) {
}

func (t tableImpl) ID() uint32 {
return t.tableId
return t.tableID
}

func (t tableImpl) Has(ctx context.Context, message proto.Message) (found bool, err error) {
Expand Down
2 changes: 1 addition & 1 deletion orm/model/ormtable/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ func TestJSONExportImport(t *testing.T) {
assertTablesEqual(t, table, store, store2)
}

func assertTablesEqual(t assert.TestingT, table ormtable.Table, ctx, ctx2 context.Context) {
func assertTablesEqual(t assert.TestingT, table ormtable.Table, ctx, ctx2 context.Context) { //nolint:revive // ignore long function name
it, err := table.List(ctx, nil)
assert.NilError(t, err)
it2, err := table.List(ctx2, nil)
Expand Down

0 comments on commit 1641bb9

Please sign in to comment.