From bf3946c4011b0d3b4785df61cb2c6bc28d89da30 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 3 Dec 2023 01:03:59 +0100 Subject: [PATCH 1/4] chore: remove trailing newline --- cmd/contains.go | 2 +- cmd/count.go | 2 +- cmd/overlaps.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/contains.go b/cmd/contains.go index 0f7fc49..b7aa78f 100644 --- a/cmd/contains.go +++ b/cmd/contains.go @@ -14,7 +14,7 @@ const ( "cidr contains 10.0.0.0/16 10.0.14.5\n" + "\n" + "# Check whether an IPv6 CIDR range contains a given IPv6 address\n" + - "cidr contains 2001:db8:1234:1a00::/106 2001:db8:1234:1a00::\n" + "cidr contains 2001:db8:1234:1a00::/106 2001:db8:1234:1a00::" ) var ( diff --git a/cmd/count.go b/cmd/count.go index 44da4dd..4237849 100644 --- a/cmd/count.go +++ b/cmd/count.go @@ -14,7 +14,7 @@ const ( "cidr count 10.0.0.0/16\n" + "\n" + "# Return the count of all distinct host addresses within a given IPv6 CIDR range\n" + - "cidr count 2001:db8:1234:1a00::/106\n" + "cidr count 2001:db8:1234:1a00::/106" ) var ( diff --git a/cmd/overlaps.go b/cmd/overlaps.go index 1e976f8..de9cd1d 100644 --- a/cmd/overlaps.go +++ b/cmd/overlaps.go @@ -14,7 +14,7 @@ const ( "cidr overlaps 10.0.0.0/16 10.0.14.0/22\n" + "\n" + "# Check whether 2 IPv6 CIDR ranges overlap\n" + - "cidr overlaps 2001:db8:1111:2222:1::/80 2001:db8:1111:2222:1:1::/96\n" + "cidr overlaps 2001:db8:1111:2222:1::/80 2001:db8:1111:2222:1:1::/96" ) var overlapsCmd = &cobra.Command{ From 2a928e1a78344588c90292468556c193c3e34bae Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 3 Dec 2023 01:49:41 +0100 Subject: [PATCH 2/4] feat: add `golangci-lint` --- .github/workflows/ci.yaml | 9 ++++++--- .golangci.yml | 27 +++++++++++++++++++++++++++ cmd/root.go | 6 +++++- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 92c4905..dd05925 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -11,9 +11,12 @@ jobs: uses: actions/setup-go@v4 with: go-version-file: go.mod - - name: Generate - run: go generate -v ./... + cache: true - name: Build run: go build -v ./... - - name: Test + - name: Run linters + uses: golangci/golangci-lint-action@v3 + with: + version: latest + - name: Run tests run: go test -v ./... diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..4c6bb5a --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,27 @@ +# Visit https://golangci-lint.run/ for usage documentation +# and information on other useful linters +issues: + max-per-linter: 0 + max-same-issues: 0 + +linters: + disable-all: true + enable: + - durationcheck + - errcheck + - exportloopref + - forcetypeassert + - godot + - gofmt + - gosimple + - ineffassign + - makezero + - misspell + - nilerr + - predeclared + - staticcheck + - tenv + - unconvert + - unparam + - unused + - vet diff --git a/cmd/root.go b/cmd/root.go index b395ba0..3a882fd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,7 +17,11 @@ var ( Short: "cidr - CLI to perform various actions on CIDR ranges", Version: version, // The version is set during the build by making using of `go build -ldflags` Run: func(cmd *cobra.Command, args []string) { - cmd.Help() + err := cmd.Help() + if err != nil { + fmt.Println(err) + os.Exit(1) + } }, } ) From 6fc3a7abf53f22cf63f619ea41d4867cb8c7217c Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 3 Dec 2023 01:58:27 +0100 Subject: [PATCH 3/4] chore: add couple other linters to golangci --- .golangci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 4c6bb5a..6a74e5a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,16 +4,28 @@ issues: max-per-linter: 0 max-same-issues: 0 + exclude-rules: + # disable funlen for test funcs + - source: "^func Test" + linters: + - funlen + linters: disable-all: true enable: + - bidichk - durationcheck + - decorder + - dogsled - errcheck - exportloopref - forcetypeassert + - funlen - godot + - godox - gofmt - gosimple + - goconst - ineffassign - makezero - misspell From 164c734d1f2747ebaf5ddf6fa0eb0cc1b6998d35 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 3 Dec 2023 02:00:47 +0100 Subject: [PATCH 4/4] chore: can be a 1-liner --- .golangci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6a74e5a..bc255c4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,4 @@ -# Visit https://golangci-lint.run/ for usage documentation -# and information on other useful linters +# Visit https://golangci-lint.run/ for usage documentation and information on other useful linters issues: max-per-linter: 0 max-same-issues: 0