Skip to content

Commit

Permalink
build(go, deps): switch to Go 1.22 and update modules (hybridgroup#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas authored and nexus166 committed Nov 4, 2024
1 parent 0d0db6c commit 368f027
Show file tree
Hide file tree
Showing 103 changed files with 323 additions and 282 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version: 2
jobs:
"test_core_and_drivers_with_coverage":
docker:
- image: cimg/go:1.20
- image: cimg/go:1.22
steps:
- checkout
- run:
Expand All @@ -31,7 +31,7 @@ jobs:
"test_platforms":
docker:
- image: cimg/go:1.20
- image: cimg/go:1.22
steps:
- checkout
- run:
Expand All @@ -45,7 +45,7 @@ jobs:
"check_examples":
docker:
- image: cimg/go:1.20
- image: cimg/go:1.22
steps:
- checkout
- run:
Expand All @@ -61,7 +61,7 @@ jobs:
"fmt_check_examples":
docker:
- image: golangci/golangci-lint:v1.56.1
- image: golangci/golangci-lint:v1.61.0
steps:
- checkout
- run:
Expand Down
8 changes: 8 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ If this is a new driver or adaptor:
- [ ] I have added an example to see how to setup and use it
- [ ] I have checked or build at least my new example (e.g. by run `make examples_check`)

If this is a Go version update:

- [ ] go.mod to new version updated
- [ ] modules updated (go get -u -t ./...)
- [ ] CI files updated
- [ ] linter setting and linter version (if a newer one exist) updated
- [ ] linter issues fixed or suppressed by config

If this is a PR for release:

- [ ] The PR's target branch is 'hybridgroup:release'
Expand Down
22 changes: 8 additions & 14 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,28 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
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.56.1
version: v1.61.0

# Optional: working directory, useful for monorepos
# working-directory: v2

# Optional: golangci-lint command line arguments.
# mostly there is no problem locally, but on server: "could not import C (cgo preprocessing failed) (typecheck)"
# and the digispark adaptor can not be build since switch to linter version 1.54.2
args: --skip-files="platforms/digispark/littleWire.go,platforms/digispark/digispark_adaptor.go"
# Note: exclude arguments, e.g. --exclude-files="my_file", will not affect the "typecheck" linter,
# at least since v1.61.0 - use build tags instead.
#args: --exclude-files="platforms/digispark/digispark_adaptor.go"

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
39 changes: 17 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,43 @@ run:
# By default, it isn't set.
modules-download-mode: readonly

issues:
# Enables skipping of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
# Default: true
skip-dirs-use-default: false
exclude-dirs-use-default: false

# note: examples will be currently omitted by the build tag
skip-dirs:
- platforms/opencv
# note: folders/files can not be excluded from "typecheck" anymore since v1.61.0

linters:
# currently active linters:
#
# INFO [lintersdb] Active 64 linters: [asasalint asciicheck bidichk bodyclose containedctx contextcheck decorder depguard dogsled dupword durationcheck
# errcheck errchkjson errorlint exportloopref forcetypeassert gci gocheckcompilerdirectives gochecknoinits gochecksumtype gocritic gofmt gofumpt goimports
# gomoddirectives gomodguard goprintffuncname gosec gosimple govet grouper inamedparam ineffassign lll makezero mirror misspell musttag nakedret nilerr nilnil
# noctx nolintlint nonamedreturns nosprintfhostport perfsprint prealloc predeclared protogetter reassign revive sloglint staticcheck tagalign tenv
# testableexamples testifylint thelper tparallel unconvert unparam unused usestdlibvars wastedassign]
# 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
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
# deprecated:
- exportloopref # Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar
- gomnd # The linter has been renamed. Replaced by mnd.
# 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)
- gochecknoglobals # not used (we allow definition of unexposed variables at top level)
- godot # not used (seems to be counting peas)
- godox # not used (we have many TODOs, so not useful)
- goerr113 # not used (we allow error creation at return statement)
- gosmopolitan # not needed (report i18n/l10n anti-patterns)
- importas # not needed (there is no alias rule at the moment)
- ireturn # not used (we allow return interfaces)
Expand All @@ -86,9 +80,10 @@ linters:
- goconst # useful (reduce bugs)
- gocyclo # useful with some tweeks (better understandable code)
- goheader # useful, if we introduce a common header (e.g. for copyright)
- gomnd # useful with some exclusions for existing code (e.g. mavlink.go)
- interfacebloat # useful with some exclusions at usage of external packages
- intrange # introduced with go 1.22, will simplify the range syntax
- maintidx # useful with some tweeks (better understandable code), maybe use instead "gocyclo", "gocognit" , "cyclop"
- mnd # useful with some exclusions for existing code (e.g. mavlink.go)
- nestif # useful (reduce bugs, simplify code, better understandable code)
- nlreturn # more common style, but could become annoying
- stylecheck # useful with some tweaking (e.g. underscores in names should be allowed - we use it for constants retrieved from C/C++)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ including_except := $(shell go list ./... | grep -v platforms/opencv)

# Run tests on nearly all directories without test cache, with race detection
test_race:
go test -failfast -count=1 -race $(including_except)
go test -failfast -count=1 -race $(including_except) -tags libusb

# Run tests on nearly all directories without test cache
test:
Expand Down Expand Up @@ -73,7 +73,7 @@ ifeq ($(CHECK),ON)
go vet ./$@
else ifeq ($(CHECK),FMT)
gofumpt -l -w ./$@
golangci-lint run ./$@ --fix --build-tags example --disable forcetypeassert --disable noctx
golangci-lint run ./$@ --fix --build-tags example,libusb --disable forcetypeassert --disable noctx
else
go build -o /tmp/gobot_examples/$@ ./$@
endif
1 change: 1 addition & 0 deletions api/basic_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func BasicAuth(username, password string) http.HandlerFunc {
}

func secureCompare(given string, actual string) bool {
//nolint:gosec // TODO: fix later
if subtle.ConstantTimeEq(int32(len(given)), int32(len(actual))) == 1 {
return subtle.ConstantTimeCompare([]byte(given), []byte(actual)) == 1
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/aio/temperature_sensor_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TemperatureSensorNtcScaler(
if input < 0 {
input = 0
}
rTherm := temperaturSensorGetResistance(uint(input), vRef, rOhm, reverse)
rTherm := temperaturSensorGetResistance(uint(input), vRef, rOhm, reverse) //nolint:gosec // checked before
temp := ntc.getTemp(rTherm)
return temp
})
Expand Down
12 changes: 9 additions & 3 deletions drivers/ble/microbit/io_pin_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (d *IOPinDriver) ReadPinADConfig() (int, error) {
}
var result byte
for i := 0; i < 4; i++ {
result |= c[i] << uint(i)
result |= c[i] << uint(i) //nolint:gosec // ok here
}

d.adMask = int(result)
Expand All @@ -83,6 +83,7 @@ func (d *IOPinDriver) ReadPinADConfig() (int, error) {
func (d *IOPinDriver) WritePinADConfig(config int) error {
d.adMask = config
data := &bytes.Buffer{}
//nolint:gosec // TODO: fix later
if err := binary.Write(data, binary.LittleEndian, uint32(config)); err != nil {
return err
}
Expand All @@ -99,7 +100,7 @@ func (d *IOPinDriver) ReadPinIOConfig() (int, error) {

var result byte
for i := 0; i < 4; i++ {
result |= c[i] << uint(i)
result |= c[i] << uint(i) //nolint:gosec // ok here
}

d.ioMask = int(result)
Expand All @@ -110,6 +111,7 @@ func (d *IOPinDriver) ReadPinIOConfig() (int, error) {
func (d *IOPinDriver) WritePinIOConfig(config int) error {
d.ioMask = config
data := &bytes.Buffer{}
//nolint:gosec // TODO: fix later
if err := binary.Write(data, binary.LittleEndian, uint32(config)); err != nil {
return err
}
Expand Down Expand Up @@ -179,6 +181,7 @@ func (d *IOPinDriver) AnalogRead(pin string) (int, error) {
}

func (d *IOPinDriver) ensureDigital(pin int) error {
//nolint:gosec // TODO: fix later
if bit.IsSet(d.adMask, uint8(pin)) {
return d.WritePinADConfig(bit.Clear(d.adMask, uint8(pin)))
}
Expand All @@ -187,6 +190,7 @@ func (d *IOPinDriver) ensureDigital(pin int) error {
}

func (d *IOPinDriver) ensureAnalog(pin int) error {
//nolint:gosec // TODO: fix later
if !bit.IsSet(d.adMask, uint8(pin)) {
return d.WritePinADConfig(bit.Set(d.adMask, uint8(pin)))
}
Expand All @@ -195,6 +199,7 @@ func (d *IOPinDriver) ensureAnalog(pin int) error {
}

func (d *IOPinDriver) ensureInput(pin int) error {
//nolint:gosec // TODO: fix later
if !bit.IsSet(d.ioMask, uint8(pin)) {
return d.WritePinIOConfig(bit.Set(d.ioMask, uint8(pin)))
}
Expand All @@ -203,8 +208,9 @@ func (d *IOPinDriver) ensureInput(pin int) error {
}

func (d *IOPinDriver) ensureOutput(pin int) error {
//nolint:gosec // TODO: fix later
if bit.IsSet(d.ioMask, uint8(pin)) {
return d.WritePinIOConfig(bit.Clear(d.ioMask, uint8(pin)))
return d.WritePinIOConfig(bit.Clear(d.ioMask, uint8(pin))) //nolint:gosec // TODO: fix later
}

return nil
Expand Down
6 changes: 6 additions & 0 deletions drivers/ble/parrot/minidrone_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ func (d *MinidroneDriver) generatePcmd() *bytes.Buffer {
if err := binary.Write(cmd, binary.LittleEndian, int8(2)); err != nil {
panic(err)
}
//nolint:gosec // TODO: fix later
if err := binary.Write(cmd, binary.LittleEndian, int8(d.stepsfa0a)); err != nil {
panic(err)
}
Expand All @@ -409,18 +410,23 @@ func (d *MinidroneDriver) generatePcmd() *bytes.Buffer {
if err := binary.Write(cmd, binary.LittleEndian, int8(0)); err != nil {
panic(err)
}
//nolint:gosec // TODO: fix later
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Flag)); err != nil {
panic(err)
}
//nolint:gosec // TODO: fix later
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Roll)); err != nil {
panic(err)
}
//nolint:gosec // TODO: fix later
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Pitch)); err != nil {
panic(err)
}
//nolint:gosec // TODO: fix later
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Yaw)); err != nil {
panic(err)
}
//nolint:gosec // TODO: fix later
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Gaz)); err != nil {
panic(err)
}
Expand Down
7 changes: 4 additions & 3 deletions drivers/ble/sphero/sphero_ollie_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (d *OllieDriver) SetRGB(r uint8, g uint8, b uint8) {

// Roll tells the Ollie to roll
func (d *OllieDriver) Roll(speed uint8, heading uint16) {
//nolint:gosec // TODO: fix later
d.sendCraftPacket([]uint8{speed, uint8(heading >> 8), uint8(heading & 0xFF), 0x01}, 0x02, 0x30)
}

Expand Down Expand Up @@ -353,13 +354,13 @@ func (d *OllieDriver) handleLocatorDetected(data []uint8) {
var x, y int16

if ux > 32255 {
x = int16(ux - 65535)
x = int16(ux - 65535) //nolint:gosec // ok here
} else {
x = int16(ux)
}

if uy > 32255 {
y = int16(uy - 65535)
y = int16(uy - 65535) //nolint:gosec // ok here
} else {
y = int16(uy)
}
Expand Down Expand Up @@ -424,7 +425,7 @@ func (d *OllieDriver) sendCraftPacket(body []uint8, did byte, cid byte) {

func (d *OllieDriver) craftPacket(body []uint8, did byte, cid byte) *packet {
dlen := len(body) + 1
hdr := []uint8{0xFF, 0xFF, did, cid, d.seq, uint8(dlen)}
hdr := []uint8{0xFF, 0xFF, did, cid, d.seq, uint8(dlen)} //nolint:gosec // TODO: fix later
buf := append(hdr, body...)

packet := &packet{
Expand Down
4 changes: 3 additions & 1 deletion drivers/common/mfrc522/mfrc522_pcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func (d *MFRC522Common) communicateWithPICC(command uint8, sendData []byte, back
}

// TODO: this is not used at the moment (propagation of IRQ pin)
//nolint:gosec // TODO: fix later
if err := d.writeByteData(regComIEn, uint8(irqEn|comIEnRegIRqInv)); err != nil {
return err
}
Expand Down Expand Up @@ -337,10 +338,11 @@ func (d *MFRC522Common) readFifo(backData []byte) (uint8, error) {
if err != nil {
return 0, err
}
//nolint:gosec // TODO: fix later
if n > uint8(len(backData)) {
return 0, fmt.Errorf("more data in FIFO (%d) than expected (%d)", n, len(backData))
}

//nolint:gosec // TODO: fix later
if n < uint8(len(backData)) {
return 0, fmt.Errorf("less data in FIFO (%d) than expected (%d)", n, len(backData))
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/common/mfrc522/mfrc522_pcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (c *busConnMock) ReadByteData(reg uint8) (uint8, error) {

switch reg {
case regFIFOLevel:
return uint8(len(c.simFifo)), nil
return uint8(len(c.simFifo)), nil //nolint:gosec // ok for test
case regFIFOData:
c.fifoIdx++
return c.simFifo[c.fifoIdx-1], nil
Expand Down
2 changes: 1 addition & 1 deletion drivers/common/mfrc522/mfrc522_picc.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (d *MFRC522Common) piccActivate() ([]byte, error) {
bcc = bcc ^ v
}
if bcc != backData[4] {
return nil, fmt.Errorf(fmt.Sprintf("BCC mismatch, expected %02x actual %02x", bcc, backData[4]))
return nil, fmt.Errorf("BCC mismatch, expected %02x actual %02x", bcc, backData[4])
}

if backData[0] == piccCascadeTag {
Expand Down
2 changes: 1 addition & 1 deletion drivers/common/spherocommon/spherocommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func CalculateChecksum(buf []byte) byte {
for i := range buf {
calculatedChecksum += uint16(buf[i])
}
return uint8(^(calculatedChecksum % 256))
return uint8(^(calculatedChecksum % 256)) //nolint:gosec // TODO: fix later
}
Loading

0 comments on commit 368f027

Please sign in to comment.