Skip to content

Commit

Permalink
build(linter): update linter to v1.64.5 and fix issues (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas authored Feb 15, 2025
1 parent 514330e commit 95e7710
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
"fmt_check_examples":
docker:
- image: golangci/golangci-lint:v1.61.0
- image: golangci/golangci-lint:v1.64.5
steps:
- checkout
- run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.61.0
version: v1.64.5

# Optional: working directory, useful for monorepos
# working-directory: v2
Expand Down
14 changes: 1 addition & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,16 @@ issues:
# note: folders/files can not be excluded from "typecheck" anymore since v1.61.0

linters:
# currently active linters:
#
# INFO [lintersdb] Active 67 linters: [asasalint asciicheck bidichk bodyclose canonicalheader containedctx
# contextcheck decorder depguard dogsled dupword durationcheck errcheck errchkjson errorlint fatcontext
# forcetypeassert gci gocheckcompilerdirectives gochecknoinits gochecksumtype gocritic gofmt gofumpt goimports
# gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper inamedparam ineffassign lll makezero
# mirror misspell mnd musttag nakedret nilerr nilnil noctx nolintlint nonamedreturns nosprintfhostport perfsprint
# prealloc predeclared protogetter reassign revive sloglint spancheck staticcheck tagalign tenv testableexamples
# testifylint thelper tparallel unconvert unparam unused usestdlibvars wastedassign]

enable-all: true

# https://golangci-lint.run/usage/linters/#enabled-by-default
# note: typecheck can not be disabled, it is used to check code compilation
disable:
# deprecated:
- exportloopref # Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar
- gomnd # The linter has been renamed. Replaced by mnd.
- tenv # replaced by usetesting
# not used for this go version: none
# not used for any reason
- err113 # not used (we allow error creation at return statement)
- execinquery # not needed (no sql)
- exhaustive # not used (we allow incomplete usage of enum switch, e.g. with default case)
- forbidigo # not used (we allow print statements)
- ginkgolinter # not needed (enforces standards of using ginkgo and gomega)
Expand Down
4 changes: 4 additions & 0 deletions adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ type SpiSystemDevicer interface {
}

// OneWireSystemDevicer is the interface to a 1-wire device at system level.
//
//nolint:iface // ok for now
type OneWireSystemDevicer interface {
// ID returns the device id in the form "family code"-"serial number".
ID() string
Expand Down Expand Up @@ -230,6 +232,8 @@ type SpiOperations interface {
}

// OneWireOperations are the wrappers around the actual functions used by the 1-wire device interface
//
//nolint:iface // ok for now
type OneWireOperations interface {
// ID returns the device id in the form "family code"-"serial number".
ID() string
Expand Down
3 changes: 2 additions & 1 deletion drivers/aio/analog_actuator_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ func NewAnalogActuatorDriver(a AnalogWriter, pin string, opts ...interface{}) *A
}
}

//nolint:forcetypeassert // ok here
d.AddCommand("Write", func(params map[string]interface{}) interface{} {
val, err := strconv.ParseFloat(params["val"].(string), 64)
if err != nil {
return err
}
return d.Write(val)
})

//nolint:forcetypeassert // ok here
d.AddCommand("WriteRaw", func(params map[string]interface{}) interface{} {
val, _ := strconv.Atoi(params["val"].(string))
return d.WriteRaw(val)
Expand Down
4 changes: 2 additions & 2 deletions drivers/aio/analog_sensor_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func NewAnalogSensorDriver(a AnalogReader, pin string, opts ...interface{}) *Ana
}
}

d.AddCommand("Read", func(params map[string]interface{}) interface{} {
d.AddCommand("Read", func(_ map[string]interface{}) interface{} {
val, err := d.Read()
return map[string]interface{}{"val": val, "err": err}
})

d.AddCommand("ReadRaw", func(params map[string]interface{}) interface{} {
d.AddCommand("ReadRaw", func(_ map[string]interface{}) interface{} {
val, err := d.ReadRaw()
return map[string]interface{}{"val": val, "err": err}
})
Expand Down
5 changes: 4 additions & 1 deletion drivers/gpio/direct_pin_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ func NewDirectPinDriver(a gobot.Connection, pin string, opts ...interface{}) *Di
driver: newDriver(a, "DirectPin", append(opts, withPin(pin))...),
}

d.AddCommand("DigitalRead", func(params map[string]interface{}) interface{} {
d.AddCommand("DigitalRead", func(_ map[string]interface{}) interface{} {
val, err := d.DigitalRead()
return map[string]interface{}{"val": val, "err": err}
})
//nolint:forcetypeassert // ok here
d.AddCommand("DigitalWrite", func(params map[string]interface{}) interface{} {
level, _ := strconv.Atoi(params["level"].(string))
return d.DigitalWrite(byte(level))
})
//nolint:forcetypeassert // ok here
d.AddCommand("PwmWrite", func(params map[string]interface{}) interface{} {
level, _ := strconv.Atoi(params["level"].(string))
return d.PwmWrite(byte(level))
})
//nolint:forcetypeassert // ok here
d.AddCommand("ServoWrite", func(params map[string]interface{}) interface{} {
level, _ := strconv.Atoi(params["level"].(string))
return d.ServoWrite(byte(level))
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpio/hcsr04_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewHCSR04Driver(a gobot.Adaptor, triggerPinID, echoPinID string, opts ...in
}

d.afterStart = func() error {
tpin, err := a.(gobot.DigitalPinnerProvider).DigitalPin(triggerPinID)
tpin, err := a.(gobot.DigitalPinnerProvider).DigitalPin(triggerPinID) //nolint:forcetypeassert // ok here
if err != nil {
return fmt.Errorf("error on get trigger pin: %v", err)
}
Expand All @@ -93,7 +93,7 @@ func NewHCSR04Driver(a gobot.Adaptor, triggerPinID, echoPinID string, opts ...in
d.triggerPin = tpin

// pins are inputs by default
epin, err := a.(gobot.DigitalPinnerProvider).DigitalPin(echoPinID)
epin, err := a.(gobot.DigitalPinnerProvider).DigitalPin(echoPinID) //nolint:forcetypeassert // ok here
if err != nil {
return fmt.Errorf("error on get echo pin: %v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions drivers/gpio/led_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ func NewLedDriver(a DigitalWriter, pin string, opts ...interface{}) *LedDriver {
d := &LedDriver{
driver: newDriver(a.(gobot.Connection), "LED", append(opts, withPin(pin))...),
}

//nolint:forcetypeassert // ok here
d.AddCommand("Brightness", func(params map[string]interface{}) interface{} {
level := byte(params["level"].(float64)) //nolint:forcetypeassert // ok here
level := byte(params["level"].(float64))
return d.Brightness(level)
})

d.AddCommand("Toggle", func(params map[string]interface{}) interface{} {
d.AddCommand("Toggle", func(_ map[string]interface{}) interface{} {
return d.Toggle()
})

d.AddCommand("On", func(params map[string]interface{}) interface{} {
d.AddCommand("On", func(_ map[string]interface{}) interface{} {
return d.On()
})

d.AddCommand("Off", func(params map[string]interface{}) interface{} {
d.AddCommand("Off", func(_ map[string]interface{}) interface{} {
return d.Off()
})

Expand Down
6 changes: 3 additions & 3 deletions drivers/gpio/relay_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func NewRelayDriver(a DigitalWriter, pin string, opts ...interface{}) *RelayDriv
}
}

d.AddCommand("Toggle", func(params map[string]interface{}) interface{} {
d.AddCommand("Toggle", func(_ map[string]interface{}) interface{} {
return d.Toggle()
})

d.AddCommand("On", func(params map[string]interface{}) interface{} {
d.AddCommand("On", func(_ map[string]interface{}) interface{} {
return d.On()
})

d.AddCommand("Off", func(params map[string]interface{}) interface{} {
d.AddCommand("Off", func(_ map[string]interface{}) interface{} {
return d.Off()
})

Expand Down
6 changes: 3 additions & 3 deletions drivers/gpio/rgb_led_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ func NewRgbLedDriver(a PwmWriter, redPin string, greenPin string, bluePin string
return d.SetRGB(r, g, b)
})

d.AddCommand("Toggle", func(params map[string]interface{}) interface{} {
d.AddCommand("Toggle", func(_ map[string]interface{}) interface{} {
return d.Toggle()
})

d.AddCommand("On", func(params map[string]interface{}) interface{} {
d.AddCommand("On", func(_ map[string]interface{}) interface{} {
return d.On()
})

d.AddCommand("Off", func(params map[string]interface{}) interface{} {
d.AddCommand("Off", func(_ map[string]interface{}) interface{} {
return d.Off()
})

Expand Down
9 changes: 5 additions & 4 deletions drivers/gpio/servo_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ func NewServoDriver(a ServoWriter, pin string, opts ...interface{}) *ServoDriver
driver: newDriver(a.(gobot.Connection), "Servo", append(opts, withPin(pin))...),
}

//nolint:forcetypeassert // ok here
d.AddCommand("Move", func(params map[string]interface{}) interface{} {
angle := byte(params["angle"].(float64)) //nolint:forcetypeassert // ok here
angle := byte(params["angle"].(float64))
return d.Move(angle)
})
d.AddCommand("ToMin", func(params map[string]interface{}) interface{} {
d.AddCommand("ToMin", func(_ map[string]interface{}) interface{} {
return d.ToMin()
})
d.AddCommand("ToCenter", func(params map[string]interface{}) interface{} {
d.AddCommand("ToCenter", func(_ map[string]interface{}) interface{} {
return d.ToCenter()
})
d.AddCommand("ToMax", func(params map[string]interface{}) interface{} {
d.AddCommand("ToMax", func(_ map[string]interface{}) interface{} {
return d.ToMax()
})

Expand Down
12 changes: 7 additions & 5 deletions drivers/gpio/stepper_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,29 @@ func NewStepperDriver(
d.sleepFunc = d.sleepOuputs
d.beforeHalt = d.shutdown

//nolint:forcetypeassert // ok here
d.AddCommand("MoveDeg", func(params map[string]interface{}) interface{} {
degs, _ := strconv.Atoi(params["degs"].(string))
return d.MoveDeg(degs)
})
//nolint:forcetypeassert // ok here
d.AddCommand("Move", func(params map[string]interface{}) interface{} {
steps, _ := strconv.Atoi(params["steps"].(string))
return d.Move(steps)
})
d.AddCommand("Step", func(params map[string]interface{}) interface{} {
d.AddCommand("Step", func(_ map[string]interface{}) interface{} {
return d.Move(1)
})
d.AddCommand("Run", func(params map[string]interface{}) interface{} {
d.AddCommand("Run", func(_ map[string]interface{}) interface{} {
return d.Run()
})
d.AddCommand("Sleep", func(params map[string]interface{}) interface{} {
d.AddCommand("Sleep", func(_ map[string]interface{}) interface{} {
return d.Sleep()
})
d.AddCommand("Stop", func(params map[string]interface{}) interface{} {
d.AddCommand("Stop", func(_ map[string]interface{}) interface{} {
return d.Stop()
})
d.AddCommand("Halt", func(params map[string]interface{}) interface{} {
d.AddCommand("Halt", func(_ map[string]interface{}) interface{} {
return d.Halt()
})

Expand Down
9 changes: 6 additions & 3 deletions drivers/i2c/ads1x15_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ func newADS1x15Driver(c Connector, name string, drs map[int]uint16, ddr int, opt
option(d)
}

//nolint:forcetypeassert // ok here
d.AddCommand("ReadDifferenceWithDefaults", func(params map[string]interface{}) interface{} {
channel := params["channel"].(int) //nolint:forcetypeassert // ok here
channel := params["channel"].(int)
val, err := d.ReadDifferenceWithDefaults(channel)
return map[string]interface{}{"val": val, "err": err}
})
Expand All @@ -127,8 +128,9 @@ func newADS1x15Driver(c Connector, name string, drs map[int]uint16, ddr int, opt
return map[string]interface{}{"val": val, "err": err}
})

//nolint:forcetypeassert // ok here
d.AddCommand("ReadWithDefaults", func(params map[string]interface{}) interface{} {
channel := params["channel"].(int) //nolint:forcetypeassert // ok here
channel := params["channel"].(int)
val, err := d.ReadWithDefaults(channel)
return map[string]interface{}{"val": val, "err": err}
})
Expand All @@ -142,8 +144,9 @@ func newADS1x15Driver(c Connector, name string, drs map[int]uint16, ddr int, opt
return map[string]interface{}{"val": val, "err": err}
})

//nolint:forcetypeassert // ok here
d.AddCommand("AnalogRead", func(params map[string]interface{}) interface{} {
pin := params["pin"].(string) //nolint:forcetypeassert // ok here
pin := params["pin"].(string)
val, err := d.AnalogRead(pin)
return map[string]interface{}{"val": val, "err": err}
})
Expand Down
4 changes: 2 additions & 2 deletions drivers/i2c/blinkm_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func NewBlinkMDriver(c Connector, options ...func(Config)) *BlinkMDriver {
return b.Fade(red, green, blue)
})

b.AddCommand("FirmwareVersion", func(params map[string]interface{}) interface{} {
b.AddCommand("FirmwareVersion", func(_ map[string]interface{}) interface{} {
version, err := b.FirmwareVersion()
return map[string]interface{}{"version": version, "err": err}
})

b.AddCommand("Color", func(params map[string]interface{}) interface{} {
b.AddCommand("Color", func(_ map[string]interface{}) interface{} {
color, err := b.Color()
return map[string]interface{}{"color": color, "err": err}
})
Expand Down
10 changes: 7 additions & 3 deletions drivers/i2c/jhd1313m1_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,30 @@ func NewJHD1313M1Driver(a Connector, options ...func(Config)) *JHD1313M1Driver {
option(d)
}

//nolint:forcetypeassert // ok here
d.AddCommand("SetRGB", func(params map[string]interface{}) interface{} {
r, _ := strconv.Atoi(params["r"].(string))
g, _ := strconv.Atoi(params["g"].(string))
b, _ := strconv.Atoi(params["b"].(string))
return d.SetRGB(r, g, b)
})
d.AddCommand("Clear", func(params map[string]interface{}) interface{} {
d.AddCommand("Clear", func(_ map[string]interface{}) interface{} {
return d.Clear()
})
d.AddCommand("Home", func(params map[string]interface{}) interface{} {
d.AddCommand("Home", func(_ map[string]interface{}) interface{} {
return d.Home()
})
//nolint:forcetypeassert // ok here
d.AddCommand("Write", func(params map[string]interface{}) interface{} {
msg := params["msg"].(string) //nolint:forcetypeassert // ok here
msg := params["msg"].(string)
return d.Write(msg)
})
//nolint:forcetypeassert // ok here
d.AddCommand("SetPosition", func(params map[string]interface{}) interface{} {
pos, _ := strconv.Atoi(params["pos"].(string))
return d.SetPosition(pos)
})
//nolint:forcetypeassert // ok here
d.AddCommand("Scroll", func(params map[string]interface{}) interface{} {
lr, _ := strconv.ParseBool(params["lr"].(string))
return d.Scroll(lr)
Expand Down
2 changes: 2 additions & 0 deletions drivers/i2c/pca9685_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ func NewPCA9685Driver(c Connector, options ...func(Config)) *PCA9685Driver {
val, _ := strconv.Atoi(params["val"].(string))
return p.ServoWrite(pin, byte(val))
})
//nolint:forcetypeassert // ok here
p.AddCommand("SetPWM", func(params map[string]interface{}) interface{} {
channel, _ := strconv.Atoi(params["channel"].(string))
on, _ := strconv.Atoi(params["on"].(string))
off, _ := strconv.Atoi(params["off"].(string))
return p.SetPWM(channel, uint16(on), uint16(off)) //nolint:gosec // TODO: fix later
})
//nolint:forcetypeassert // ok here
p.AddCommand("SetPWMFreq", func(params map[string]interface{}) interface{} {
freq, _ := strconv.ParseFloat(params["freq"].(string), 32)
return p.SetPWMFreq(float32(freq))
Expand Down
4 changes: 2 additions & 2 deletions drivers/i2c/pcf8583_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewPCF8583Driver(c Connector, options ...func(Config)) *PCF8583Driver {
err := d.WriteTime(val)
return map[string]interface{}{"err": err}
})
d.AddCommand("ReadTime", func(params map[string]interface{}) interface{} {
d.AddCommand("ReadTime", func(_ map[string]interface{}) interface{} {
val, err := d.ReadTime()
return map[string]interface{}{"val": val, "err": err}
})
Expand All @@ -97,7 +97,7 @@ func NewPCF8583Driver(c Connector, options ...func(Config)) *PCF8583Driver {
err := d.WriteCounter(val)
return map[string]interface{}{"err": err}
})
d.AddCommand("ReadCounter", func(params map[string]interface{}) interface{} {
d.AddCommand("ReadCounter", func(_ map[string]interface{}) interface{} {
val, err := d.ReadCounter()
return map[string]interface{}{"val": val, "err": err}
})
Expand Down
Loading

0 comments on commit 95e7710

Please sign in to comment.