diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd3f18b..36335b2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,30 +11,33 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: ["1.18"] + go-version: ["1.20"] steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: - version: v1.47.3 + version: v1.60.3 test: name: test runs-on: ubuntu-latest strategy: matrix: - go-version: ["1.18", "1.19"] + go-version: + - "1.20" + - "1.21" + - "1.22" steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: unit-tests run: | go test -count=2 -race -covermode atomic -coverprofile=covprofile ./... diff --git a/.golangci.yml b/.golangci.yml index f4b30d5..1a59fb5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,7 +12,7 @@ linters-settings: - performance - style govet: - check-shadowing: true + enable-all: true nolintlint: require-explanation: true require-specific: true @@ -20,23 +20,27 @@ linters-settings: allow-assign-and-anything: true allow-cuddle-declarations: true allow-assign-and-call: true + depguard: + rules: + main: + list-mode: lax + allow: + - "github.com/uber/h3-go/v4" linters: disable-all: true enable: - bodyclose - - deadcode - depguard - dogsled - dupl - errcheck - - exportloopref + # - copyloopvar Enable this after upgrading go version to 1.22 - exhaustive - goconst - # - gocritic - gofmt - goimports - - gomnd + - mnd - gocyclo - gosec - gosimple @@ -49,14 +53,12 @@ linters: - predeclared - revive - staticcheck - - structcheck - stylecheck - thelper - tparallel - typecheck - unconvert - unparam - - varcheck - whitespace - wsl diff --git a/README.md b/README.md index 93ad9c1..9ccc913 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ func ExampleLatLngToCell() { | `originToDirectedEdges` | `Cell#DirectedEdges` | | `directedEdgeToBoundary` | `DirectedEdge#Boundary` | | `cellToVertex` | `CellToVertex` | -| `cellToVertexes` | `cellToVertexes` | +| `cellToVertexes` | `CellToVertexes` | | `vertexToLatLng` | `VertexToLatLng` | | `isValidVertex` | `IsValidVertex` | | `gridDistance` | `GridDistance`, `Cell#GridDistance` | diff --git a/bench_test.go b/bench_test.go index cb6b0d3..faccfa7 100644 --- a/bench_test.go +++ b/bench_test.go @@ -24,6 +24,7 @@ func BenchmarkToString(b *testing.B) { func BenchmarkFromString(b *testing.B) { for n := 0; n < b.N; n++ { + //nolint:gosec // IndexFromString returns uint64 and fixing that to detect integer overflows will break package API. Let's skip it for now. cell = Cell(IndexFromString("850dab63fffffff")) } } diff --git a/go.mod b/go.mod index 2dd6f9d..0fd5b13 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/uber/h3-go/v4 -go 1.18 +go 1.20 diff --git a/h3.go b/h3.go index a473af6..abaafbd 100644 --- a/h3.go +++ b/h3.go @@ -407,7 +407,7 @@ func EdgeLengthM(e DirectedEdge) float64 { func NumCells(resolution int) int { // NOTE: this is a mathematical operation, no need to call into H3 library. // See h3api.h for formula derivation. - return 2 + 120*intPow(7, (resolution)) //nolint:gomnd // math formula + return 2 + 120*intPow(7, (resolution)) //nolint:mnd // math formula } // Res0Cells returns all the cells at resolution 0. @@ -765,7 +765,7 @@ func ringSize(k int) int { return 1 } - return 6 * k //nolint:gomnd // math formula + return 6 * k //nolint:mnd // math formula } // Convert slice of LatLngs to an array of C LatLngs (represented in C-style as diff --git a/h3_test.go b/h3_test.go index 04a3a3c..db853b3 100644 --- a/h3_test.go +++ b/h3_test.go @@ -324,6 +324,8 @@ func TestStrings(t *testing.T) { t.Run("good string round trip", func(t *testing.T) { t.Parallel() i := IndexFromString(validCell.String()) + + //nolint:gosec // IndexFromString returns uint64 and fixing that to detect integer overflows will break package API. Let's skip it for now. assertEqual(t, validCell, Cell(i)) }) @@ -612,8 +614,10 @@ func TestPentagons(t *testing.T) { res := res t.Run(fmt.Sprintf("res=%d", res), func(t *testing.T) { t.Parallel() + pentagons := Pentagons(res) assertEqual(t, 12, len(pentagons)) + for _, pentagon := range pentagons { assertTrue(t, pentagon.IsPentagon()) assertEqual(t, res, pentagon.Resolution()) @@ -737,6 +741,7 @@ func assertEqual[T comparable](t *testing.T, expected, actual T, msgAndArgs ...i expStr = fmt.Sprintf("%v", e) actStr = fmt.Sprintf("%v", a) } + t.Errorf("%v != %v", expStr, actStr) logMsgAndArgs(t, msgAndArgs...) } @@ -779,6 +784,7 @@ func assertEqualLatLngs(t *testing.T, expected, actual []LatLng, msgAndArgs ...i t.Errorf("LatLngs[%d]: (%s, %s)", i, latStr, lngStr) logMsgAndArgs(t, msgAndArgs...) + count++ if count > 10 { @@ -808,6 +814,7 @@ func assertEqualCells(t *testing.T, expected, actual []Cell, msgAndArgs ...inter if c != actual[i] { t.Errorf("Cells[%d]: %v != %v", i, c, actual[i]) logMsgAndArgs(t, msgAndArgs...) + count++ if count > 10 { @@ -863,6 +870,7 @@ func assertEqualDisks(t *testing.T, expected, actual []Cell) { for i, cell := range expected { if cell != actual[i] { t.Errorf("cell[%d]: %v != %v", i, cell, actual[i]) + count++ if count > 5 {