From 584734d38e7b02d7841cbb727349a302f830ab29 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 12 Jul 2026 07:32:18 +0200 Subject: [PATCH] Update static checkers and Go to 1.26 Also fix issues found by updated static checkers. --- .gitlab-ci.yml | 9 +------- .golangci.yml | 59 ++++++++++++++++++++++++++++++++++++++++---------- ci/run | 4 +--- config.go | 4 ++-- dot.go | 27 ++++++++++++++++++----- go.mod | 2 +- setup.go | 29 ++++++++++++++++++++----- 7 files changed, 96 insertions(+), 38 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 23f32e8..615e2ec 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,11 +1,4 @@ golang: - image: golang:1.23-bookworm + image: golang:1.26 script: - ./ci/run - -golang-debian-stable: - image: golang:1.19-bookworm - script: - # Only check building as not all additional checks work with the old - # golang version. - - go build diff --git a/.golangci.yml b/.golangci.yml index 7a20a33..8fd3586 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,35 +1,70 @@ +version: "2" + linters: - disable-all: true + default: none enable: # Enabled by default - errcheck - - gosimple - govet - ineffassign - staticcheck - unused # Additional checks - bodyclose + - containedctx - contextcheck - copyloopvar - durationcheck - errname - exhaustive - - exportloopref - - gofmt + - exptostd + - gocheckcompilerdirectives + - gocritic + - iface + - importas - nilerr + - nilnesserr - nolintlint + - nonamedreturns + - nosprintfhostport - predeclared + - reassign + - recvcheck - rowserrcheck - - typecheck + - thelper + - tparallel - unconvert + - usestdlibvars + - usetesting - wastedassign - issues: - # Don't hide potential important issues - exclude-use-default: false + settings: + exhaustive: + # "default" is good enough to be exhaustive + default-signifies-exhaustive: true + gocritic: + disabled-checks: + - exitAfterDefer + - ifElseChain + - singleCaseSwitch + staticcheck: + checks: + # Defaults + - "all" + - "-ST1000" + - "-ST1003" + - "-ST1016" + - "-ST1020" + - "-ST1021" + - "-ST1022" + # + - "-QF1001" + - "-QF1003" + - "-QF1003" + - "-QF1007" + usestdlibvars: + http-method: false + -linters-settings: - exhaustive: - # "default" is good enough to be exhaustive - default-signifies-exhaustive: true +run: + timeout: 10m diff --git a/ci/run b/ci/run index 5ba8ec2..9c18468 100755 --- a/ci/run +++ b/ci/run @@ -17,9 +17,7 @@ make # Additional static checks only run in CI go install golang.org/x/vuln/cmd/govulncheck@latest govulncheck ./... -go install honnef.co/go/tools/cmd/staticcheck@v0.5.1 -staticcheck ./... -go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.0 +go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2 golangci-lint run test -z "$(git clean -nd)" # any untracked files left? diff --git a/config.go b/config.go index 11963e6..ffac2ba 100644 --- a/config.go +++ b/config.go @@ -55,7 +55,7 @@ type Link struct { Addrs []netip.Prefix } B struct { - *Node + Node *Node Addrs []netip.Prefix } } @@ -65,7 +65,7 @@ func LoadConfig(path string) (*Config, error) { if err != nil { return nil, err } - defer f.Close() + defer f.Close() //nolint:errcheck cfg := Config{ Nets: make(map[string]*Net), diff --git a/dot.go b/dot.go index c0f058e..b33cd37 100644 --- a/dot.go +++ b/dot.go @@ -18,11 +18,17 @@ func writeDot(cfg *Config, path string) error { if err != nil { return err } - defer f.Close() + defer f.Close() //nolint:errcheck // checked by f.Sync() below w := bufio.NewWriter(f) - fmt.Fprintf(w, "graph {\n") - fmt.Fprintf(w, "graph [nodesep=3]\n") + _, err = fmt.Fprintf(w, "graph {\n") + if err != nil { + return err + } + _, err = fmt.Fprintf(w, "graph [nodesep=3]\n") + if err != nil { + return err + } for _, node := range cfg.Nodes { var as []string @@ -31,8 +37,11 @@ func writeDot(cfg *Config, path string) error { as = append(as, fmt.Sprintf(" %s 
", html.EscapeString(x.String()))) } - fmt.Fprintf(w, "%q [label=<%s>]\n", + _, err := fmt.Fprintf(w, "%q [label=<%s>]\n", node.Name, strings.Join(as, "")) + if err != nil { + return err + } } for _, link := range cfg.Links { @@ -46,12 +55,18 @@ func writeDot(cfg *Config, path string) error { abs = append(abs, fmt.Sprintf(" %s 
", html.EscapeString(x.Addr().String()))) } - fmt.Fprintf(w, "%q -- %q [taillabel=<%s>,headlabel=<%s>,labelfontsize=10]\n", + _, err := fmt.Fprintf(w, "%q -- %q [taillabel=<%s>,headlabel=<%s>,labelfontsize=10]\n", link.A.Node.Name, link.B.Node.Name, strings.Join(aas, ""), strings.Join(abs, "")) + if err != nil { + return err + } } - fmt.Fprintf(w, "}\n") + _, err = fmt.Fprintf(w, "}\n") + if err != nil { + return err + } err = w.Flush() if err != nil { diff --git a/go.mod b/go.mod index 2cba665..0860777 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module linux-network-namespace-labs -go 1.19 +go 1.26 diff --git a/setup.go b/setup.go index bbf42f4..f220f51 100644 --- a/setup.go +++ b/setup.go @@ -253,25 +253,42 @@ func writeHosts(cfg *Config, path string) error { if err != nil { return err } - defer f.Close() + defer f.Close() //nolint:errcheck // checked by f.Sync() below w := bufio.NewWriter(f) // Standard entries - fmt.Fprintf(w, "127.0.0.1 localhost\n") - fmt.Fprintf(w, "::1 localhost ip6-localhost ip6-loopback\n") + _, err = fmt.Fprintf(w, "127.0.0.1 localhost\n") + if err != nil { + return err + } + _, err = fmt.Fprintf(w, "::1 localhost ip6-localhost ip6-loopback\n") + if err != nil { + return err + } for _, node := range cfg.Nodes { for _, x := range node.Loopbacks { - fmt.Fprintf(w, "%s %s-loop\n", x.String(), node.Name) + _, err := fmt.Fprintf(w, "%s %s-loop\n", x.String(), node.Name) + if err != nil { + return err + } } } for _, link := range cfg.Links { for _, x := range link.A.Addrs { - fmt.Fprintf(w, "%s %s\n", x.Addr().String(), link.A.Node.Name) + _, err := fmt.Fprintf(w, "%s %s\n", x.Addr().String(), + link.A.Node.Name) + if err != nil { + return err + } } for _, x := range link.B.Addrs { - fmt.Fprintf(w, "%s %s\n", x.Addr().String(), link.B.Node.Name) + _, err := fmt.Fprintf(w, "%s %s\n", x.Addr().String(), + link.B.Node.Name) + if err != nil { + return err + } } } -- 2.55.0