Skip to content

Commit a8f47ea

Browse files
authored
build(go, deps): switch to Go 1.22 and update modules (hybridgroup#1093)
1 parent fd85df0 commit a8f47ea

File tree

103 files changed

+323
-282
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+323
-282
lines changed

.circleci/config.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ version: 2
1414
jobs:
1515
"test_core_and_drivers_with_coverage":
1616
docker:
17-
- image: cimg/go:1.20
17+
- image: cimg/go:1.22
1818
steps:
1919
- checkout
2020
- run:
@@ -31,7 +31,7 @@ jobs:
3131
3232
"test_platforms":
3333
docker:
34-
- image: cimg/go:1.20
34+
- image: cimg/go:1.22
3535
steps:
3636
- checkout
3737
- run:
@@ -45,7 +45,7 @@ jobs:
4545
4646
"check_examples":
4747
docker:
48-
- image: cimg/go:1.20
48+
- image: cimg/go:1.22
4949
steps:
5050
- checkout
5151
- run:
@@ -61,7 +61,7 @@ jobs:
6161
6262
"fmt_check_examples":
6363
docker:
64-
- image: golangci/golangci-lint:v1.56.1
64+
- image: golangci/golangci-lint:v1.61.0
6565
steps:
6666
- checkout
6767
- run:

.github/pull_request_template.md

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ If this is a new driver or adaptor:
2222
- [ ] I have added an example to see how to setup and use it
2323
- [ ] I have checked or build at least my new example (e.g. by run `make examples_check`)
2424

25+
If this is a Go version update:
26+
27+
- [ ] go.mod to new version updated
28+
- [ ] modules updated (go get -u -t ./...)
29+
- [ ] CI files updated
30+
- [ ] linter setting and linter version (if a newer one exist) updated
31+
- [ ] linter issues fixed or suppressed by config
32+
2533
If this is a PR for release:
2634

2735
- [ ] The PR's target branch is 'hybridgroup:release'

.github/workflows/golangci-lint.yml

+8-14
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,28 @@ jobs:
1515
name: lint
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v3
19-
- uses: actions/setup-go@v4
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-go@v5
2020
with:
21-
go-version: '1.20'
21+
go-version: '1.22'
2222
cache: false
2323
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v3
24+
uses: golangci/golangci-lint-action@v6
2525
with:
2626
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
27-
version: v1.56.1
27+
version: v1.61.0
2828

2929
# Optional: working directory, useful for monorepos
3030
# working-directory: v2
3131

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

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

4040
# Optional: if set to true then the all caching functionality will be complete disabled,
4141
# takes precedence over all other caching options.
4242
# skip-cache: true
43-
44-
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
45-
# skip-pkg-cache: true
46-
47-
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
48-
# skip-build-cache: true

.golangci.yml

+17-22
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,43 @@ run:
2222
# By default, it isn't set.
2323
modules-download-mode: readonly
2424

25+
issues:
2526
# Enables skipping of directories:
2627
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
2728
# Default: true
28-
skip-dirs-use-default: false
29+
exclude-dirs-use-default: false
2930

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

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

4344
enable-all: true
4445

4546
# https://golangci-lint.run/usage/linters/#enabled-by-default
4647
# note: typecheck can not be disabled, it is used to check code compilation
4748
disable:
48-
# deprecated
49-
- deadcode # deprecated
50-
- exhaustivestruct # deprecated
51-
- golint # deprecated
52-
- ifshort # deprecated
53-
- interfacer # deprecated
54-
- maligned # deprecated
55-
- nosnakecase # deprecated
56-
- scopelint # deprecated
57-
- structcheck # deprecated
58-
- varcheck # deprecated
49+
# deprecated:
50+
- exportloopref # Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar
51+
- gomnd # The linter has been renamed. Replaced by mnd.
52+
# not used for this go version: none
5953
# not used for any reason
54+
- err113 # not used (we allow error creation at return statement)
6055
- execinquery # not needed (no sql)
6156
- exhaustive # not used (we allow incomplete usage of enum switch, e.g. with default case)
6257
- forbidigo # not used (we allow print statements)
6358
- ginkgolinter # not needed (enforces standards of using ginkgo and gomega)
6459
- gochecknoglobals # not used (we allow definition of unexposed variables at top level)
6560
- godot # not used (seems to be counting peas)
6661
- godox # not used (we have many TODOs, so not useful)
67-
- goerr113 # not used (we allow error creation at return statement)
6862
- gosmopolitan # not needed (report i18n/l10n anti-patterns)
6963
- importas # not needed (there is no alias rule at the moment)
7064
- ireturn # not used (we allow return interfaces)
@@ -86,9 +80,10 @@ linters:
8680
- goconst # useful (reduce bugs)
8781
- gocyclo # useful with some tweeks (better understandable code)
8882
- goheader # useful, if we introduce a common header (e.g. for copyright)
89-
- gomnd # useful with some exclusions for existing code (e.g. mavlink.go)
9083
- interfacebloat # useful with some exclusions at usage of external packages
84+
- intrange # introduced with go 1.22, will simplify the range syntax
9185
- maintidx # useful with some tweeks (better understandable code), maybe use instead "gocyclo", "gocognit" , "cyclop"
86+
- mnd # useful with some exclusions for existing code (e.g. mavlink.go)
9287
- nestif # useful (reduce bugs, simplify code, better understandable code)
9388
- nlreturn # more common style, but could become annoying
9489
- stylecheck # useful with some tweaking (e.g. underscores in names should be allowed - we use it for constants retrieved from C/C++)

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ including_except := $(shell go list ./... | grep -v platforms/opencv)
1212

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

1717
# Run tests on nearly all directories without test cache
1818
test:
@@ -73,7 +73,7 @@ ifeq ($(CHECK),ON)
7373
go vet ./$@
7474
else ifeq ($(CHECK),FMT)
7575
gofumpt -l -w ./$@
76-
golangci-lint run ./$@ --fix --build-tags example --disable forcetypeassert --disable noctx
76+
golangci-lint run ./$@ --fix --build-tags example,libusb --disable forcetypeassert --disable noctx
7777
else
7878
go build -o /tmp/gobot_examples/$@ ./$@
7979
endif

api/basic_auth.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func BasicAuth(username, password string) http.HandlerFunc {
2222
}
2323

2424
func secureCompare(given string, actual string) bool {
25+
//nolint:gosec // TODO: fix later
2526
if subtle.ConstantTimeEq(int32(len(given)), int32(len(actual))) == 1 {
2627
return subtle.ConstantTimeCompare([]byte(given), []byte(actual)) == 1
2728
}

drivers/aio/temperature_sensor_driver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TemperatureSensorNtcScaler(
8686
if input < 0 {
8787
input = 0
8888
}
89-
rTherm := temperaturSensorGetResistance(uint(input), vRef, rOhm, reverse)
89+
rTherm := temperaturSensorGetResistance(uint(input), vRef, rOhm, reverse) //nolint:gosec // checked before
9090
temp := ntc.getTemp(rTherm)
9191
return temp
9292
})

drivers/ble/microbit/io_pin_driver.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (d *IOPinDriver) ReadPinADConfig() (int, error) {
7272
}
7373
var result byte
7474
for i := 0; i < 4; i++ {
75-
result |= c[i] << uint(i)
75+
result |= c[i] << uint(i) //nolint:gosec // ok here
7676
}
7777

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

100101
var result byte
101102
for i := 0; i < 4; i++ {
102-
result |= c[i] << uint(i)
103+
result |= c[i] << uint(i) //nolint:gosec // ok here
103104
}
104105

105106
d.ioMask = int(result)
@@ -110,6 +111,7 @@ func (d *IOPinDriver) ReadPinIOConfig() (int, error) {
110111
func (d *IOPinDriver) WritePinIOConfig(config int) error {
111112
d.ioMask = config
112113
data := &bytes.Buffer{}
114+
//nolint:gosec // TODO: fix later
113115
if err := binary.Write(data, binary.LittleEndian, uint32(config)); err != nil {
114116
return err
115117
}
@@ -179,6 +181,7 @@ func (d *IOPinDriver) AnalogRead(pin string) (int, error) {
179181
}
180182

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

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

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

205210
func (d *IOPinDriver) ensureOutput(pin int) error {
211+
//nolint:gosec // TODO: fix later
206212
if bit.IsSet(d.ioMask, uint8(pin)) {
207-
return d.WritePinIOConfig(bit.Clear(d.ioMask, uint8(pin)))
213+
return d.WritePinIOConfig(bit.Clear(d.ioMask, uint8(pin))) //nolint:gosec // TODO: fix later
208214
}
209215

210216
return nil

drivers/ble/parrot/minidrone_driver.go

+6
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ func (d *MinidroneDriver) generatePcmd() *bytes.Buffer {
394394
if err := binary.Write(cmd, binary.LittleEndian, int8(2)); err != nil {
395395
panic(err)
396396
}
397+
//nolint:gosec // TODO: fix later
397398
if err := binary.Write(cmd, binary.LittleEndian, int8(d.stepsfa0a)); err != nil {
398399
panic(err)
399400
}
@@ -409,18 +410,23 @@ func (d *MinidroneDriver) generatePcmd() *bytes.Buffer {
409410
if err := binary.Write(cmd, binary.LittleEndian, int8(0)); err != nil {
410411
panic(err)
411412
}
413+
//nolint:gosec // TODO: fix later
412414
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Flag)); err != nil {
413415
panic(err)
414416
}
417+
//nolint:gosec // TODO: fix later
415418
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Roll)); err != nil {
416419
panic(err)
417420
}
421+
//nolint:gosec // TODO: fix later
418422
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Pitch)); err != nil {
419423
panic(err)
420424
}
425+
//nolint:gosec // TODO: fix later
421426
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Yaw)); err != nil {
422427
panic(err)
423428
}
429+
//nolint:gosec // TODO: fix later
424430
if err := binary.Write(cmd, binary.LittleEndian, int8(pcmd.Gaz)); err != nil {
425431
panic(err)
426432
}

drivers/ble/sphero/sphero_ollie_driver.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ func (d *OllieDriver) SetRGB(r uint8, g uint8, b uint8) {
143143

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

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

355356
if ux > 32255 {
356-
x = int16(ux - 65535)
357+
x = int16(ux - 65535) //nolint:gosec // ok here
357358
} else {
358359
x = int16(ux)
359360
}
360361

361362
if uy > 32255 {
362-
y = int16(uy - 65535)
363+
y = int16(uy - 65535) //nolint:gosec // ok here
363364
} else {
364365
y = int16(uy)
365366
}
@@ -424,7 +425,7 @@ func (d *OllieDriver) sendCraftPacket(body []uint8, did byte, cid byte) {
424425

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

430431
packet := &packet{

drivers/common/mfrc522/mfrc522_pcd.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func (d *MFRC522Common) communicateWithPICC(command uint8, sendData []byte, back
172172
}
173173

174174
// TODO: this is not used at the moment (propagation of IRQ pin)
175+
//nolint:gosec // TODO: fix later
175176
if err := d.writeByteData(regComIEn, uint8(irqEn|comIEnRegIRqInv)); err != nil {
176177
return err
177178
}
@@ -337,10 +338,11 @@ func (d *MFRC522Common) readFifo(backData []byte) (uint8, error) {
337338
if err != nil {
338339
return 0, err
339340
}
341+
//nolint:gosec // TODO: fix later
340342
if n > uint8(len(backData)) {
341343
return 0, fmt.Errorf("more data in FIFO (%d) than expected (%d)", n, len(backData))
342344
}
343-
345+
//nolint:gosec // TODO: fix later
344346
if n < uint8(len(backData)) {
345347
return 0, fmt.Errorf("less data in FIFO (%d) than expected (%d)", n, len(backData))
346348
}

drivers/common/mfrc522/mfrc522_pcd_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (c *busConnMock) ReadByteData(reg uint8) (uint8, error) {
2020

2121
switch reg {
2222
case regFIFOLevel:
23-
return uint8(len(c.simFifo)), nil
23+
return uint8(len(c.simFifo)), nil //nolint:gosec // ok for test
2424
case regFIFOData:
2525
c.fifoIdx++
2626
return c.simFifo[c.fifoIdx-1], nil

drivers/common/mfrc522/mfrc522_picc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func (d *MFRC522Common) piccActivate() ([]byte, error) {
336336
bcc = bcc ^ v
337337
}
338338
if bcc != backData[4] {
339-
return nil, fmt.Errorf(fmt.Sprintf("BCC mismatch, expected %02x actual %02x", bcc, backData[4]))
339+
return nil, fmt.Errorf("BCC mismatch, expected %02x actual %02x", bcc, backData[4])
340340
}
341341

342342
if backData[0] == piccCascadeTag {

drivers/common/spherocommon/spherocommon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ func CalculateChecksum(buf []byte) byte {
2929
for i := range buf {
3030
calculatedChecksum += uint16(buf[i])
3131
}
32-
return uint8(^(calculatedChecksum % 256))
32+
return uint8(^(calculatedChecksum % 256)) //nolint:gosec // TODO: fix later
3333
}

0 commit comments

Comments
 (0)