Merge pull request #18 from hairyhenderson/upgrade-to-golangci-lint-v2

fix(lint): Upgrade to golangci-lint v2, Go 1.24, and fixing lint errors
This commit is contained in:
Dave Henderson 2025-04-17 08:57:26 -04:00 committed by GitHub
commit fa8f3eedfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 49 additions and 40 deletions

View File

@ -1,24 +1,7 @@
linters-settings: version: "2"
govet:
check-shadowing: true
enable-all: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 10
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 4
ignore-tests: true
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
linters: linters:
disable-all: true default: none
enable: enable:
- asciicheck - asciicheck
- bodyclose - bodyclose
@ -26,25 +9,15 @@ linters:
- dupl - dupl
- errcheck - errcheck
- exhaustive - exhaustive
- exportloopref
# - funlen
# - gci
# - gochecknoglobals
- gochecknoinits - gochecknoinits
- gocognit - gocognit
- goconst - goconst
- gocritic - gocritic
- gocyclo - gocyclo
# - godox
- gofmt
- gofumpt
- goheader - goheader
- goimports
# - gomnd
- gomodguard - gomodguard
- goprintffuncname - goprintffuncname
- gosec - gosec
- gosimple
- govet - govet
- ineffassign - ineffassign
- misspell - misspell
@ -58,10 +31,50 @@ linters:
- rowserrcheck - rowserrcheck
- sqlclosecheck - sqlclosecheck
- staticcheck - staticcheck
- stylecheck
- typecheck
- unconvert - unconvert
- unparam - unparam
- unused - unused
- whitespace - whitespace
# - wsl
settings:
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 4
gocyclo:
min-complexity: 10
govet:
enable-all: true
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- goconst
path: (.+)_test\.go
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$

View File

@ -48,7 +48,7 @@ test:
endif endif
lint: lint:
@golangci-lint run --max-same-issues=0 --sort-results @golangci-lint run --max-same-issues=0
.PHONY: clean test build lint .PHONY: clean test build lint
.DELETE_ON_ERROR: .DELETE_ON_ERROR:

View File

@ -184,8 +184,6 @@ func readCmd(cmd *cobra.Command, _ []string) error {
// humanizeBytes produces a human readable representation of an IEC size. // humanizeBytes produces a human readable representation of an IEC size.
// Taken from github.com/dustin/go-humanize // Taken from github.com/dustin/go-humanize
//
//nolint:gomnd
func humanizeBytes(s float64) string { func humanizeBytes(s float64) string {
base := 1024.0 base := 1024.0
sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"} sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}

View File

@ -21,7 +21,7 @@ func commands() *cobra.Command {
This tool can be used to verify that the OneRNG device operates This tool can be used to verify that the OneRNG device operates
correctly, and that the firmware has not been tampered with.`, correctly, and that the firmware has not been tampered with.`,
Version: version.Version, Version: version.Version,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
cmd.SilenceErrors = true cmd.SilenceErrors = true
cmd.SilenceUsage = true cmd.SilenceUsage = true

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/hairyhenderson/go-onerng module github.com/hairyhenderson/go-onerng
go 1.21.5 go 1.24.0
require ( require (
github.com/spf13/cobra v1.8.0 github.com/spf13/cobra v1.8.0

View File

@ -442,6 +442,7 @@ func (o *OneRNG) AESWhitener(ctx context.Context, out io.Writer) (io.WriteCloser
return nil, err return nil, err
} }
//nolint:staticcheck // not ready to change the algorithm yet
stream := cipher.NewCFBEncrypter(block, iv) stream := cipher.NewCFBEncrypter(block, iv)
s := &cipher.StreamWriter{S: stream, W: out} s := &cipher.StreamWriter{S: stream, W: out}

View File

@ -43,8 +43,6 @@ func read(r io.Reader, p []byte) error {
} }
// readHeader reads the header and returns the length and the version // readHeader reads the header and returns the length and the version
//
//nolint:gomnd
func readHeader(r io.Reader) (length, version int, err error) { func readHeader(r io.Reader) (length, version int, err error) {
// read the length // read the length
l := make([]byte, 3) l := make([]byte, 3)
@ -138,7 +136,6 @@ func verifyImage(signed, sig []byte, pubkey string) (signer *openpgp.Entity, err
return signer, nil return signer, nil
} }
//nolint:gomnd
func parseImage(image io.Reader, version, length int) (signed, sig []byte, err error) { func parseImage(image io.Reader, version, length int) (signed, sig []byte, err error) {
c := make([]byte, length) c := make([]byte, length)
n, err := io.ReadAtLeast(image, c, length) n, err := io.ReadAtLeast(image, c, length)