Skip to content

Commit

Permalink
lint(all): switch to 1.55.2 and adjust linter issues (hybridgroup#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas authored Nov 12, 2023
1 parent 030de93 commit aee8143
Show file tree
Hide file tree
Showing 169 changed files with 1,727 additions and 1,581 deletions.
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@v3
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.54.2
version: v1.55.2

# Optional: working directory, useful for monorepos
# working-directory: v2
Expand Down
11 changes: 7 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# note: GolangCI-Lint also searches for config files in all directories from the directory of the first analyzed path up to the root.
run:
build-tags:
- utils

# Timeout for analysis, e.g. 30s, 5m.
# gobot is very expensive, on a machine with heavy load it takes some minutes
# for first run or after empty the cache by 'golangci-lint cache clean'
Expand Down Expand Up @@ -31,10 +34,10 @@ run:
linters:
# currently active linters:
#
#INFO [lintersdb] Active 42 linters: [asasalint asciicheck bidichk contextcheck decorder depguard dupword durationcheck errcheck exportloopref
# gocheckcompilerdirectives gofmt gofumpt goimports gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper ineffassign makezero mirror
# misspell musttag nilerr nilnil nolintlint nosprintfhostport prealloc reassign revive staticcheck tagalign tenv testableexamples tparallel unconvert unparam
# unused wastedassign]
#INFO [lintersdb] Active 49 linters: [asasalint asciicheck bidichk contextcheck decorder depguard dupword durationcheck errcheck exportloopref
# gocheckcompilerdirectives gochecknoinits gochecksumtype gofmt gofumpt goimports gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper
# inamedparam ineffassign makezero mirror misspell musttag nilerr nilnil nolintlint nosprintfhostport perfsprint prealloc protogetter reassign revive
# sloglint staticcheck tagalign tenv testableexamples testifylint tparallel unconvert unparam unused wastedassign]

enable-all: true

Expand Down
14 changes: 7 additions & 7 deletions adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// DigitalPinOptioner is the interface to provide the possibility to change pin behavior for the next usage
type DigitalPinOptioner interface {
// SetLabel change the pins label
SetLabel(string) (changed bool)
SetLabel(label string) (changed bool)
// SetDirectionOutput sets the pins direction to output with the given initial value
SetDirectionOutput(initialState int) (changed bool)
// SetDirectionInput sets the pins direction to input
Expand Down Expand Up @@ -38,7 +38,7 @@ type DigitalPinOptioner interface {
// DigitalPinOptionApplier is the interface to apply options to change pin behavior immediately
type DigitalPinOptionApplier interface {
// ApplyOptions apply all given options to the pin immediately
ApplyOptions(...func(DigitalPinOptioner) bool) error
ApplyOptions(options ...func(DigitalPinOptioner) bool) error
}

// DigitalPinner is the interface for system gpio interactions
Expand All @@ -50,7 +50,7 @@ type DigitalPinner interface {
// Read reads the current value of the pin
Read() (int, error)
// Write writes to the pin
Write(int) error
Write(val int) error
// DigitalPinOptionApplier is the interface to change pin behavior immediately
DigitalPinOptionApplier
}
Expand Down Expand Up @@ -78,19 +78,19 @@ type PWMPinner interface {
// Enabled returns the enabled state of the PWM pin
Enabled() (bool, error)
// SetEnabled enables/disables the PWM pin
SetEnabled(bool) error
SetEnabled(val bool) error
// Polarity returns true if the polarity of the PWM pin is normal, otherwise false
Polarity() (bool, error)
// SetPolarity sets the polarity of the PWM pin to normal if called with true and to inverted if called with false
SetPolarity(normal bool) error
// Period returns the current PWM period in nanoseconds for pin
Period() (uint32, error)
// SetPeriod sets the current PWM period in nanoseconds for pin
SetPeriod(uint32) error
SetPeriod(period uint32) error
// DutyCycle returns the duty cycle in nanoseconds for the PWM pin
DutyCycle() (uint32, error)
// SetDutyCycle writes the duty cycle in nanoseconds to the PWM pin
SetDutyCycle(uint32) error
SetDutyCycle(dutyCyle uint32) error
}

// PWMPinnerProvider is the interface that an Adaptor should implement to allow
Expand Down Expand Up @@ -210,7 +210,7 @@ type Adaptor interface {
// Name returns the label for the Adaptor
Name() string
// SetName sets the label for the Adaptor
SetName(string)
SetName(name string)
// Connect initiates the Adaptor
Connect() error
// Finalize terminates the Adaptor
Expand Down
12 changes: 6 additions & 6 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func TestIndex(t *testing.T) {

a.ServeHTTP(response, request)

assert.Equal(t, response.Code, http.StatusMovedPermanently)
assert.Equal(t, response.Header()["Location"][0], "/index.html")
assert.Equal(t, http.StatusMovedPermanently, response.Code)
assert.Equal(t, "/index.html", response.Header()["Location"][0])
}

func TestMcp(t *testing.T) {
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestRobots(t *testing.T) {

var body map[string]interface{}
_ = json.NewDecoder(response.Body).Decode(&body)
assert.Equal(t, 3, len(body["robots"].([]interface{})))
assert.Len(t, body["robots"].([]interface{}), 3)
}

func TestRobot(t *testing.T) {
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestRobotDevices(t *testing.T) {

var body map[string]interface{}
_ = json.NewDecoder(response.Body).Decode(&body)
assert.Equal(t, 3, len(body["devices"].([]interface{})))
assert.Len(t, body["devices"].([]interface{}), 3)

// unknown robot
request, _ = http.NewRequest("GET", "/api/robots/UnknownRobot1/devices", nil)
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestRobotDeviceCommands(t *testing.T) {

var body map[string]interface{}
_ = json.NewDecoder(response.Body).Decode(&body)
assert.Equal(t, 2, len(body["commands"].([]interface{})))
assert.Len(t, body["commands"].([]interface{}), 2)

// unknown device
request, _ = http.NewRequest("GET",
Expand Down Expand Up @@ -345,7 +345,7 @@ func TestRobotConnections(t *testing.T) {

var body map[string]interface{}
_ = json.NewDecoder(response.Body).Decode(&body)
assert.Equal(t, 3, len(body["connections"].([]interface{})))
assert.Len(t, body["connections"].([]interface{}), 3)

// unknown robot
request, _ = http.NewRequest("GET", "/api/robots/UnknownRobot1/connections", nil)
Expand Down
2 changes: 1 addition & 1 deletion commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type commander struct {
// which exposes API commands.
type Commander interface {
// Command returns a command given a name. Returns nil if the command is not found.
Command(string) (command func(map[string]interface{}) interface{})
Command(name string) (command func(map[string]interface{}) interface{})
// Commands returns a map of commands.
Commands() (commands map[string]func(map[string]interface{}) interface{})
// AddCommand adds a command given a name.
Expand Down
2 changes: 1 addition & 1 deletion commander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestCommander(t *testing.T) {
})

// act && assert
assert.Equal(t, 1, len(c.Commands()))
assert.Len(t, c.Commands(), 1)
assert.NotNil(t, c.Command("test"))
assert.Nil(t, c.Command("booyeah"))
}
23 changes: 12 additions & 11 deletions drivers/aio/analog_actuator_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAnalogActuatorDriver(t *testing.T) {
Expand All @@ -15,16 +16,16 @@ func TestAnalogActuatorDriver(t *testing.T) {
assert.Equal(t, "47", d.Pin())

err := d.RawWrite(100)
assert.NoError(t, err)
assert.Equal(t, 1, len(a.written))
require.NoError(t, err)
assert.Len(t, a.written, 1)
assert.Equal(t, 100, a.written[0])

err = d.Write(247.0)
assert.NoError(t, err)
assert.Equal(t, 2, len(a.written))
require.NoError(t, err)
assert.Len(t, a.written, 2)
assert.Equal(t, 247, a.written[1])
assert.Equal(t, 247, d.RawValue())
assert.Equal(t, 247.0, d.Value())
assert.InDelta(t, 247.0, d.Value(), 0.0)
}

func TestAnalogActuatorDriverWithScaler(t *testing.T) {
Expand All @@ -35,12 +36,12 @@ func TestAnalogActuatorDriverWithScaler(t *testing.T) {

err := d.Command("RawWrite")(map[string]interface{}{"val": "100"})
assert.Nil(t, err)
assert.Equal(t, 1, len(a.written))
assert.Len(t, a.written, 1)
assert.Equal(t, 100, a.written[0])

err = d.Command("Write")(map[string]interface{}{"val": "247.0"})
assert.Nil(t, err)
assert.Equal(t, 2, len(a.written))
assert.Len(t, a.written, 2)
assert.Equal(t, 100, a.written[1])
}

Expand Down Expand Up @@ -76,21 +77,21 @@ func TestAnalogActuatorDriverLinearScaler(t *testing.T) {
// act
err := d.Write(tt.input)
// assert
assert.NoError(t, err)
assert.Equal(t, 1, len(a.written))
require.NoError(t, err)
assert.Len(t, a.written, 1)
assert.Equal(t, tt.want, a.written[0])
})
}
}

func TestAnalogActuatorDriverStart(t *testing.T) {
d := NewAnalogActuatorDriver(newAioTestAdaptor(), "1")
assert.NoError(t, d.Start())
require.NoError(t, d.Start())
}

func TestAnalogActuatorDriverHalt(t *testing.T) {
d := NewAnalogActuatorDriver(newAioTestAdaptor(), "1")
assert.NoError(t, d.Halt())
require.NoError(t, d.Halt())
}

func TestAnalogActuatorDriverDefaultName(t *testing.T) {
Expand Down
21 changes: 11 additions & 10 deletions drivers/aio/analog_sensor_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gobot.io/x/gobot/v2"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func TestAnalogSensorDriver(t *testing.T) {
assert.Nil(t, ret["err"])

ret = d.Command("Read")(nil).(map[string]interface{})
assert.Equal(t, 247.0, ret["val"].(float64))
assert.InDelta(t, 247.0, ret["val"].(float64), 0.0)
assert.Nil(t, ret["err"])

// refresh value on read
Expand All @@ -47,11 +48,11 @@ func TestAnalogSensorDriver(t *testing.T) {
val = 150
return
}
assert.Equal(t, 0.0, d.Value())
assert.InDelta(t, 0.0, d.Value(), 0.0)
val, err := d.Read()
assert.NoError(t, err)
assert.Equal(t, 150.0, val)
assert.Equal(t, 150.0, d.Value())
require.NoError(t, err)
assert.InDelta(t, 150.0, val, 0.0)
assert.InDelta(t, 150.0, d.Value(), 0.0)
assert.Equal(t, 150, d.RawValue())
}

Expand Down Expand Up @@ -85,8 +86,8 @@ func TestAnalogSensorDriverWithLinearScaler(t *testing.T) {
// act
got, err := d.Read()
// assert
assert.NoError(t, err)
assert.Equal(t, tt.want, got)
require.NoError(t, err)
assert.InDelta(t, tt.want, got, 0.0)
})
}
}
Expand All @@ -104,7 +105,7 @@ func TestAnalogSensorDriverStart(t *testing.T) {
})

_ = d.Once(d.Event(Value), func(data interface{}) {
assert.Equal(t, 10000.0, data.(float64))
assert.InDelta(t, 10000.0, data.(float64), 0.0)
sem <- true
})

Expand All @@ -114,7 +115,7 @@ func TestAnalogSensorDriverStart(t *testing.T) {
return
}

assert.NoError(t, d.Start())
require.NoError(t, d.Start())

select {
case <-sem:
Expand Down Expand Up @@ -170,7 +171,7 @@ func TestAnalogSensorDriverHalt(t *testing.T) {
<-d.halt
close(done)
}()
assert.NoError(t, d.Halt())
require.NoError(t, d.Halt())
select {
case <-done:
case <-time.After(100 * time.Millisecond):
Expand Down
3 changes: 2 additions & 1 deletion drivers/aio/grove_drivers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gobot.io/x/gobot/v2"
)

Expand Down Expand Up @@ -89,7 +90,7 @@ func TestDriverPublishesError(t *testing.T) {
return
}

assert.NoError(t, driver.Start())
require.NoError(t, driver.Start())

// expect error
_ = driver.Once(driver.Event(Error), func(data interface{}) {
Expand Down
9 changes: 5 additions & 4 deletions drivers/aio/grove_temperature_sensor_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gobot.io/x/gobot/v2"
)

Expand Down Expand Up @@ -47,8 +48,8 @@ func TestGroveTemperatureSensorDriverScaling(t *testing.T) {
// act
got, err := d.Read()
// assert
assert.NoError(t, err)
assert.Equal(t, tt.want, got)
require.NoError(t, err)
assert.InDelta(t, tt.want, got, 0.0)
})
}
}
Expand All @@ -66,15 +67,15 @@ func TestGroveTempSensorPublishesTemperatureInCelsius(t *testing.T) {
assert.Equal(t, "31.62", fmt.Sprintf("%.2f", data.(float64)))
sem <- true
})
assert.NoError(t, d.Start())
require.NoError(t, d.Start())

select {
case <-sem:
case <-time.After(1 * time.Second):
t.Errorf("Grove Temperature Sensor Event \"Data\" was not published")
}

assert.Equal(t, 31.61532462352477, d.Temperature())
assert.InDelta(t, 31.61532462352477, d.Temperature(), 0.0)
}

func TestGroveTempDriverDefaultName(t *testing.T) {
Expand Down
Loading

0 comments on commit aee8143

Please sign in to comment.