From 3e4e0c361d1dea277956e7c3ceef99c14ca3c075 Mon Sep 17 00:00:00 2001 From: Daniel <dhaavi@users.noreply.github.com> Date: Tue, 1 Feb 2022 13:40:50 +0100 Subject: [PATCH] Fix or disable new linters --- .golangci.yml | 6 ++++++ database/accessor/accessor.go | 2 -- database/accessor/accessor_test.go | 2 +- database/database_test.go | 2 +- database/record/record.go | 4 ++++ formats/dsd/dsd_test.go | 2 +- formats/dsd/gencode_test.go | 4 ++-- log/output.go | 2 +- modules/subsystems/registry.go | 2 +- modules/tasks.go | 2 +- runtime/registry.go | 6 +++--- runtime/registry_test.go | 4 ++-- 12 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 468bfff..6cdc8ff 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,6 +4,8 @@ linters: enable-all: true disable: + - containedctx + - contextcheck - cyclop - exhaustivestruct - forbidigo @@ -16,12 +18,16 @@ linters: - gomnd - ifshort - interfacer + - ireturn - lll - nestif + - nilnil - nlreturn - noctx - revive + - tagliatelle - testpackage + - varnamelen - whitespace - wrapcheck - wsl diff --git a/database/accessor/accessor.go b/database/accessor/accessor.go index 9fde0e0..67a5373 100644 --- a/database/accessor/accessor.go +++ b/database/accessor/accessor.go @@ -13,8 +13,6 @@ type Accessor interface { GetFloat(key string) (value float64, ok bool) GetBool(key string) (value bool, ok bool) Exists(key string) bool - Set(key string, value interface{}) error - Type() string } diff --git a/database/accessor/accessor_test.go b/database/accessor/accessor_test.go index 302c8aa..5954c10 100644 --- a/database/accessor/accessor_test.go +++ b/database/accessor/accessor_test.go @@ -44,7 +44,7 @@ var ( F64: 42.42, B: true, } - testJSONBytes, _ = json.Marshal(testStruct) + testJSONBytes, _ = json.Marshal(testStruct) //nolint:errchkjson testJSON = string(testJSONBytes) ) diff --git a/database/database_test.go b/database/database_test.go index c4c2a30..b2d0225 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -45,7 +45,7 @@ func makeKey(dbName, key string) string { return fmt.Sprintf("%s:%s", dbName, key) } -func testDatabase(t *testing.T, storageType string, shadowDelete bool) { //nolint:gocognit,gocyclo,thelper +func testDatabase(t *testing.T, storageType string, shadowDelete bool) { //nolint:maintidx,thelper t.Run(fmt.Sprintf("TestStorage_%s_%v", storageType, shadowDelete), func(t *testing.T) { dbName := fmt.Sprintf("testing-%s-%v", storageType, shadowDelete) fmt.Println(dbName) diff --git a/database/record/record.go b/database/record/record.go index 65808f2..1da432c 100644 --- a/database/record/record.go +++ b/database/record/record.go @@ -12,17 +12,21 @@ type Record interface { DatabaseName() string // test DatabaseKey() string // config + // Metadata. Meta() *Meta SetMeta(meta *Meta) CreateMeta() UpdateMeta() + // Serialization. Marshal(self Record, format uint8) ([]byte, error) MarshalRecord(self Record) ([]byte, error) GetAccessor(self Record) accessor.Accessor + // Locking. Lock() Unlock() + // Wrapping. IsWrapped() bool } diff --git a/formats/dsd/dsd_test.go b/formats/dsd/dsd_test.go index 79fdd9b..479f727 100644 --- a/formats/dsd/dsd_test.go +++ b/formats/dsd/dsd_test.go @@ -117,7 +117,7 @@ var ( } ) -func TestConversion(t *testing.T) { +func TestConversion(t *testing.T) { //nolint:maintidx t.Parallel() compressionFormats := []uint8{AUTO, GZIP} diff --git a/formats/dsd/gencode_test.go b/formats/dsd/gencode_test.go index f1366f3..1957961 100644 --- a/formats/dsd/gencode_test.go +++ b/formats/dsd/gencode_test.go @@ -259,7 +259,7 @@ func (d *GenCodeTestStruct) Size() (s uint64) { return } -func (d *GenCodeTestStruct) GenCodeMarshal(buf []byte) ([]byte, error) { +func (d *GenCodeTestStruct) GenCodeMarshal(buf []byte) ([]byte, error) { //nolint:maintidx size := d.Size() { if uint64(cap(buf)) >= size { @@ -555,7 +555,7 @@ func (d *GenCodeTestStruct) GenCodeMarshal(buf []byte) ([]byte, error) { return buf[:i+35], nil } -func (d *GenCodeTestStruct) GenCodeUnmarshal(buf []byte) (uint64, error) { +func (d *GenCodeTestStruct) GenCodeUnmarshal(buf []byte) (uint64, error) { //nolint:maintidx i := uint64(0) { diff --git a/log/output.go b/log/output.go index 1c8f1ac..f3831c2 100644 --- a/log/output.go +++ b/log/output.go @@ -96,7 +96,7 @@ func TriggerWriterChannel() chan struct{} { } func defaultColorFormater(line Message, duplicates uint64) string { - return formatLine(line.(*logLine), duplicates, true) + return formatLine(line.(*logLine), duplicates, true) //nolint:forcetypeassert // TODO: improve } func startWriter() { diff --git a/modules/subsystems/registry.go b/modules/subsystems/registry.go index 6225b07..2914243 100644 --- a/modules/subsystems/registry.go +++ b/modules/subsystems/registry.go @@ -269,6 +269,6 @@ func (mng *Manager) findParentSubsystem(m *modules.Module) (*Subsystem, *ModuleS // Otherwise Less() will panic. type bySubsystemID []record.Record -func (sl bySubsystemID) Less(i, j int) bool { return sl[i].(*Subsystem).ID < sl[j].(*Subsystem).ID } +func (sl bySubsystemID) Less(i, j int) bool { return sl[i].(*Subsystem).ID < sl[j].(*Subsystem).ID } //nolint:forcetypeassert // Can only be *Subsystem. func (sl bySubsystemID) Swap(i, j int) { sl[i], sl[j] = sl[j], sl[i] } func (sl bySubsystemID) Len() int { return len(sl) } diff --git a/modules/tasks.go b/modules/tasks.go index a37b96e..0f23dbf 100644 --- a/modules/tasks.go +++ b/modules/tasks.go @@ -427,7 +427,7 @@ func waitUntilNextScheduledTask() <-chan time.Time { defer scheduleLock.Unlock() if taskSchedule.Len() > 0 { - return time.After(time.Until(taskSchedule.Front().Value.(*Task).executeAt)) + return time.After(time.Until(taskSchedule.Front().Value.(*Task).executeAt)) //nolint:forcetypeassert // Can only be *Task. } return waitForever } diff --git a/runtime/registry.go b/runtime/registry.go index 7fe7ee3..26235e2 100644 --- a/runtime/registry.go +++ b/runtime/registry.go @@ -278,7 +278,7 @@ func (r *Registry) getMatchingProvider(key string) *keyedValueProvider { return nil } - return provider.(*keyedValueProvider) + return provider.(*keyedValueProvider) //nolint:forcetypeassert } func (r *Registry) collectProviderByPrefix(prefix string) []*keyedValueProvider { @@ -288,12 +288,12 @@ func (r *Registry) collectProviderByPrefix(prefix string) []*keyedValueProvider // if there's a LongestPrefix provider that's the only one // we need to ask if _, p, ok := r.providers.LongestPrefix(prefix); ok { - return []*keyedValueProvider{p.(*keyedValueProvider)} + return []*keyedValueProvider{p.(*keyedValueProvider)} //nolint:forcetypeassert } var providers []*keyedValueProvider r.providers.WalkPrefix(prefix, func(key string, p interface{}) bool { - providers = append(providers, p.(*keyedValueProvider)) + providers = append(providers, p.(*keyedValueProvider)) //nolint:forcetypeassert return false }) diff --git a/runtime/registry_test.go b/runtime/registry_test.go index 84f88b5..f4459ca 100644 --- a/runtime/registry_test.go +++ b/runtime/registry_test.go @@ -84,12 +84,12 @@ func TestRegistryGet(t *testing.T) { r, err = reg.Get("p1/f1/v1") require.NoError(t, err) require.NotNil(t, r) - assert.Equal(t, "p1.1", r.(*testRecord).Value) + assert.Equal(t, "p1.1", r.(*testRecord).Value) //nolint:forcetypeassert r, err = reg.Get("p1/v3") require.NoError(t, err) require.NotNil(t, r) - assert.Equal(t, "p1.3", r.(*testRecord).Value) + assert.Equal(t, "p1.3", r.(*testRecord).Value) //nolint:forcetypeassert r, err = reg.Get("p1/v4") require.Error(t, err)