chore: fix linter

This commit is contained in:
andig 2022-04-17 19:31:18 +02:00
parent 631706cb37
commit bc4545e173
9 changed files with 17 additions and 14 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)
}

View file

@ -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

View file

@ -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)"

View file

@ -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]{

View file

@ -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) {

View file

@ -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

View file

@ -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