From 493ec396fab32d9e8859e34ad497fdb0a910a33c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 17:49:11 -0700 Subject: lint: Turn on forcetypeassert --- lib/containers/lru.go | 5 ++++- lib/containers/set.go | 7 +++++-- lib/containers/syncmap.go | 6 +++++- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'lib/containers') diff --git a/lib/containers/lru.go b/lib/containers/lru.go index a235a12..12446b0 100644 --- a/lib/containers/lru.go +++ b/lib/containers/lru.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -44,6 +44,7 @@ func (c *LRUCache[K, V]) Get(key K) (value V, ok bool) { c.init() _value, ok := c.inner.Get(key) if ok { + //nolint:forcetypeassert // Typed wrapper around untyped lib. value = _value.(V) } return value, ok @@ -53,6 +54,7 @@ func (c *LRUCache[K, V]) Keys() []K { untyped := c.inner.Keys() typed := make([]K, len(untyped)) for i := range untyped { + //nolint:forcetypeassert // Typed wrapper around untyped lib. typed[i] = untyped[i].(K) } return typed @@ -65,6 +67,7 @@ func (c *LRUCache[K, V]) Peek(key K) (value V, ok bool) { c.init() _value, ok := c.inner.Peek(key) if ok { + //nolint:forcetypeassert // Typed wrapper around untyped lib. value = _value.(V) } return value, ok diff --git a/lib/containers/set.go b/lib/containers/set.go index 67ba7ac..4fc8aad 100644 --- a/lib/containers/set.go +++ b/lib/containers/set.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -22,7 +22,10 @@ var ( _ lowmemjson.Decodable = (*Set[int])(nil) ) -func cast[T any](x any) T { return x.(T) } +func cast[T any](x any) T { + //nolint:forcetypeassert // Only called within a type switch. + return x.(T) +} func (o Set[T]) EncodeJSON(w io.Writer) error { var less func(a, b T) bool diff --git a/lib/containers/syncmap.go b/lib/containers/syncmap.go index fb7f59b..4af678f 100644 --- a/lib/containers/syncmap.go +++ b/lib/containers/syncmap.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -18,6 +18,7 @@ func (m *SyncMap[K, V]) Delete(key K) { func (m *SyncMap[K, V]) Load(key K) (value V, ok bool) { _value, ok := m.inner.Load(key) if ok { + //nolint:forcetypeassert // Typed wrapper around untyped lib. value = _value.(V) } return value, ok @@ -25,17 +26,20 @@ func (m *SyncMap[K, V]) Load(key K) (value V, ok bool) { func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool) { _value, ok := m.inner.LoadAndDelete(key) if ok { + //nolint:forcetypeassert // Typed wrapper around untyped lib. value = _value.(V) } return value, ok } func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool) { _actual, loaded := m.inner.LoadOrStore(key, value) + //nolint:forcetypeassert // Typed wrapper around untyped lib. actual = _actual.(V) return actual, loaded } func (m *SyncMap[K, V]) Range(f func(key K, value V) bool) { m.inner.Range(func(key, value any) bool { + //nolint:forcetypeassert // Typed wrapper around untyped lib. return f(key.(K), value.(V)) }) } -- cgit v1.2.3-2-g168b