From 852719de423d9db7f91824f42a47ed044f13aaee Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Mon, 12 Aug 2024 23:39:09 +0330 Subject: [PATCH 01/27] feat: added IsValidVertex method --- h3.go | 4 ++++ h3_test.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/h3.go b/h3.go index 77fe71a..3819b65 100644 --- a/h3.go +++ b/h3.go @@ -713,6 +713,10 @@ func LocalIJToCell(origin Cell, ij CoordIJ) Cell { return Cell(out) } +func IsValidVertex(c Cell) bool { + return C.isValidVertex(C.H3Index(c)) == 1 +} + func maxGridDiskSize(k int) int { return 3*k*(k+1) + 1 } diff --git a/h3_test.go b/h3_test.go index c2ab758..476d9d4 100644 --- a/h3_test.go +++ b/h3_test.go @@ -621,6 +621,13 @@ func TestPentagons(t *testing.T) { } } +func TestIsValidVertex(t *testing.T) { + t.Parallel() + + assertFalse(t, IsValidVertex(0)) + assertTrue(t, IsValidVertex(2473183460575936511)) +} + func equalEps(expected, actual float64) bool { return math.Abs(expected-actual) < eps } From 10feb9a05bb6dbe8fa54e105bf651ad6bdf5b7e3 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Mon, 12 Aug 2024 23:40:13 +0330 Subject: [PATCH 02/27] docs: added IsValidVertex to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eaed8ed..29175c5 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ func ExampleLatLngToCell() { | `cellToVertex` | TODO | | `cellToVertexes` | TODO | | `vertexToLatLng` | TODO | -| `isValidVertex` | TODO | +| `isValidVertex` | `IsValidVertex` | | `gridDistance` | `GridDistance`, `Cell#GridDistance` | | `gridPathCells` | `GridPath`, `Cell#GridPath` | | `cellToLocalIj` | `CellToLocalIJ` | From a4c797d91b5181f411812966875e5f42ba0c02b8 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Mon, 12 Aug 2024 23:58:12 +0330 Subject: [PATCH 03/27] fix: fix loop variable res captured by func literal error --- h3_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/h3_test.go b/h3_test.go index 476d9d4..e118228 100644 --- a/h3_test.go +++ b/h3_test.go @@ -609,6 +609,7 @@ func TestPentagons(t *testing.T) { t.Parallel() for _, res := range []int{0, 8, 15} { + res := res t.Run(fmt.Sprintf("res=%d", res), func(t *testing.T) { t.Parallel() pentagons := Pentagons(res) From 2e5075fb2a9e147fd87dc4b5842dc3922c7a6d59 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Sat, 17 Aug 2024 23:34:48 +0330 Subject: [PATCH 04/27] feat: add cell to vertex function --- README.md | 2 +- h3.go | 7 +++++++ h3_test.go | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 29175c5..a2d6c1a 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ func ExampleLatLngToCell() { | `directedEdgeToCells` | `DirectedEdge#Cells` | | `originToDirectedEdges` | `Cell#DirectedEdges` | | `directedEdgeToBoundary` | `DirectedEdge#Boundary` | -| `cellToVertex` | TODO | +| `cellToVertex` | `CellToVertex` | | `cellToVertexes` | TODO | | `vertexToLatLng` | TODO | | `isValidVertex` | `IsValidVertex` | diff --git a/h3.go b/h3.go index 3819b65..6d5be28 100644 --- a/h3.go +++ b/h3.go @@ -713,6 +713,13 @@ func LocalIJToCell(origin Cell, ij CoordIJ) Cell { return Cell(out) } +func CellToVertex(c Cell, vertexNum int) Cell { + var out C.H3Index + C.cellToVertex(C.H3Index(c), C.int(vertexNum), &out) + + return Cell(out) +} + func IsValidVertex(c Cell) bool { return C.isValidVertex(C.H3Index(c)) == 1 } diff --git a/h3_test.go b/h3_test.go index e118228..560b7a4 100644 --- a/h3_test.go +++ b/h3_test.go @@ -622,6 +622,16 @@ func TestPentagons(t *testing.T) { } } +func TestCellToVertex(t *testing.T) { + t.Parallel() + + validVertex := CellToVertex(validCell, 0) + invalidVertex := CellToVertex(validCell, 6) + + assertEqual(t, 0x2050dab63fffffff, validVertex) + assertEqual(t, 0, invalidVertex) +} + func TestIsValidVertex(t *testing.T) { t.Parallel() From 011422a6b52d6b28ce4e204adc7a613ea9ba1179 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Sat, 17 Aug 2024 23:50:35 +0330 Subject: [PATCH 05/27] feat: added cell to vertexes function --- README.md | 2 +- h3.go | 12 ++++++++++-- h3_test.go | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a2d6c1a..729df65 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ func ExampleLatLngToCell() { | `originToDirectedEdges` | `Cell#DirectedEdges` | | `directedEdgeToBoundary` | `DirectedEdge#Boundary` | | `cellToVertex` | `CellToVertex` | -| `cellToVertexes` | TODO | +| `cellToVertexes` | `cellToVertexes` | | `vertexToLatLng` | TODO | | `isValidVertex` | `IsValidVertex` | | `gridDistance` | `GridDistance`, `Cell#GridDistance` | diff --git a/h3.go b/h3.go index 6d5be28..f3618ac 100644 --- a/h3.go +++ b/h3.go @@ -60,8 +60,9 @@ const ( base16 = 16 bitSize = 64 - numCellEdges = 6 - numEdgeCells = 2 + numCellEdges = 6 + numEdgeCells = 2 + numCellVertexes = 6 DegsToRads = math.Pi / 180.0 RadsToDegs = 180.0 / math.Pi @@ -720,6 +721,13 @@ func CellToVertex(c Cell, vertexNum int) Cell { return Cell(out) } +func CellToVertexes(c Cell) []Cell { + out := make([]C.H3Index, numCellVertexes) + C.cellToVertexes(C.H3Index(c), &out[0]) + + return cellsFromC(out, true, false) +} + func IsValidVertex(c Cell) bool { return C.isValidVertex(C.H3Index(c)) == 1 } diff --git a/h3_test.go b/h3_test.go index 560b7a4..c272953 100644 --- a/h3_test.go +++ b/h3_test.go @@ -632,6 +632,26 @@ func TestCellToVertex(t *testing.T) { assertEqual(t, 0, invalidVertex) } +func TestCellToVertexes(t *testing.T) { + t.Parallel() + + testCases := []struct { + cell Cell + numVertexes int + }{ + {cell: validCell, numVertexes: 6}, + {cell: pentagonCell, numVertexes: 5}, + {cell: -1, numVertexes: 0}, // Invalid cel. + } + + for _, tc := range testCases { + t.Run(fmt.Sprint(tc.numVertexes), func(t *testing.T) { + vertexes := CellToVertexes(tc.cell) + assertEqual(t, tc.numVertexes, len(vertexes)) + }) + } +} + func TestIsValidVertex(t *testing.T) { t.Parallel() From 04a186842eaaa8c78f7f15d0b190491067b75aba Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Sat, 17 Aug 2024 23:51:47 +0330 Subject: [PATCH 06/27] test: improve tests for cell to vertex function --- h3_test.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/h3_test.go b/h3_test.go index c272953..6f4ec1b 100644 --- a/h3_test.go +++ b/h3_test.go @@ -625,11 +625,22 @@ func TestPentagons(t *testing.T) { func TestCellToVertex(t *testing.T) { t.Parallel() - validVertex := CellToVertex(validCell, 0) - invalidVertex := CellToVertex(validCell, 6) + testCases := []struct { + cell Cell + expectedVertex Cell + vertexNum int + }{ + {cell: validCell, expectedVertex: 0x2050dab63fffffff, vertexNum: 0}, + {cell: validCell, expectedVertex: 0, vertexNum: 6}, // vertex num should be between 0 and 5 for hexagonal cells. + } + + for i, tc := range testCases { + t.Run(fmt.Sprint(i), func(t *testing.T) { + vertex := CellToVertex(tc.cell, tc.vertexNum) + assertEqual(t, tc.expectedVertex, vertex) + }) + } - assertEqual(t, 0x2050dab63fffffff, validVertex) - assertEqual(t, 0, invalidVertex) } func TestCellToVertexes(t *testing.T) { From 4b62928c06ef7001ded74f8f3305aa21b4f81366 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Sun, 18 Aug 2024 00:01:46 +0330 Subject: [PATCH 07/27] feat: added vertex to lat lng method --- README.md | 2 +- h3.go | 7 +++++++ h3_test.go | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 729df65..93ad9c1 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ func ExampleLatLngToCell() { | `directedEdgeToBoundary` | `DirectedEdge#Boundary` | | `cellToVertex` | `CellToVertex` | | `cellToVertexes` | `cellToVertexes` | -| `vertexToLatLng` | TODO | +| `vertexToLatLng` | `VertexToLatLng` | | `isValidVertex` | `IsValidVertex` | | `gridDistance` | `GridDistance`, `Cell#GridDistance` | | `gridPathCells` | `GridPath`, `Cell#GridPath` | diff --git a/h3.go b/h3.go index f3618ac..a473af6 100644 --- a/h3.go +++ b/h3.go @@ -728,6 +728,13 @@ func CellToVertexes(c Cell) []Cell { return cellsFromC(out, true, false) } +func VertexToLatLng(vertex Cell) LatLng { + var out C.LatLng + C.vertexToLatLng(C.H3Index(vertex), &out) + + return latLngFromC(out) +} + func IsValidVertex(c Cell) bool { return C.isValidVertex(C.H3Index(c)) == 1 } diff --git a/h3_test.go b/h3_test.go index 6f4ec1b..dbb84cd 100644 --- a/h3_test.go +++ b/h3_test.go @@ -663,6 +663,25 @@ func TestCellToVertexes(t *testing.T) { } } +func TestVertexToLatLng(t *testing.T) { + t.Parallel() + + testCases := []struct { + vertex Cell + expectedLatLng LatLng + }{ + {vertex: CellToVertex(validCell, 0), expectedLatLng: LatLng{Lat: 67.22475, Lng: -168.52301}}, + {vertex: -1, expectedLatLng: LatLng{}}, // Invalid vertex. + } + + for i, tc := range testCases { + t.Run(fmt.Sprint(i), func(t *testing.T) { + latLng := VertexToLatLng(tc.vertex) + assertEqualLatLng(t, tc.expectedLatLng, latLng) + }) + } +} + func TestIsValidVertex(t *testing.T) { t.Parallel() From d5c086e792b8a1359d069e3f96333e35671cb0e0 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Sun, 18 Aug 2024 00:17:55 +0330 Subject: [PATCH 08/27] fix: added t.Parallel() for subtests --- h3_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/h3_test.go b/h3_test.go index dbb84cd..b32c744 100644 --- a/h3_test.go +++ b/h3_test.go @@ -635,7 +635,9 @@ func TestCellToVertex(t *testing.T) { } for i, tc := range testCases { + tc := tc t.Run(fmt.Sprint(i), func(t *testing.T) { + t.Parallel() vertex := CellToVertex(tc.cell, tc.vertexNum) assertEqual(t, tc.expectedVertex, vertex) }) @@ -656,7 +658,9 @@ func TestCellToVertexes(t *testing.T) { } for _, tc := range testCases { + tc := tc t.Run(fmt.Sprint(tc.numVertexes), func(t *testing.T) { + t.Parallel() vertexes := CellToVertexes(tc.cell) assertEqual(t, tc.numVertexes, len(vertexes)) }) @@ -675,7 +679,9 @@ func TestVertexToLatLng(t *testing.T) { } for i, tc := range testCases { + tc := tc t.Run(fmt.Sprint(i), func(t *testing.T) { + t.Parallel() latLng := VertexToLatLng(tc.vertex) assertEqualLatLng(t, tc.expectedLatLng, latLng) }) From d488fcdebb249f50ef10d6ff196023edb8e05478 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Sun, 18 Aug 2024 00:23:37 +0330 Subject: [PATCH 09/27] fix: fix lint issues --- h3_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/h3_test.go b/h3_test.go index b32c744..8dfbd0c 100644 --- a/h3_test.go +++ b/h3_test.go @@ -636,13 +636,13 @@ func TestCellToVertex(t *testing.T) { for i, tc := range testCases { tc := tc + t.Run(fmt.Sprint(i), func(t *testing.T) { t.Parallel() vertex := CellToVertex(tc.cell, tc.vertexNum) assertEqual(t, tc.expectedVertex, vertex) }) } - } func TestCellToVertexes(t *testing.T) { @@ -659,6 +659,7 @@ func TestCellToVertexes(t *testing.T) { for _, tc := range testCases { tc := tc + t.Run(fmt.Sprint(tc.numVertexes), func(t *testing.T) { t.Parallel() vertexes := CellToVertexes(tc.cell) @@ -680,6 +681,7 @@ func TestVertexToLatLng(t *testing.T) { for i, tc := range testCases { tc := tc + t.Run(fmt.Sprint(i), func(t *testing.T) { t.Parallel() latLng := VertexToLatLng(tc.vertex) From 78b8a47757d1b41a03d6e67208506d481fb61cf8 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Sun, 18 Aug 2024 00:27:13 +0330 Subject: [PATCH 10/27] fix: fix lint issues --- h3_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/h3_test.go b/h3_test.go index 8dfbd0c..a710d9a 100644 --- a/h3_test.go +++ b/h3_test.go @@ -636,9 +636,9 @@ func TestCellToVertex(t *testing.T) { for i, tc := range testCases { tc := tc - t.Run(fmt.Sprint(i), func(t *testing.T) { t.Parallel() + vertex := CellToVertex(tc.cell, tc.vertexNum) assertEqual(t, tc.expectedVertex, vertex) }) @@ -659,9 +659,9 @@ func TestCellToVertexes(t *testing.T) { for _, tc := range testCases { tc := tc - t.Run(fmt.Sprint(tc.numVertexes), func(t *testing.T) { t.Parallel() + vertexes := CellToVertexes(tc.cell) assertEqual(t, tc.numVertexes, len(vertexes)) }) @@ -681,9 +681,9 @@ func TestVertexToLatLng(t *testing.T) { for i, tc := range testCases { tc := tc - t.Run(fmt.Sprint(i), func(t *testing.T) { t.Parallel() + latLng := VertexToLatLng(tc.vertex) assertEqualLatLng(t, tc.expectedLatLng, latLng) }) From fb31b100ccce69a6fc2fa1ce3439c0de2caee76d Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Sun, 18 Aug 2024 00:36:50 +0330 Subject: [PATCH 11/27] fix: fix lint issues --- h3_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/h3_test.go b/h3_test.go index a710d9a..04a3a3c 100644 --- a/h3_test.go +++ b/h3_test.go @@ -636,6 +636,7 @@ func TestCellToVertex(t *testing.T) { for i, tc := range testCases { tc := tc + t.Run(fmt.Sprint(i), func(t *testing.T) { t.Parallel() @@ -681,6 +682,7 @@ func TestVertexToLatLng(t *testing.T) { for i, tc := range testCases { tc := tc + t.Run(fmt.Sprint(i), func(t *testing.T) { t.Parallel() From 94d70d996b0ff4ff8fb289821fb74b45be8050a1 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Mon, 26 Aug 2024 19:28:24 +0330 Subject: [PATCH 12/27] chore: upgrade to go 1.22 --- .github/workflows/build.yml | 9 +++++++-- go.mod | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd3f18b..99fd097 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: ["1.18"] + go-version: ["1.22"] steps: - uses: actions/setup-go@v3 @@ -28,7 +28,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: ["1.18", "1.19"] + go-version: + - "1.18" + - "1.19" + - "1.20" + - "1.21" + - "1.22" steps: - uses: actions/setup-go@v3 diff --git a/go.mod b/go.mod index 2dd6f9d..7e196ab 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/uber/h3-go/v4 -go 1.18 +go 1.22 From 5aefadd5774614734efb2e7bcef7f1a4448df5d2 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Mon, 26 Aug 2024 19:29:00 +0330 Subject: [PATCH 13/27] docs: fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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` | From c06d43acbec94c988c2c7d3975e9c3e6ff9fba01 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Mon, 26 Aug 2024 19:40:48 +0330 Subject: [PATCH 14/27] fix: revert to go 1.21 --- .github/workflows/build.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 99fd097..e4538d5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: ["1.22"] + go-version: ["1.21"] steps: - uses: actions/setup-go@v3 diff --git a/go.mod b/go.mod index 7e196ab..58320d4 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/uber/h3-go/v4 -go 1.22 +go 1.21 From c88919086f024835b4b7ea3ef3d20cf2dc566eda Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Mon, 26 Aug 2024 19:47:09 +0330 Subject: [PATCH 15/27] fix: revert to go 1.20 --- .github/workflows/build.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e4538d5..1e59721 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: ["1.21"] + go-version: ["1.20"] steps: - uses: actions/setup-go@v3 diff --git a/go.mod b/go.mod index 58320d4..0fd5b13 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/uber/h3-go/v4 -go 1.21 +go 1.20 From f30bae6ef7794c2d5e2825a830e741df1e63f123 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Mon, 26 Aug 2024 19:50:00 +0330 Subject: [PATCH 16/27] feat: support 3 latest go versions --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1e59721..f0b8ecf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,8 +29,6 @@ jobs: strategy: matrix: go-version: - - "1.18" - - "1.19" - "1.20" - "1.21" - "1.22" From 6222bb9c2c03bd21d31d29533e684daeb172802a Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 01:59:06 +0330 Subject: [PATCH 17/27] chore: bump golangci version to its current latest version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f0b8ecf..b9e2562 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.47.3 + version: v1.60.3 test: name: test From 9325bbd0f5728fbab9d0cb6452e0254fa3a62d86 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 02:20:13 +0330 Subject: [PATCH 18/27] fix: fix lint errors --- .golangci.yml | 3 +++ h3_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index f4b30d5..4faac52 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,9 @@ linters-settings: allow-assign-and-anything: true allow-cuddle-declarations: true allow-assign-and-call: true + main: + allow: + - "github.com/uber/h3-go/v4" linters: disable-all: true diff --git a/h3_test.go b/h3_test.go index 04a3a3c..57d7d46 100644 --- a/h3_test.go +++ b/h3_test.go @@ -612,8 +612,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 +739,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 +782,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 +812,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 +868,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 { From c8c13a230e60544f1daadfcd4abe16772109c616 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 02:50:11 +0330 Subject: [PATCH 19/27] fix: skip gosec lint errors for IndexFromString method --- bench_test.go | 1 + h3_test.go | 2 ++ 2 files changed, 3 insertions(+) diff --git a/bench_test.go b/bench_test.go index cb6b0d3..538b823 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 cell = Cell(IndexFromString("850dab63fffffff")) } } diff --git a/h3_test.go b/h3_test.go index 57d7d46..e2ecaa0 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 assertEqual(t, validCell, Cell(i)) }) From 299f11245701832eae181ee609935e1c755b6fa5 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 02:50:47 +0330 Subject: [PATCH 20/27] fix: remove inadtivated linters --- .golangci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4faac52..6e73a81 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -28,7 +28,6 @@ linters: disable-all: true enable: - bodyclose - - deadcode - depguard - dogsled - dupl @@ -52,14 +51,12 @@ linters: - predeclared - revive - staticcheck - - structcheck - stylecheck - thelper - tparallel - typecheck - unconvert - unparam - - varcheck - whitespace - wsl From 0e2b009d2835eb3d93da4c10e310dc58a305b71c Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 02:56:41 +0330 Subject: [PATCH 21/27] fix: fix depguard issues --- .golangci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6e73a81..68b184e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,9 +20,11 @@ linters-settings: allow-assign-and-anything: true allow-cuddle-declarations: true allow-assign-and-call: true - main: - allow: - - "github.com/uber/h3-go/v4" + depguard: + rules: + main: + allow: + - "github.com/uber/h3-go/v4" linters: disable-all: true From f7416d274a82bf8736d8415c600350edcc62cc29 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 03:02:24 +0330 Subject: [PATCH 22/27] fix: fix depguard issues --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 68b184e..17f75da 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,6 +23,7 @@ linters-settings: depguard: rules: main: + list-mode: lax allow: - "github.com/uber/h3-go/v4" From dc8b31a48554342a25c9374aa6f570a3f0791d6f Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 03:09:22 +0330 Subject: [PATCH 23/27] fix: fix nolintlint issues --- bench_test.go | 2 +- h3_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bench_test.go b/bench_test.go index 538b823..e54c5f4 100644 --- a/bench_test.go +++ b/bench_test.go @@ -24,7 +24,7 @@ func BenchmarkToString(b *testing.B) { func BenchmarkFromString(b *testing.B) { for n := 0; n < b.N; n++ { - //nolint:gosec + //nolint:gosec // IndexFromString returns uint64 and fixing that to detect integers overflows will break package API. Let's skip it for now. cell = Cell(IndexFromString("850dab63fffffff")) } } diff --git a/h3_test.go b/h3_test.go index e2ecaa0..aad1605 100644 --- a/h3_test.go +++ b/h3_test.go @@ -325,7 +325,7 @@ func TestStrings(t *testing.T) { t.Parallel() i := IndexFromString(validCell.String()) - //nolint:gosec + //nolint:gosec // IndexFromString returns uint64 and fixing that to detect integers overflows will break package API. Let's skip it for now. assertEqual(t, validCell, Cell(i)) }) From ab0b684938585bb45425a05f9dbee8385384c75a Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 03:22:01 +0330 Subject: [PATCH 24/27] fix: fix warn linter logs --- .golangci.yml | 48 ++++++++++++++++++++++++++++++++++++++++++++---- h3.go | 4 ++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 17f75da..7814c2f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,7 +12,48 @@ linters-settings: - performance - style govet: - check-shadowing: true + disable-all: true + enable: + - appends + - asmdecl + - assign + - atomic + - atomicalign + - bools + - buildtag + - cgocall + - composites + - copylocks + - deepequalerrors + - defers + - directive + - errorsas + - fieldalignment + - findcall + - framepointer + - httpresponse + - ifaceassert + - loopclosure + - lostcancel + - nilfunc + - nilness + - printf + - reflectvaluecompare + - shadow + - shift + - sigchanyzer + - slog + - sortslice + - stdmethods + - stringintconv + - structtag + - testinggoroutine + - tests + - unmarshal + - unreachable + - unsafeptr + - unusedresult + - unusedwrite nolintlint: require-explanation: true require-specific: true @@ -35,13 +76,12 @@ linters: - dogsled - dupl - errcheck - - exportloopref + # - copyloopvar Enable this after upgrading go version to 1.22 - exhaustive - goconst - # - gocritic - gofmt - goimports - - gomnd + - mnd - gocyclo - gosec - gosimple 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 From cd633c512ba3c3aea7eaa38a6326368963969b1d Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 03:24:47 +0330 Subject: [PATCH 25/27] fix: enable all govet analyzers which includes shadow as well --- .golangci.yml | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7814c2f..1a59fb5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,48 +12,7 @@ linters-settings: - performance - style govet: - disable-all: true - enable: - - appends - - asmdecl - - assign - - atomic - - atomicalign - - bools - - buildtag - - cgocall - - composites - - copylocks - - deepequalerrors - - defers - - directive - - errorsas - - fieldalignment - - findcall - - framepointer - - httpresponse - - ifaceassert - - loopclosure - - lostcancel - - nilfunc - - nilness - - printf - - reflectvaluecompare - - shadow - - shift - - sigchanyzer - - slog - - sortslice - - stdmethods - - stringintconv - - structtag - - testinggoroutine - - tests - - unmarshal - - unreachable - - unsafeptr - - unusedresult - - unusedwrite + enable-all: true nolintlint: require-explanation: true require-specific: true From 846ecb696ebe59fb5e8c227d4435046050ec9c33 Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 03:27:42 +0330 Subject: [PATCH 26/27] style: fix typo --- bench_test.go | 2 +- h3_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bench_test.go b/bench_test.go index e54c5f4..faccfa7 100644 --- a/bench_test.go +++ b/bench_test.go @@ -24,7 +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 integers overflows will break package API. Let's skip it for now. + //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/h3_test.go b/h3_test.go index aad1605..db853b3 100644 --- a/h3_test.go +++ b/h3_test.go @@ -325,7 +325,7 @@ func TestStrings(t *testing.T) { t.Parallel() i := IndexFromString(validCell.String()) - //nolint:gosec // IndexFromString returns uint64 and fixing that to detect integers overflows will break package API. Let's skip it for now. + //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)) }) From e29ad14caafe1c5c574eb2b1fd4d552a271f98ee Mon Sep 17 00:00:00 2001 From: Mojtaba Arezoomand Date: Thu, 29 Aug 2024 03:42:56 +0330 Subject: [PATCH 27/27] chore: bump version of github action packages --- .github/workflows/build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b9e2562..36335b2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,12 +14,12 @@ jobs: 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.60.3 @@ -34,10 +34,10 @@ jobs: - "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 ./...