Skip to content

Commit

Permalink
build(linter): update linter to v1.56.1 and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas committed Feb 13, 2024
1 parent 1a66f4b commit 7150ce9
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 20 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.55.2
- image: golangci/golangci-lint:v1.56.1
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@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.55.2
version: v1.56.1

# Optional: working directory, useful for monorepos
# working-directory: v2
Expand Down
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ linters-settings:
# Default: false
require-specific: true

perfsprint:
# Optimizes `fmt.Errorf`.
# Default: true
errorf: false
# Optimizes `fmt.Sprintf` with only one argument
# Default: true
sprintf1: false

revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return
Expand Down
9 changes: 5 additions & 4 deletions drivers/aio/temperature_sensor_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,17 @@ func TestTemperatureSensorWithSensorCyclicRead_PublishesError(t *testing.T) {
func TestTemperatureSensorHalt_WithSensorCyclicRead(t *testing.T) {
// arrange
d := NewTemperatureSensorDriver(newAioTestAdaptor(), "1", WithSensorCyclicRead(10*time.Millisecond))
done := make(chan struct{})
require.NoError(t, d.Start())
errChan := make(chan error, 1)
// act & assert
go func() {
require.NoError(t, d.Halt())
close(done)
errChan <- d.Halt()
}()

// test that the halt is not blocked by any deadlock with mutex and/or channel
select {
case <-done:
case err := <-errChan:
require.NoError(t, err)
case <-time.After(100 * time.Millisecond):
require.Fail(t, "Temperature Sensor was not halted")
}
Expand Down
8 changes: 4 additions & 4 deletions drivers/i2c/ads1x15_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestADS1x15CommandsReadDifferenceWithDefaults(t *testing.T) {
result := d.Command("ReadDifferenceWithDefaults")(ads1x15TestChannel)
// assert
assert.Nil(t, result.(map[string]interface{})["err"])
assert.Equal(t, -4.096, result.(map[string]interface{})["val"])
assert.InDelta(t, -4.096, result.(map[string]interface{})["val"], 0.0)
}

func TestADS1x15CommandsReadDifference(t *testing.T) {
Expand All @@ -61,7 +61,7 @@ func TestADS1x15CommandsReadDifference(t *testing.T) {
result := d.Command("ReadDifference")(ads1x15TestChannelGainDataRate)
// assert
assert.Nil(t, result.(map[string]interface{})["err"])
assert.Equal(t, -2.048, result.(map[string]interface{})["val"])
assert.InDelta(t, -2.048, result.(map[string]interface{})["val"], 0.0)
}

func TestADS1x15CommandsReadWithDefaults(t *testing.T) {
Expand All @@ -71,7 +71,7 @@ func TestADS1x15CommandsReadWithDefaults(t *testing.T) {
result := d.Command("ReadWithDefaults")(ads1x15TestChannel)
// assert
assert.Nil(t, result.(map[string]interface{})["err"])
assert.Equal(t, -4.096, result.(map[string]interface{})["val"])
assert.InDelta(t, -4.096, result.(map[string]interface{})["val"], 0.0)
}

func TestADS1x15CommandsRead(t *testing.T) {
Expand All @@ -81,7 +81,7 @@ func TestADS1x15CommandsRead(t *testing.T) {
result := d.Command("Read")(ads1x15TestChannelGainDataRate)
// assert
assert.Nil(t, result.(map[string]interface{})["err"])
assert.Equal(t, -2.048, result.(map[string]interface{})["val"])
assert.InDelta(t, -2.048, result.(map[string]interface{})["val"], 0.0)
}

func TestADS1x15CommandsAnalogRead(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/i2c/wiichuck_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestWiichuckDriverCButton(t *testing.T) {
done := make(chan bool)

_ = d.On(d.Event(C), func(data interface{}) {
assert.Equal(t, true, data) //nolint:testifylint // data is an interface
assert.Equal(t, true, data)
done <- true
})

Expand All @@ -132,7 +132,7 @@ func TestWiichuckDriverZButton(t *testing.T) {
done := make(chan bool)

_ = d.On(d.Event(Z), func(data interface{}) {
assert.Equal(t, true, data) //nolint:testifylint // data is an interface
assert.Equal(t, true, data)
done <- true
})

Expand Down
2 changes: 1 addition & 1 deletion platforms/joystick/bin/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func main() {

case <-ticker.C:
printAt(1, 0, "-- Press 'q' to Exit --")
printAt(1, 1, fmt.Sprintf("Joystick Name: %s", js.Name()))
printAt(1, 1, fmt.Sprintf("Joystick Name: %s", js.Name())) //nolint:perfsprint // ok here
printAt(1, 2, fmt.Sprintf(" Axis Count: %d", js.AxisCount()))
printAt(1, 3, fmt.Sprintf(" Button Count: %d", js.ButtonCount()))
readJoystick(js)
Expand Down
8 changes: 4 additions & 4 deletions platforms/joystick/joystick_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ func (j *Driver) initConfig() error {

func (j *Driver) initEvents() {
for _, value := range j.config.Buttons {
j.AddEvent(fmt.Sprintf("%s_press", value.Name))
j.AddEvent(fmt.Sprintf("%s_release", value.Name))
j.AddEvent(fmt.Sprintf("%s_press", value.Name)) //nolint:perfsprint // ok here
j.AddEvent(fmt.Sprintf("%s_release", value.Name)) //nolint:perfsprint // ok here
}
for _, value := range j.config.Axis {
j.AddEvent(value.Name)
Expand All @@ -214,9 +214,9 @@ func (j *Driver) handleButtons(state js.State) error {
}

if buttonPressed {
j.Publish(j.Event(fmt.Sprintf("%s_press", name)), nil)
j.Publish(j.Event(fmt.Sprintf("%s_press", name)), nil) //nolint:perfsprint // ok here
} else {
j.Publish(j.Event(fmt.Sprintf("%s_release", name)), nil)
j.Publish(j.Event(fmt.Sprintf("%s_release", name)), nil) //nolint:perfsprint // ok here
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions platforms/parrot/bebop/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ func (b *Bebop) Discover() error {
data := make([]byte, 10240)

_, err = b.discoveryClient.Read(data)

if err != nil {
return err
}
Expand All @@ -214,7 +213,6 @@ func (b *Bebop) Connect() error {
}

b.c2dClient, err = net.DialUDP("udp", nil, c2daddr)

if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion robot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func TestRobotStartAutoRun(t *testing.T) {
// work,
)

errChan := make(chan error, 1)
go func() {
require.NoError(t, r.Start())
errChan <- r.Start() // if there is no strange thing happen, this run until os.Signal happen
}()

time.Sleep(10 * time.Millisecond)
Expand All @@ -65,4 +66,10 @@ func TestRobotStartAutoRun(t *testing.T) {
// stop it
require.NoError(t, r.Stop())
assert.False(t, r.Running())
select {
case err := <-errChan:
require.NoError(t, err)
case <-time.After(10 * time.Millisecond):
// because the Start() will run forever, until os.Signal, this is ok here
}
}

0 comments on commit 7150ce9

Please sign in to comment.