Skip to content

Commit

Permalink
update linter settings (viamrobotics#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels authored Dec 26, 2021
1 parent 906ab11 commit c6566d0
Show file tree
Hide file tree
Showing 427 changed files with 4,415 additions and 4,495 deletions.
66 changes: 66 additions & 0 deletions .artifact/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -50003,6 +50003,72 @@
}
}
},
"preprocessing": {
"align-test-1615760748.both.gz": {
"hash": "a4b99c91c6bc68b734499799c05367e7",
"size": 909570
},
"align-test-1615761783.both.gz": {
"hash": "4d68902ed4ee155b4abcc0ff9ae3a800",
"size": 1036966
},
"align-test-1615761793.both.gz": {
"hash": "d4a8814121f88435e12e678f54377797",
"size": 1025703
},
"chess1.both.gz": {
"hash": "68685fe5b1899a5874df4092de0be4e1",
"size": 981318
},
"chess2.both.gz": {
"hash": "6d4e08f5f954f725d8a07f129600c39f",
"size": 978001
},
"chess3.both.gz": {
"hash": "9a5ba64331d22f7b454beb585b6bebf1",
"size": 1036462
},
"gripper-big1.both.gz": {
"hash": "e09120e237eb6010ec4f9c9248abbbc0",
"size": 1237456
}
},
"transform": {
"align-test-1615761793.both.gz": {
"hash": "d4a8814121f88435e12e678f54377797",
"size": 1025703
},
"homography": {
"align-test-1615760748.both.gz": {
"hash": "a4b99c91c6bc68b734499799c05367e7",
"size": 909570
},
"align-test-1615761783.both.gz": {
"hash": "4d68902ed4ee155b4abcc0ff9ae3a800",
"size": 1036966
},
"align-test-1615761793.both.gz": {
"hash": "d4a8814121f88435e12e678f54377797",
"size": 1025703
},
"chess1.both.gz": {
"hash": "68685fe5b1899a5874df4092de0be4e1",
"size": 981318
},
"chess2.both.gz": {
"hash": "6d4e08f5f954f725d8a07f129600c39f",
"size": 978001
},
"chess3.both.gz": {
"hash": "9a5ba64331d22f7b454beb585b6bebf1",
"size": 1036462
},
"gripper-big1.both.gz": {
"hash": "e09120e237eb6010ec4f9c9248abbbc0",
"size": 1237456
}
}
},
"transforms": {
"intrinsics_helper.csv": {
"hash": "43db58ae2f7be23438fa63e875a938d6",
Expand Down
10 changes: 3 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,19 @@ jobs:
run: |
sudo -u testbot bash -lc 'make setup'
- name: Verify no uncommitted changes from "make build goformat"
- name: Verify no uncommitted changes from "make build lint"
run: |
git init
git add .
chown -R testbot .
sudo -u testbot bash -lc 'make build goformat'
sudo -u testbot bash -lc 'make build lint'
GEN_DIFF=$(git diff)
if [ -n "$GEN_DIFF" ]; then
echo '"make build goformat" resulted in changes not in git' 1>&2
echo '"make build lint" resulted in changes not in git' 1>&2
git status
exit 1
fi
- name: Lint
run: |
sudo -u testbot bash -lc 'make lint'
- name: Test
env:
ARTIFACT_GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.ARTIFACT_GOOGLE_APPLICATION_CREDENTIALS }}
Expand Down
13 changes: 2 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ SERVER_DEB_VER = 0.5
binsetup:
mkdir -p ${BIN_OUTPUT_PATH}

goformat:
go install golang.org/x/tools/cmd/goimports
gofmt -s -w .
`go env GOPATH`/bin/goimports -w -local=go.viam.com/rdk `go list -f '{{.Dir}}' ./... | grep -Ev "proto"`

setup:
bash etc/setup.sh

Expand All @@ -43,17 +38,13 @@ buf:
buf generate
buf generate --template ./etc/buf.web.gen.yaml buf.build/googleapis/googleapis
buf generate --template ./etc/buf.web.gen.yaml buf.build/erdaniels/gostream
go install golang.org/x/tools/cmd/goimports
`go env GOPATH`/bin/goimports -w -local=go.viam.com/rdk proto

lint: goformat
lint:
buf lint
go install github.com/edaniels/golinters/cmd/combined
go install github.com/golangci/golangci-lint/cmd/golangci-lint
go install github.com/polyfloyd/go-errorlint
go list -f '{{.Dir}}' ./... | grep -v gen | grep -v proto | xargs go vet -vettool=`go env GOPATH`/bin/combined
go list -f '{{.Dir}}' ./... | grep -v gen | grep -v proto | xargs `go env GOPATH`/bin/go-errorlint -errorf
go list -f '{{.Dir}}' ./... | grep -v gen | grep -v proto | xargs go run github.com/golangci/golangci-lint/cmd/golangci-lint run -v --config=./etc/.golangci.yaml
go list -f '{{.Dir}}' ./... | grep -v gen | grep -v proto | xargs go run github.com/golangci/golangci-lint/cmd/golangci-lint run -v --fix --config=./etc/.golangci.yaml

cover:
./etc/test.sh cover
Expand Down
3 changes: 1 addition & 2 deletions action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ var actionRegistry = map[string]Action{}

// RegisterAction associates a name to an action.
func RegisterAction(name string, action Action) {
_, old := actionRegistry[name]
if old {
if _, old := actionRegistry[name]; old {
panic(errors.Errorf("trying to register 2 actions with the same name (%s)", name))
}
actionRegistry[name] = action
Expand Down
6 changes: 1 addition & 5 deletions action/drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import (
"fmt"
"time"

"github.com/pkg/errors"

"github.com/edaniels/gostream"

"github.com/pkg/errors"
"go.viam.com/utils"
"go.viam.com/utils/artifact"

Expand All @@ -31,7 +29,6 @@ func RandomWalk(ctx context.Context, theRobot robot.Robot) {
defer cancelFunc()
for {
err := randomWalkIncrement(ctx, theRobot)

if err != nil {
theRobot.Logger().Debugf("error doing random walk, trying again: %s", err)
if !utils.SelectContextOrWait(ctx, 2*time.Second) {
Expand All @@ -43,7 +40,6 @@ func RandomWalk(ctx context.Context, theRobot robot.Robot) {
}

func randomWalkIncrement(ctx context.Context, theRobot robot.Robot) error {

base, camera, err := setup(theRobot)
if err != nil {
return err
Expand Down
8 changes: 3 additions & 5 deletions action/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
"fmt"
"image"

"go.viam.com/rdk/rimage"
"go.viam.com/rdk/utils"

"github.com/edaniels/golog"
"github.com/fogleman/gg"

"go.viam.com/rdk/rimage"
"go.viam.com/rdk/utils"
)

func roverWalk(pc *rimage.ImageWithDepth, debug bool, logger golog.Logger) (image.Image, int) {

var dc *gg.Context
if debug {
dc = gg.NewContextForImage(image.NewRGBA(pc.Color.Bounds()))
Expand Down Expand Up @@ -76,7 +75,6 @@ func roverWalk(pc *rimage.ImageWithDepth, debug bool, logger golog.Logger) (imag

return nil
})

if err != nil {
panic(err)
}
Expand Down
16 changes: 7 additions & 9 deletions action/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import (
"strings"
"testing"

"go.viam.com/rdk/rimage"
"go.viam.com/rdk/vision/segmentation"

"github.com/edaniels/golog"
"go.viam.com/test"

"go.viam.com/rdk/rimage"
"go.viam.com/rdk/vision/segmentation"
)

type MyDebug struct {
}
type MyDebug struct{}

func (ddd MyDebug) Process(
t *testing.T,
Expand All @@ -22,6 +21,7 @@ func (ddd MyDebug) Process(
img image.Image,
logger golog.Logger,
) error {
t.Helper()
dm, err := rimage.ParseDepthMap(strings.Replace(fn, ".png", ".dat.gz", 1))
if err != nil {
return err
Expand All @@ -46,11 +46,9 @@ func TestAutoDrive1(t *testing.T) {
d := rimage.NewMultipleImageTestDebugger(t, "minirover2/autodrive", "*.png", false)
err := d.Process(t, MyDebug{})
test.That(t, err, test.ShouldBeNil)

}

type ChargeDebug struct {
}
type ChargeDebug struct{}

func (cd ChargeDebug) Process(
t *testing.T,
Expand All @@ -59,6 +57,7 @@ func (cd ChargeDebug) Process(
img image.Image,
logger golog.Logger,
) error {
t.Helper()
iwd := rimage.ConvertToImageWithDepth(img).Rotate(180)
pCtx.GotDebugImage(iwd, "rotated")

Expand All @@ -79,5 +78,4 @@ func TestCharge1(t *testing.T) {
d := rimage.NewMultipleImageTestDebugger(t, "minirover2/charging2", "*.both.gz", false)
err := d.Process(t, ChargeDebug{})
test.That(t, err, test.ShouldBeNil)

}
2 changes: 1 addition & 1 deletion action/verify_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
testutilsext "go.viam.com/utils/testutils/ext"
)

// TestMain is used to control the execution of all tests run within this package (including _test packages)
// TestMain is used to control the execution of all tests run within this package (including _test packages).
func TestMain(m *testing.M) {
testutilsext.VerifyTestMain(m)
}
3 changes: 1 addition & 2 deletions base/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"testing"

"github.com/pkg/errors"
"go.viam.com/test"

"go.viam.com/rdk/base"
"go.viam.com/rdk/testutils/inject"

"go.viam.com/test"
)

func TestDoMove(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion base/compass.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/edaniels/golog"

goutils "go.viam.com/utils"

"go.viam.com/rdk/sensor/compass"
Expand Down
5 changes: 2 additions & 3 deletions base/compass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"math"
"testing"

"github.com/pkg/errors"

"github.com/edaniels/golog"
"github.com/pkg/errors"
"go.viam.com/test"

"go.viam.com/rdk/base"
Expand All @@ -25,7 +24,7 @@ func TestAugmentReduce(t *testing.T) {
comp := &inject.Compass{}
aug := base.AugmentWithCompass(dev, comp, logger)
test.That(t, aug, test.ShouldNotEqual, dev)
var baseDev *base.Base = nil
var baseDev *base.Base
test.That(t, aug, test.ShouldImplement, baseDev)

test.That(t, base.Reduce(aug), test.ShouldEqual, dev)
Expand Down
2 changes: 1 addition & 1 deletion base/impl/verify_main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
testutilsext "go.viam.com/utils/testutils/ext"
)

// TestMain is used to control the execution of all tests run within this package (including _test packages)
// TestMain is used to control the execution of all tests run within this package (including _test packages).
func TestMain(m *testing.M) {
testutilsext.VerifyTestMain(m)
}
16 changes: 6 additions & 10 deletions base/impl/wheeled_base.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package baseimpl implements some bases, like a wheeled base.
package baseimpl

import (
Expand All @@ -6,18 +7,16 @@ import (
"math"
"time"

"github.com/edaniels/golog"
"github.com/pkg/errors"

"go.uber.org/multierr"
"go.viam.com/utils"

"go.viam.com/rdk/base"
"go.viam.com/rdk/component/motor"
"go.viam.com/rdk/config"
"go.viam.com/rdk/registry"
"go.viam.com/rdk/robot"

"github.com/edaniels/golog"
"go.uber.org/multierr"
)

func init() {
Expand All @@ -36,7 +35,6 @@ type wheeledBase struct {
}

func (base *wheeledBase) Spin(ctx context.Context, angleDeg float64, degsPerSec float64, block bool) error {

// Spin math
rpm, revolutions := base.spinMath(angleDeg, degsPerSec)

Expand Down Expand Up @@ -112,7 +110,7 @@ func (base *wheeledBase) MoveArc(ctx context.Context, distanceMillis int, millis
return base.WaitForMotorsToStop(ctx)
}

// returns rpm, revolutions for spin motion
// returns rpm, revolutions for spin motion.
func (base *wheeledBase) spinMath(angleDeg float64, degsPerSec float64) (float64, float64) {
wheelTravel := base.spinSlipFactor * float64(base.widthMillis) * math.Pi * angleDeg / 360.0
revolutions := wheelTravel / float64(base.wheelCircumferenceMillis)
Expand Down Expand Up @@ -166,7 +164,6 @@ func (base *wheeledBase) arcMath(distanceMillis int, millisPerSec float64, angle
}

func (base *wheeledBase) straightDistanceToMotorInfo(distanceMillis int, millisPerSec float64) (float64, float64) {

rotations := float64(distanceMillis) / float64(base.wheelCircumferenceMillis)

rotationsPerSec := millisPerSec / float64(base.wheelCircumferenceMillis)
Expand Down Expand Up @@ -215,8 +212,8 @@ func (base *wheeledBase) Stop(ctx context.Context) error {
return err
}

func (base *wheeledBase) Close() error {
return base.Stop(context.Background())
func (base *wheeledBase) Close(ctx context.Context) error {
return base.Stop(ctx)
}

func (base *wheeledBase) WidthMillis(ctx context.Context) (int, error) {
Expand Down Expand Up @@ -266,7 +263,6 @@ func CreateFourWheelBase(ctx context.Context, r robot.Robot, config config.Compo

// CreateWheeledBase returns a new wheeled base defined by the given config.
func CreateWheeledBase(ctx context.Context, r robot.Robot, config config.Component, logger golog.Logger) (base.Base, error) {

base := &wheeledBase{
widthMillis: config.Attributes.Int("widthMillis", 0),
wheelCircumferenceMillis: config.Attributes.Int("wheelCircumferenceMillis", 0),
Expand Down
Loading

0 comments on commit c6566d0

Please sign in to comment.