From a28550c0081ba6f7ebdd532b91616a243bca150d Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Thu, 17 Apr 2025 08:55:54 -0400 Subject: [PATCH] fix(lint): Upgrade to golangci-lint v2, Go 1.24, and fixing lint errors Signed-off-by: Dave Henderson --- .golangci.yml | 77 ++++++++++++++++++++++++------------------ Makefile | 2 +- cmd/onerng/commands.go | 2 -- cmd/onerng/main.go | 2 +- go.mod | 2 +- onerng.go | 1 + verify.go | 3 -- 7 files changed, 49 insertions(+), 40 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ed5b15c..33c2248 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,24 +1,7 @@ -linters-settings: - 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 +version: "2" linters: - disable-all: true + default: none enable: - asciicheck - bodyclose @@ -26,25 +9,15 @@ linters: - dupl - errcheck - exhaustive - - exportloopref - # - funlen - # - gci - # - gochecknoglobals - gochecknoinits - gocognit - goconst - gocritic - gocyclo - # - godox - - gofmt - - gofumpt - goheader - - goimports - # - gomnd - gomodguard - goprintffuncname - gosec - - gosimple - govet - ineffassign - misspell @@ -58,10 +31,50 @@ linters: - rowserrcheck - sqlclosecheck - staticcheck - - stylecheck - - typecheck - unconvert - unparam - unused - 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$ diff --git a/Makefile b/Makefile index e48ee3b..2ffe16d 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ test: endif lint: - @golangci-lint run --max-same-issues=0 --sort-results + @golangci-lint run --max-same-issues=0 .PHONY: clean test build lint .DELETE_ON_ERROR: diff --git a/cmd/onerng/commands.go b/cmd/onerng/commands.go index 1988715..00f49b1 100644 --- a/cmd/onerng/commands.go +++ b/cmd/onerng/commands.go @@ -184,8 +184,6 @@ func readCmd(cmd *cobra.Command, _ []string) error { // humanizeBytes produces a human readable representation of an IEC size. // Taken from github.com/dustin/go-humanize -// -//nolint:gomnd func humanizeBytes(s float64) string { base := 1024.0 sizes := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"} diff --git a/cmd/onerng/main.go b/cmd/onerng/main.go index 0356967..fc628f6 100644 --- a/cmd/onerng/main.go +++ b/cmd/onerng/main.go @@ -21,7 +21,7 @@ func commands() *cobra.Command { This tool can be used to verify that the OneRNG device operates correctly, and that the firmware has not been tampered with.`, Version: version.Version, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { cmd.SilenceErrors = true cmd.SilenceUsage = true diff --git a/go.mod b/go.mod index 8673398..5ad865a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hairyhenderson/go-onerng -go 1.21.5 +go 1.24.0 require ( github.com/spf13/cobra v1.8.0 diff --git a/onerng.go b/onerng.go index cb0b28e..253445f 100644 --- a/onerng.go +++ b/onerng.go @@ -442,6 +442,7 @@ func (o *OneRNG) AESWhitener(ctx context.Context, out io.Writer) (io.WriteCloser return nil, err } + //nolint:staticcheck // not ready to change the algorithm yet stream := cipher.NewCFBEncrypter(block, iv) s := &cipher.StreamWriter{S: stream, W: out} diff --git a/verify.go b/verify.go index 63d0100..7d7a688 100644 --- a/verify.go +++ b/verify.go @@ -43,8 +43,6 @@ func read(r io.Reader, p []byte) error { } // readHeader reads the header and returns the length and the version -// -//nolint:gomnd func readHeader(r io.Reader) (length, version int, err error) { // read the length l := make([]byte, 3) @@ -138,7 +136,6 @@ func verifyImage(signed, sig []byte, pubkey string) (signer *openpgp.Entity, err return signer, nil } -//nolint:gomnd func parseImage(image io.Reader, version, length int) (signed, sig []byte, err error) { c := make([]byte, length) n, err := io.ReadAtLeast(image, c, length)