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..bc255c4 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,38 @@ +# Visit https://golangci-lint.run/ for usage documentation and information on other useful linters +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 + - nilerr + - predeclared + - staticcheck + - tenv + - unconvert + - unparam + - unused + - vet 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 d42d574..f59d4b0 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{ diff --git a/cmd/root.go b/cmd/root.go index 8975d1f..fcc79d1 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) + } }, } )