Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Go to 1.23 which includes new linter rules #2

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: goreleaser

on:
pull_request:
push:
tags:
- "*"
Expand All @@ -24,13 +23,13 @@ jobs:
with:
go-version: stable
- name: Run GoReleaser Build
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: build --clean
- name: Run GoReleaser Release
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 20 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -90,10 +97,12 @@ linters:
- bodyclose
- dogsled
- dupl
- exportloopref
- copyloopvar
- errcheck
- funlen
- goconst
- gosmopolitan
- gocritic
- gocyclo
- gofmt
- goimports
Expand All @@ -104,6 +113,7 @@ linters:
- ineffassign
- lll
- misspell
- mnd
- nakedret
- nolintlint
- rowserrcheck
Expand All @@ -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
- dupl # duplicate code detection

17 changes: 16 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
report_sizes: true

before:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
24 changes: 14 additions & 10 deletions cmd/in-addr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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])
}
Expand All @@ -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:
Expand All @@ -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 {
Expand All @@ -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
}
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/jimmystewpot/in-addr

go 1.22.1
go 1.23

require (
github.com/alecthomas/kong v0.9.0
Expand Down
Loading