chore: enable use-any from revive

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2025-01-17 07:58:10 +01:00
parent 5b1738abf8
commit cbba3bdde7
139 changed files with 798 additions and 799 deletions
+11 -11
View File
@@ -37,8 +37,8 @@ type logrusAdapter struct {
// args are alternating key, value pairs, where the keys
// are expected to be strings, and values can be any type.
func argsToFields(args ...interface{}) logrus.Fields {
fields := make(map[string]interface{})
func argsToFields(args ...any) logrus.Fields {
fields := make(map[string]any)
for i := 0; i < len(args); i += 2 {
switch args[i] {
@@ -52,7 +52,7 @@ func argsToFields(args ...interface{}) logrus.Fields {
// to log at based on the hclog-compatible `@level` field which
// we're adding via HcLogLevelHook).
default:
var val interface{}
var val any
if i+1 < len(args) {
val = args[i+1]
}
@@ -66,27 +66,27 @@ func argsToFields(args ...interface{}) logrus.Fields {
// Trace emits a message and key/value pairs at the DEBUG level
// (logrus doesn't have a TRACE level)
func (l *logrusAdapter) Trace(msg string, args ...interface{}) {
func (l *logrusAdapter) Trace(msg string, args ...any) {
l.Debug(msg, args...)
}
// Debug emits a message and key/value pairs at the DEBUG level
func (l *logrusAdapter) Debug(msg string, args ...interface{}) {
func (l *logrusAdapter) Debug(msg string, args ...any) {
l.impl.WithFields(argsToFields(args...)).Debug(msg)
}
// Info emits a message and key/value pairs at the INFO level
func (l *logrusAdapter) Info(msg string, args ...interface{}) {
func (l *logrusAdapter) Info(msg string, args ...any) {
l.impl.WithFields(argsToFields(args...)).Info(msg)
}
// Warn emits a message and key/value pairs at the WARN level
func (l *logrusAdapter) Warn(msg string, args ...interface{}) {
func (l *logrusAdapter) Warn(msg string, args ...any) {
l.impl.WithFields(argsToFields(args...)).Warn(msg)
}
// Error emits a message and key/value pairs at the ERROR level
func (l *logrusAdapter) Error(msg string, args ...interface{}) {
func (l *logrusAdapter) Error(msg string, args ...any) {
l.impl.WithFields(argsToFields(args...)).Error(msg)
}
@@ -121,7 +121,7 @@ func (l *logrusAdapter) IsError() bool {
}
// With creates a sublogger that will always have the given key/value pairs
func (l *logrusAdapter) With(args ...interface{}) hclog.Logger {
func (l *logrusAdapter) With(args ...any) hclog.Logger {
return &logrusAdapter{
impl: l.impl.WithFields(argsToFields(args...)),
level: l.level,
@@ -164,7 +164,7 @@ func (l *logrusAdapter) SetLevel(_ hclog.Level) {
}
// ImpliedArgs returns With key/value pairs
func (l *logrusAdapter) ImpliedArgs() []interface{} {
func (l *logrusAdapter) ImpliedArgs() []any {
panic("not implemented")
}
@@ -172,7 +172,7 @@ func (l *logrusAdapter) ImpliedArgs() []interface{} {
// keys must be strings
// vals can be any type, but display is implementation specific
// Emit a message and key/value pairs at a provided log level
func (l *logrusAdapter) Log(level hclog.Level, msg string, args ...interface{}) {
func (l *logrusAdapter) Log(level hclog.Level, msg string, args ...any) {
switch level {
case hclog.Trace:
l.Trace(msg, args...)
@@ -26,34 +26,34 @@ import (
func TestArgsToFields(t *testing.T) {
tests := []struct {
name string
args []interface{}
args []any
expectedFields logrus.Fields
}{
{
name: "empty args results in empty map of fields",
args: []interface{}{},
expectedFields: logrus.Fields(map[string]interface{}{}),
args: []any{},
expectedFields: logrus.Fields(map[string]any{}),
},
{
name: "matching string keys/values are correctly set as fields",
args: []interface{}{"key-1", "value-1", "key-2", "value-2"},
expectedFields: logrus.Fields(map[string]interface{}{
args: []any{"key-1", "value-1", "key-2", "value-2"},
expectedFields: logrus.Fields(map[string]any{
"key-1": "value-1",
"key-2": "value-2",
}),
},
{
name: "time/timestamp/level entries are removed",
args: []interface{}{"time", time.Now(), "key-1", "value-1", "timestamp", time.Now(), "key-2", "value-2", "level", "WARN"},
expectedFields: logrus.Fields(map[string]interface{}{
args: []any{"time", time.Now(), "key-1", "value-1", "timestamp", time.Now(), "key-2", "value-2", "level", "WARN"},
expectedFields: logrus.Fields(map[string]any{
"key-1": "value-1",
"key-2": "value-2",
}),
},
{
name: "odd number of args adds the last arg as a field with a nil value",
args: []interface{}{"key-1", "value-1", "key-2", "value-2", "key-3"},
expectedFields: logrus.Fields(map[string]interface{}{
args: []any{"key-1", "value-1", "key-2", "value-2", "key-3"},
expectedFields: logrus.Fields(map[string]any{
"key-1": "value-1",
"key-2": "value-2",
"key-3": nil,
+2 -2
View File
@@ -40,7 +40,7 @@ func (pf *processFactory) newProcess(command string, logger logrus.FieldLogger,
}
type Process interface {
dispense(key KindAndName) (interface{}, error)
dispense(key KindAndName) (any, error)
exited() bool
kill()
}
@@ -97,7 +97,7 @@ func removeFeaturesFlag(args []string) []string {
return commandArgs
}
func (r *process) dispense(key KindAndName) (interface{}, error) {
func (r *process) dispense(key KindAndName) (any, error) {
// This calls GRPCClient(clientConn) on the plugin instance registered for key.name.
dispensed, err := r.protocolClient.Dispense(key.Kind.String())
if err != nil {
@@ -36,7 +36,7 @@ func (cp *mockClientProtocol) Close() error {
return args.Error(0)
}
func (cp *mockClientProtocol) Dispense(name string) (interface{}, error) {
func (cp *mockClientProtocol) Dispense(name string) (any, error) {
args := cp.Called(name)
return args.Get(0), args.Error(1)
}
@@ -50,7 +50,7 @@ type mockClientDispenser struct {
mock.Mock
}
func (cd *mockClientDispenser) ClientFor(name string) interface{} {
func (cd *mockClientDispenser) ClientFor(name string) any {
args := cd.Called(name)
return args.Get(0)
}
@@ -93,7 +93,7 @@ func TestDispense(t *testing.T) {
clientDispenser := new(mockClientDispenser)
defer clientDispenser.AssertExpectations(t)
var client interface{}
var client any
key := KindAndName{}
if tc.clientDispenser {
@@ -42,7 +42,7 @@ type RestartableProcess interface {
AddReinitializer(key KindAndName, r Reinitializer)
Reset() error
ResetIfNeeded() error
GetByKindAndName(key KindAndName) (interface{}, error)
GetByKindAndName(key KindAndName) (any, error)
Stop()
}
@@ -57,7 +57,7 @@ type restartableProcess struct {
// lock guards all of the fields below
lock sync.RWMutex
process Process
plugins map[KindAndName]interface{}
plugins map[KindAndName]any
reinitializers map[KindAndName]Reinitializer
resetFailures int
}
@@ -65,7 +65,7 @@ type restartableProcess struct {
// reinitializer is capable of reinitializing a restartable plugin instance using the newly dispensed plugin.
type Reinitializer interface {
// reinitialize reinitializes a restartable plugin instance using the newly dispensed plugin.
Reinitialize(dispensed interface{}) error
Reinitialize(dispensed any) error
}
// newRestartableProcess creates a new restartableProcess for the given command and options.
@@ -74,7 +74,7 @@ func newRestartableProcess(command string, logger logrus.FieldLogger, logLevel l
command: command,
logger: logger,
logLevel: logLevel,
plugins: make(map[KindAndName]interface{}),
plugins: make(map[KindAndName]any),
reinitializers: make(map[KindAndName]Reinitializer),
}
@@ -118,7 +118,7 @@ func (p *restartableProcess) resetLH() error {
// Redispense any previously dispensed plugins, reinitializing if necessary.
// Start by creating a new map to hold the newly dispensed plugins.
newPlugins := make(map[KindAndName]interface{})
newPlugins := make(map[KindAndName]any)
for key := range p.plugins {
// Re-dispense
dispensed, err := p.process.dispense(key)
@@ -160,7 +160,7 @@ func (p *restartableProcess) ResetIfNeeded() error {
}
// GetByKindAndName acquires the lock and calls getByKindAndNameLH.
func (p *restartableProcess) GetByKindAndName(key KindAndName) (interface{}, error) {
func (p *restartableProcess) GetByKindAndName(key KindAndName) (any, error) {
p.lock.Lock()
defer p.lock.Unlock()
@@ -169,7 +169,7 @@ func (p *restartableProcess) GetByKindAndName(key KindAndName) (interface{}, err
// getByKindAndNameLH returns the dispensed plugin for key. If the plugin hasn't been dispensed before, it dispenses a
// new one.
func (p *restartableProcess) getByKindAndNameLH(key KindAndName) (interface{}, error) {
func (p *restartableProcess) getByKindAndNameLH(key KindAndName) (any, error) {
dispensed, found := p.plugins[key]
if found {
return dispensed, nil