From bc4545e1735ebf2c240b096f38df5c6250249f44 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 17 Apr 2022 19:31:18 +0200 Subject: [PATCH] chore: fix linter --- charger/tapo/connection.go | 4 ++-- cmd/charger.go | 2 ++ cmd/config.go | 1 + cmd/configure/devicetest.go | 8 ++++---- meter/tq-em.go | 1 - provider/cache.go | 8 ++++---- server/http.go | 1 + util/templates/config.go | 2 +- util/templates/template.go | 4 ++-- 9 files changed, 17 insertions(+), 14 deletions(-) diff --git a/charger/tapo/connection.go b/charger/tapo/connection.go index ccdea6f62..4782b2bc9 100644 --- a/charger/tapo/connection.go +++ b/charger/tapo/connection.go @@ -51,7 +51,7 @@ type Connection struct { func NewConnection(uri, user, password string) *Connection { log := util.NewLogger("tapo") - //lint:ignore + // nosemgrep:go.lang.security.audit.crypto.use_of_weak_crypto.use-of-sha1 h := sha1.New() _, _ = h.Write([]byte(user)) userhash := hex.EncodeToString(h.Sum(nil)) @@ -276,7 +276,7 @@ func (d *Connection) CheckErrorCode(errorCode int) error { } if errorCode != 0 { - return errors.New(fmt.Sprintf("Tapo error %d: %s", errorCode, errorDesc[errorCode])) + return fmt.Errorf("tapo error %d: %s", errorCode, errorDesc[errorCode]) } return nil diff --git a/cmd/charger.go b/cmd/charger.go index 660bcae8b..ef8bfc73b 100644 --- a/cmd/charger.go +++ b/cmd/charger.go @@ -27,7 +27,9 @@ func init() { rootCmd.AddCommand(chargerCmd) chargerCmd.PersistentFlags().StringP(flagName, "n", "", fmt.Sprintf(flagNameDescription, "charger")) chargerCmd.PersistentFlags().IntP(flagCurrent, "I", noCurrent, flagCurrentDescription) + //lint:ignore SA1019 as Title is safe on ascii chargerCmd.PersistentFlags().BoolP(flagEnable, "e", false, strings.Title(flagEnable)) + //lint:ignore SA1019 as Title is safe on ascii chargerCmd.PersistentFlags().BoolP(flagDisable, "d", false, strings.Title(flagDisable)) chargerCmd.PersistentFlags().BoolP(flagWakeup, "w", false, flagWakeupDescription) chargerCmd.PersistentFlags().Bool(flagHeaders, false, flagHeadersDescription) diff --git a/cmd/config.go b/cmd/config.go index 779ae0c4d..a78054265 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -216,6 +216,7 @@ func (cp *ConfigProvider) configureVehicles(conf config) error { } if ccWithTitle.Title == "" { + //lint:ignore SA1019 as Title is safe on ascii cc.Other["title"] = strings.Title(cc.Name) } diff --git a/cmd/configure/devicetest.go b/cmd/configure/devicetest.go index fe5bd5b44..b7cbb74da 100644 --- a/cmd/configure/devicetest.go +++ b/cmd/configure/devicetest.go @@ -84,7 +84,7 @@ func (d *DeviceTest) testCharger(v interface{}) (DeviceTestResult, error) { return DeviceTestResultInvalid, err } } else { - return DeviceTestResultInvalid, errors.New("selected device is not a wallbox!") + return DeviceTestResultInvalid, errors.New("selected device is not a wallbox") } if v, ok := v.(api.Meter); ok { @@ -125,11 +125,11 @@ func (d *DeviceTest) testMeter(deviceCategory DeviceCategory, v interface{}) (De return DeviceTestResultInvalid, err } } else { - return DeviceTestResultInvalid, errors.New("selected device is not a battery meter!") + return DeviceTestResultInvalid, errors.New("selected device is not a battery meter") } } } else { - return DeviceTestResultInvalid, errors.New("selected device is not a meter!") + return DeviceTestResultInvalid, errors.New("selected device is not a meter") } return DeviceTestResultValid, nil @@ -144,7 +144,7 @@ func (d *DeviceTest) testVehicle(v interface{}) (DeviceTestResult, error) { } } } else { - return DeviceTestResultInvalid, errors.New("selected device is not a vehicle!") + return DeviceTestResultInvalid, errors.New("selected device is not a vehicle") } return DeviceTestResultValid, nil diff --git a/meter/tq-em.go b/meter/tq-em.go index 651076236..4068e2ab1 100644 --- a/meter/tq-em.go +++ b/meter/tq-em.go @@ -53,7 +53,6 @@ type tqemData struct { type TqEm struct { dataG func() (tqemData, error) - scale float64 } //go:generate go run ../cmd/tools/decorate.go -f decorateTqEm -b api.Meter -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)" diff --git a/provider/cache.go b/provider/cache.go index 0c0da6c09..1b041a3e8 100644 --- a/provider/cache.go +++ b/provider/cache.go @@ -40,15 +40,15 @@ func Cached[T any](g func() (T, error), cache time.Duration) func() (T, error) { return c.Get } -// Cachable is the interface for a resettable cache -type Cachable[T any] interface { +// Cacheable is the interface for a resettable cache +type Cacheable[T any] interface { Get() (T, error) Reset() } -var _ Cachable[int64] = (*cached[int64])(nil) +var _ Cacheable[int64] = (*cached[int64])(nil) -// ResettableCached wraps a getter with a cache. It returns a `Cachable`. +// ResettableCached wraps a getter with a cache. It returns a `Cacheable`. // Instead of the cached getter, the `Get()` and `Reset()` methods are exposed. func ResettableCached[T any](g func() (T, error), cache time.Duration) *cached[T] { return &cached[T]{ diff --git a/server/http.go b/server/http.go index 3b5ef71ac..166203196 100644 --- a/server/http.go +++ b/server/http.go @@ -21,6 +21,7 @@ type route struct { HandlerFunc http.HandlerFunc } +//lint:ignore U1000 if needed // routeLogger traces matched routes including their executing time func routeLogger(inner http.Handler) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { diff --git a/util/templates/config.go b/util/templates/config.go index f4537c2c9..37fdc440b 100644 --- a/util/templates/config.go +++ b/util/templates/config.go @@ -31,7 +31,7 @@ func (c *ConfigDefaults) LoadDefaults() { } if err := yaml.Unmarshal([]byte(definition.DefaultsContent), &c); err != nil { - panic(fmt.Errorf("Error: failed to parse deviceGroupListDefinition: %v\n", err)) + panic(fmt.Errorf("failed to parse deviceGroupListDefinition: %v", err)) } // resolve modbus param references diff --git a/util/templates/template.go b/util/templates/template.go index afba7d75b..17871df89 100644 --- a/util/templates/template.go +++ b/util/templates/template.go @@ -134,7 +134,7 @@ func (t *Template) ResolvePresets() error { if p.Preset != "" { base, ok := t.ConfigDefaults.Presets[p.Preset] if !ok { - return fmt.Errorf("Error: Could not find preset definition: %s\n", p.Preset) + return fmt.Errorf("could not find preset definition: %s", p.Preset) } t.Params = append(t.Params, base.Params...) @@ -159,7 +159,7 @@ func (t *Template) ResolveGroup() error { _, ok := t.ConfigDefaults.DeviceGroups[t.Group] if !ok { - return fmt.Errorf("Error: Could not find devicegroup definition: %s\n", t.Group) + return fmt.Errorf("could not find devicegroup definition: %s", t.Group) } return nil