From c37820751cbc68e0e8c13cc0b925f6f8b0b2ba70 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 17 Sep 2024 14:33:03 +1000 Subject: [PATCH 1/5] Update code to reflect new lint and go version --- .golangci.yml | 26 ++++++++++++++++++++------ Makefile | 2 +- cmd/in-addr/main.go | 24 ++++++++++++++---------- go.mod | 2 +- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d75f9a3..a315ca7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -30,10 +30,17 @@ linters-settings: local-prefixes: github.com/golangci/golangci-lint golint: min-confidence: 0 - gomnd: - checks: argument,case,condition,return govet: disable-all: true + # Enable analyzers by name. + # (in addition to default: + # appends, asmdecl, assign, atomic, bools, buildtag, cgocall, composites, copylocks, defers, directive, errorsas, + # framepointer, httpresponse, ifaceassert, loopclosure, lostcancel, nilfunc, printf, shift, sigchanyzer, slog, + # stdmethods, stringintconv, structtag, testinggoroutine, tests, timeformat, unmarshal, unreachable, unsafeptr, + # unusedresult + # ). + # Run `GL_DEBUG=govet golangci-lint run --enable=govet` to see default, all available analyzers, and enabled analyzers. + # Default: [] enable: - appends - asmdecl @@ -78,7 +85,7 @@ linters-settings: lll: line-length: 160 misspell: - locale: UK + locale: US, UK nolintlint: allow-unused: false # report any unused nolint directives require-explanation: false # don't require an explanation for nolint directives @@ -90,10 +97,12 @@ linters: - bodyclose - dogsled - dupl - - exportloopref + - copyloopvar - errcheck - funlen - goconst + - gosmopolitan + - gocritic - gocyclo - gofmt - goimports @@ -104,6 +113,7 @@ linters: - ineffassign - lll - misspell + - mnd - nakedret - nolintlint - rowserrcheck @@ -119,9 +129,13 @@ linters: issues: # Exclude configuration for test files exclude-rules: - - path: (.+)_test.go + - path: _test\.go linters: + - gomnd # magic numbers + - govet # we don't care about align and other problems in test files usually. - lll # long lines; test strings, bytes etc. + - mnd # magic numbers - scopelint # using tt var in ranged loop - funlen # long functions, common in table-driven tests - - govet # fieldalignment on test structs \ No newline at end of file + - dupl # duplicate code detection + diff --git a/Makefile b/Makefile index 2c51577..d5e0b54 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ deps: @echo "" @echo "***** Installing dependencies for ${TOOL} *****" go clean --cache - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.0 lint: deps reportdir @echo "" diff --git a/cmd/in-addr/main.go b/cmd/in-addr/main.go index 6020f39..102646b 100644 --- a/cmd/in-addr/main.go +++ b/cmd/in-addr/main.go @@ -16,7 +16,9 @@ const ( // v6splitBits is the size of the subnet to split down to for IPv6 v6splitBits uint = 64 // v6Bytes is used to describe how many bytes an ipv6 address takes to store. - v6Bytes int = 16 + v6Bytes int = 16 + v4SubnetSize int = 32 + v6SubnetSize int = 128 ) var cli struct { @@ -39,6 +41,8 @@ func fatal(m ...string) string { } // ipv6 process IPv6 addresses into subnets, then reverse them. +// +//nolint:mnd // not an mnd func ipv6(prefix netip.Prefix) ([]string, error) { ipv6, err := netaddr.ParseIPv6Net(prefix.String()) if err != nil { @@ -93,6 +97,7 @@ func ipv4(prefix netip.Prefix) ([]string, error) { // using the slice of subnets we need to reverse the network addresses and print them to stdout. for idx := 0; idx < len(ips); idx++ { var reversed strings.Builder + //nolint:mnd // not an mnd for segment := len(ips[idx].As4()) - 2; segment >= 0; segment-- { fmt.Fprintf(&reversed, "%d.", ips[idx].As4()[segment]) } @@ -106,10 +111,10 @@ func ipv4(prefix netip.Prefix) ([]string, error) { func checkPrefixes(prefix netip.Prefix) ([]string, error) { networkAddress := prefix.Masked() switch prefix.Addr().BitLen() { - case 128: + case v6SubnetSize: // IPv6 magic return ipv6(networkAddress) - case 32: + case v4SubnetSize: // IPv4 magic return ipv4(networkAddress) default: @@ -126,7 +131,7 @@ func (g *Generate) Run() error { } prefix, err := netip.ParsePrefix(g.Subnet) if err != nil { - return fmt.Errorf(fatal(err.Error())) + return fmt.Errorf("%s", fatal(err.Error())) } results, err := checkPrefixes(prefix) if err != nil { @@ -143,17 +148,16 @@ func (g *Generate) subnet() error { if !strings.Contains(g.Subnet, "/") { p, err := netip.ParseAddr(g.Subnet) if err != nil { - return fmt.Errorf(fatal(g.Subnet, "invalid input, does not match IP Address or Prefix")) + return fmt.Errorf("%s", fatal(g.Subnet, "invalid input, does not match IP Address or Prefix")) } var withPrefix string switch p.BitLen() { - case 32: - withPrefix = fmt.Sprintf("%s/32", g.Subnet) - - case 128: + case v6SubnetSize: withPrefix = fmt.Sprintf("%s/128", g.Subnet) + case v4SubnetSize: + withPrefix = fmt.Sprintf("%s/32", g.Subnet) } - return fmt.Errorf(fatal(g.Subnet, "does not include a subnet mask, try", withPrefix)) + return fmt.Errorf("%s", fatal(g.Subnet, "does not include a subnet mask, try", withPrefix)) } return nil } diff --git a/go.mod b/go.mod index c5cc239..e78960f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/jimmystewpot/in-addr -go 1.22.1 +go 1.23 require ( github.com/alecthomas/kong v0.9.0 From 902cbbf373e8537a1f12a4980bb7c65d2759c73b Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 17 Sep 2024 15:01:41 +1000 Subject: [PATCH 2/5] update goreleaser configuration file --- .github/workflows/release.yml | 2 +- .goreleaser.yaml | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5f1e174..60c6b7f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: version: latest args: build --clean - name: Run GoReleaser Release - uses: goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: latest diff --git a/.goreleaser.yaml b/.goreleaser.yaml index bf63002..551eeb3 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,3 +1,4 @@ +version: 2 report_sizes: true before: @@ -30,15 +31,29 @@ builds: - netbsd - openbsd - windows + goarch: - amd64 - arm - arm64 - - 386 + goarm: - 6 - 7 + goamd64: + - v2 + - v3 + + ignore: + - goos: darwin + goarch: arm + goarm: 6 + - goos: darwin + goarch: arm + goarm: 7 + + mod_timestamp: "{{ .CommitTimestamp }}" skip: false no_unique_dist_dir: false From 87d04c728f407b8affdc760d59880c2703c46e1e Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 17 Sep 2024 15:03:37 +1000 Subject: [PATCH 3/5] update goreleaser action from v5 to v6 --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 60c6b7f..a7ba75a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: with: go-version: stable - name: Run GoReleaser Build - uses: goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: latest From 21e49ee2378913098e316b86265048e87d8b50e2 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 17 Sep 2024 15:05:51 +1000 Subject: [PATCH 4/5] fix error in configuration file that mismatched the version --- .github/workflows/sonar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index ce72366..f2556f7 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -10,7 +10,7 @@ jobs: name: SonarCloud runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up Go From d87ed1247f2518152132942ab0490fb91e1dc45b Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 17 Sep 2024 15:14:58 +1000 Subject: [PATCH 5/5] fix goreleaser to not execute on pull requests --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a7ba75a..cb3516c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,6 @@ name: goreleaser on: - pull_request: push: tags: - "*"