Skip to content

Commit

Permalink
update min Go version to 1.22 and update golangci, fix lints
Browse files Browse the repository at this point in the history
golangci.yml was cleaned up basd on warnings it printed.

Go 1.22 because it fixes the loop reference reuse.
  • Loading branch information
benma committed Nov 18, 2024
1 parent a2115fe commit 7101d30
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
name: ci
on: [push, pull_request]
env:
GO_VERSION: "^1.20"
GOLANGCI_LINT_VERSION: "v1.55.2"
GO_VERSION: "^1.22"
GOLANGCI_LINT_VERSION: "v1.62.0"

jobs:
lint:
Expand Down
35 changes: 2 additions & 33 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ run:

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true

Expand All @@ -31,28 +28,11 @@ output:
linters-settings:
gocritic:
enabled-checks:
- assignOp
- builtinShadow
- captLocal
- caseOrder
- defaultCaseOrder
- dupArg
- dupBranchBody
- dupCase
- elseif
- flagDeref
- ifElseChain
- nilValReturn
- rangeExprCopy
- rangeValCopy
- regexpMust
- sloppyLen
- switchTrue
- typeSwitchVar
- typeUnparen
- underef
- unlambda
- unslice
gocyclo:
min-complexity: 29
maligned:
Expand Down Expand Up @@ -81,9 +61,6 @@ linters-settings:
linters:
enable-all: true
disable:
- golint
- scopelint
- interfacer
- gosec
- bodyclose
- dogsled
Expand All @@ -93,17 +70,14 @@ linters:
- gochecknoinits
- gocognit
- godox
- goerr113 # can't switch to errors.Is due to GopherJS still on go1.12
- gomnd
- lll
- maligned
- nestif
- prealloc
- stylecheck
- whitespace
- wsl
- execinquery
- ireturn
- err113
- wrapcheck
- varnamelen
- tagliatelle
Expand All @@ -112,12 +86,10 @@ linters:
- noctx
- nlreturn
- cyclop
- ifshort
- exhaustive
- nilnil
- nilerr
- forcetypeassert
- exhaustivestruct
- exhaustruct
- maintidx
- errorlint
Expand All @@ -128,19 +100,16 @@ linters:
- makezero
- nolintlint
- gocyclo
- nosnakecase
- interfacebloat
- revive
- musttag
- structcheck
- deadcode
- varcheck
- depguard
- protogetter
- gosmopolitan
- inamedparam
# could not find a way to disable float-compare: https://github.com/golangci/golangci-lint/issues/4187
- testifylint
- mnd
disable-all: false

issues:
Expand Down
4 changes: 1 addition & 3 deletions api/bootloader/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func TestVersions(t *testing.T) {
"x\x00aaaaaaaa", // wrong cmd, good len
"v\x01aaaaaaaa", // wrong op status
} {
testResponse := testResponse
env.communication.query = func([]byte) ([]byte, error) {
return []byte(testResponse), nil
}
Expand All @@ -149,7 +148,6 @@ func TestGetHashes(t *testing.T) {
{true, false, "h\x01\x00"},
{true, true, "h\x01\x01"},
} {
test := test
t.Run("happy", func(t *testing.T) {
h1 := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
h2 := "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
Expand Down Expand Up @@ -279,7 +277,7 @@ func TestUpgradeFirmware(t *testing.T) {
require.Equal(t, []byte("ed"), msg)

// flash chunks
for chunkIndex := 0; chunkIndex < numChunks; chunkIndex++ {
for chunkIndex := range numChunks {
msg, status = takeOne()

require.True(t, status.Upgrading)
Expand Down
2 changes: 1 addition & 1 deletion api/firmware/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func runSimulator(filename string) (func() error, *Device, error) {
}
var conn net.Conn
var err error
for i := 0; i < 200; i++ {
for range 200 {
conn, err = net.Dial("tcp", "localhost:15423")
if err == nil {
break
Expand Down
2 changes: 1 addition & 1 deletion api/firmware/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (device *Device) rawQueryV7(msg []byte) ([]byte, error) {
device.log.Debug("unexpected NACK response in first loop iteration")
} else {
logStr := "unexpected NACK response; last successful retry query intervals (newest first) were: "
for i := 0; i < lastQueryTimes.Len()-1; i++ {
for range lastQueryTimes.Len() - 1 {
if lastQueryTimes.Value == nil || lastQueryTimes.Prev().Value == nil {
break
}
Expand Down
2 changes: 0 additions & 2 deletions communication/usart/usart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func TestReadWrite(t *testing.T) {

func TestWrite(t *testing.T) {
for _, test := range tests {
test := test
t.Run("", func(t *testing.T) {
buf := new(bytes.Buffer)
err := usart.NewCommunication(
Expand All @@ -110,7 +109,6 @@ func TestWrite(t *testing.T) {

func TestRead(t *testing.T) {
for _, test := range tests {
test := test
t.Run("", func(t *testing.T) {
communication := usart.NewCommunication(
&deviceMock{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/BitBoxSwiss/bitbox02-api-go

go 1.21
go 1.22

require (
github.com/benma/miniscript-go v0.0.0-20240226152043-f7c34099edf9
Expand Down
2 changes: 1 addition & 1 deletion util/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (version *SemVer) String() string {
}

// MarshalJSON implements json.Marshaler.
func (version SemVer) MarshalJSON() ([]byte, error) {
func (version *SemVer) MarshalJSON() ([]byte, error) {
return json.Marshal(version.String())
}

Expand Down

0 comments on commit 7101d30

Please sign in to comment.