diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 1ddfe1a..fd813bb 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -11,14 +11,14 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Setup Go - uses: actions/setup-go@v5 + uses: actions/setup-go@v6 with: go-version-file: go.mod check-latest: true - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v9.2.0 with: - version: v1.50 + version: v2.11.4 diff --git a/clip/clip.go b/clip/clip.go index b64fda3..765969c 100644 --- a/clip/clip.go +++ b/clip/clip.go @@ -91,10 +91,7 @@ func ring(box orb.Bound, in orb.Ring) orb.Ring { f := in[0] l := in[len(in)-1] - initClosed := false - if f == l { - initClosed = true - } + initClosed := f == l for edge := 1; edge <= 8; edge <<= 1 { out = out[:0] @@ -150,9 +147,11 @@ func ring(box orb.Bound, in orb.Ring) orb.Ring { } // bitCode returns the point position relative to the bbox: -// left mid right -// top 1001 1000 1010 -// mid 0001 0000 0010 +// +// left mid right +// top 1001 1000 1010 +// mid 0001 0000 0010 +// // bottom 0101 0100 0110 func bitCode(b orb.Bound, p orb.Point) int { code := 0 diff --git a/encoding/ewkb/ewkb_test.go b/encoding/ewkb/ewkb_test.go index 5d1dbee..10dcdb3 100644 --- a/encoding/ewkb/ewkb_test.go +++ b/encoding/ewkb/ewkb_test.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/binary" "encoding/hex" - "io/ioutil" + "io" "testing" "github.com/paulmach/orb" @@ -37,7 +37,7 @@ func MustDecodeHex(s string) []byte { func BenchmarkEncode_Point(b *testing.B) { g := orb.Point{1, 2} - e := NewEncoder(ioutil.Discard) + e := NewEncoder(io.Discard) b.ReportAllocs() b.ResetTimer() @@ -54,7 +54,7 @@ func BenchmarkEncode_LineString(b *testing.B) { {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, } - e := NewEncoder(ioutil.Discard) + e := NewEncoder(io.Discard) b.ReportAllocs() b.ResetTimer() diff --git a/encoding/internal/wkbcommon/wkb.go b/encoding/internal/wkbcommon/wkb.go index 515802e..415786b 100644 --- a/encoding/internal/wkbcommon/wkb.go +++ b/encoding/internal/wkbcommon/wkb.go @@ -284,11 +284,12 @@ func readByteOrderType(r io.Reader, buf []byte) (byteOrder, uint32, int, error) } var order byteOrder - if buf[0] == 0 { + switch buf[0] { + case 0: order = bigEndian - } else if buf[0] == 1 { + case 1: order = littleEndian - } else { + default: return 0, 0, 0, ErrNotWKB } diff --git a/encoding/mvt/marshal_test.go b/encoding/mvt/marshal_test.go index e30812d..2c14d8c 100644 --- a/encoding/mvt/marshal_test.go +++ b/encoding/mvt/marshal_test.go @@ -4,8 +4,8 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "math" + "os" "reflect" "testing" @@ -388,7 +388,7 @@ func comparePoints(t testing.TB, e, r []orb.Point, xEpsilon, yEpsilon float64) { } func loadMVT(t testing.TB, tile maptile.Tile) []byte { - data, err := ioutil.ReadFile(fmt.Sprintf("testdata/%d-%d-%d.mvt", tile.Z, tile.X, tile.Y)) + data, err := os.ReadFile(fmt.Sprintf("testdata/%d-%d-%d.mvt", tile.Z, tile.X, tile.Y)) if err != nil { t.Fatalf("failed to load mvt file: %v", err) } @@ -397,7 +397,7 @@ func loadMVT(t testing.TB, tile maptile.Tile) []byte { } func loadGeoJSON(t testing.TB, tile maptile.Tile) map[string]*geojson.FeatureCollection { - data, err := ioutil.ReadFile(fmt.Sprintf("testdata/%d-%d-%d.json", tile.Z, tile.X, tile.Y)) + data, err := os.ReadFile(fmt.Sprintf("testdata/%d-%d-%d.json", tile.Z, tile.X, tile.Y)) if err != nil { t.Fatalf("failed to load mvt file: %v", err) } diff --git a/encoding/mvt/unmarshal.go b/encoding/mvt/unmarshal.go index 7454850..7749419 100644 --- a/encoding/mvt/unmarshal.go +++ b/encoding/mvt/unmarshal.go @@ -5,7 +5,7 @@ import ( "compress/gzip" "errors" "fmt" - "io/ioutil" + "io" "github.com/paulmach/orb" "github.com/paulmach/orb/encoding/mvt/vectortile" @@ -23,7 +23,7 @@ func UnmarshalGzipped(data []byte) (Layers, error) { return nil, fmt.Errorf("failed to create gzreader: %v", err) } - decoded, err := ioutil.ReadAll(gzreader) + decoded, err := io.ReadAll(gzreader) if err != nil { return nil, fmt.Errorf("failed to unzip: %v", err) } diff --git a/encoding/wkb/wkb_test.go b/encoding/wkb/wkb_test.go index 460307d..44e41c7 100644 --- a/encoding/wkb/wkb_test.go +++ b/encoding/wkb/wkb_test.go @@ -3,7 +3,7 @@ package wkb import ( "bytes" "encoding/binary" - "io/ioutil" + "io" "testing" "github.com/paulmach/orb" @@ -27,7 +27,7 @@ func TestMustMarshal(t *testing.T) { func BenchmarkEncode_Point(b *testing.B) { g := orb.Point{1, 2} - e := NewEncoder(ioutil.Discard) + e := NewEncoder(io.Discard) b.ReportAllocs() b.ResetTimer() @@ -44,7 +44,7 @@ func BenchmarkEncode_LineString(b *testing.B) { {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, } - e := NewEncoder(ioutil.Discard) + e := NewEncoder(io.Discard) b.ReportAllocs() b.ResetTimer() diff --git a/encoding/wkt/benchmarks_test.go b/encoding/wkt/benchmarks_test.go index fd48ec0..07339ce 100644 --- a/encoding/wkt/benchmarks_test.go +++ b/encoding/wkt/benchmarks_test.go @@ -2,7 +2,7 @@ package wkt import ( "encoding/json" - "io/ioutil" + "os" "testing" "github.com/paulmach/orb" @@ -103,7 +103,7 @@ func BenchmarkUnmarshalMultiPolygon(b *testing.B) { } func loadJSON(tb testing.TB, filename string, obj interface{}) { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if err != nil { tb.Fatalf("failed to load mvt file: %v", err) } diff --git a/geo/area.go b/geo/area.go index 4cf5d17..f36f509 100644 --- a/geo/area.go +++ b/geo/area.go @@ -56,19 +56,20 @@ func ringArea(r orb.Ring) float64 { area := 0.0 for i := 0; i < l; i++ { - if i == l-3 { // i = N-3 + switch i { + case l - 3: // i = N-3 lo = l - 3 mi = l - 2 hi = 0 - } else if i == l-2 { // i = N-2 + case l - 2: // i = N-2 lo = l - 2 mi = 0 hi = 0 - } else if i == l-1 { // i = N-1 + case l - 1: // i = N-1 lo = 0 mi = 0 hi = 1 - } else { // i = 0 to N-3 + default: // i = 0 to N-3 lo = i mi = i + 1 hi = i + 2 diff --git a/geojson/feature_test.go b/geojson/feature_test.go index a976448..0fefc70 100644 --- a/geojson/feature_test.go +++ b/geojson/feature_test.go @@ -3,7 +3,7 @@ package geojson import ( "bytes" "encoding/json" - "io/ioutil" + "os" "reflect" "strings" "testing" @@ -424,7 +424,7 @@ func TestFeature_MarshalBSON_extraMembers(t *testing.T) { // } func BenchmarkFeatureMarshalJSON(b *testing.B) { - data, err := ioutil.ReadFile("../encoding/mvt/testdata/16-17896-24449.json") + data, err := os.ReadFile("../encoding/mvt/testdata/16-17896-24449.json") if err != nil { b.Fatalf("could not open file: %v", err) } @@ -446,7 +446,7 @@ func BenchmarkFeatureMarshalJSON(b *testing.B) { } func BenchmarkFeatureUnmarshalJSON(b *testing.B) { - data, err := ioutil.ReadFile("../encoding/mvt/testdata/16-17896-24449.json") + data, err := os.ReadFile("../encoding/mvt/testdata/16-17896-24449.json") if err != nil { b.Fatalf("could not open file: %v", err) } @@ -463,7 +463,7 @@ func BenchmarkFeatureUnmarshalJSON(b *testing.B) { } func BenchmarkFeatureMarshalBSON(b *testing.B) { - data, err := ioutil.ReadFile("../encoding/mvt/testdata/16-17896-24449.json") + data, err := os.ReadFile("../encoding/mvt/testdata/16-17896-24449.json") if err != nil { b.Fatalf("could not open file: %v", err) } @@ -485,7 +485,7 @@ func BenchmarkFeatureMarshalBSON(b *testing.B) { } func BenchmarkFeatureUnmarshalBSON(b *testing.B) { - data, err := ioutil.ReadFile("../encoding/mvt/testdata/16-17896-24449.json") + data, err := os.ReadFile("../encoding/mvt/testdata/16-17896-24449.json") if err != nil { b.Fatalf("could not open file: %v", err) } diff --git a/go.mod b/go.mod index 8f99949..186da82 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/paulmach/orb -go 1.15 +go 1.25 require ( github.com/gogo/protobuf v1.3.2 diff --git a/go.sum b/go.sum index d1a75cb..7dcd0ae 100644 --- a/go.sum +++ b/go.sum @@ -11,10 +11,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/paulmach/protoscan v0.2.1 h1:rM0FpcTjUMvPUNk2BhPJrreDKetq43ChnL+x1sRg8O8= @@ -68,13 +66,11 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/maptile/tile.go b/maptile/tile.go index 1e61bd3..2a4488b 100644 --- a/maptile/tile.go +++ b/maptile/tile.go @@ -228,9 +228,12 @@ func (t Tile) Children() Tiles { // ChildrenInZoomRange returns all the children tiles of tile from ranges [zoomStart, zoomEnd], both ends inclusive. func ChildrenInZoomRange(tile Tile, zoomStart, zoomEnd Zoom) Tiles { + //nolint:staticcheck // clearer this way if !(zoomStart <= zoomEnd) { panic("zoomStart must be <= zoomEnd") } + + //nolint:staticcheck // clearer this way if !(tile.Z <= zoomStart) { panic("tile.Z is must be <= zoomStart") } diff --git a/maptile/tilecover/cover_test.go b/maptile/tilecover/cover_test.go index ff33496..ae7a91a 100644 --- a/maptile/tilecover/cover_test.go +++ b/maptile/tilecover/cover_test.go @@ -2,8 +2,8 @@ package tilecover import ( "encoding/json" - "io/ioutil" "math" + "os" "sort" "strings" "testing" @@ -92,7 +92,7 @@ func TestTestdata(t *testing.T) { // ts := Geometry(f.Geometry, tc.max) // blob, _ := json.MarshalIndent(MergeUp(ts, tc.min).ToFeatureCollection(), "", " ") - // ioutil.WriteFile("./testdata/"+tc.name+"_out.geojson", blob, 0644) + // os.WriteFile("./testdata/"+tc.name+"_out.geojson", blob, 0644) expected := loadFeatureCollection(t, "./testdata/"+tc.name+"_out.geojson") @@ -108,7 +108,7 @@ func TestTestdata(t *testing.T) { } func TestCountries(t *testing.T) { - files, err := ioutil.ReadDir("./testdata/world") + files, err := os.ReadDir("./testdata/world") if err != nil { t.Errorf("could not read directory: %v", err) } @@ -182,7 +182,7 @@ func sortFC(fc *geojson.FeatureCollection) { func loadFeature(t testing.TB, path string) *geojson.Feature { t.Helper() - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { t.Fatalf("unable to read file: %v", err) } @@ -210,7 +210,7 @@ func loadFeature(t testing.TB, path string) *geojson.Feature { func loadFeatureCollection(t testing.TB, path string) *geojson.FeatureCollection { t.Helper() - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { t.Fatalf("unable to read file: %v", err) } @@ -250,7 +250,7 @@ func output(t testing.TB, name string, r *geojson.FeatureCollection) { t.Fatalf("error marshalling json: %v", err) } - err = ioutil.WriteFile("failure_"+name+".geojson", data, 0644) + err = os.WriteFile("failure_"+name+".geojson", data, 0644) if err != nil { t.Fatalf("write file failure: %v", err) } diff --git a/planar/contains.go b/planar/contains.go index fbfc455..1d5cc53 100644 --- a/planar/contains.go +++ b/planar/contains.go @@ -66,7 +66,8 @@ func rayIntersect(p, s, e orb.Point) (intersects, on bool) { s, e = e, s } - if p[0] == s[0] { + switch p[0] { + case s[0]: if p[1] == s[1] { // p == start return false, true @@ -84,7 +85,7 @@ func rayIntersect(p, s, e orb.Point) (intersects, on bool) { // Move the y coordinate to deal with degenerate case p[0] = math.Nextafter(p[0], math.Inf(1)) - } else if p[0] == e[0] { + case e[0]: if p[1] == e[1] { // matching the end point return false, true diff --git a/simplify/benchmarks_test.go b/simplify/benchmarks_test.go index 14d043f..cdff2fa 100644 --- a/simplify/benchmarks_test.go +++ b/simplify/benchmarks_test.go @@ -164,7 +164,11 @@ func benchmarkData() orb.LineString { if err != nil { panic(err) } - defer f.Close() + defer func() { + if err := f.Close(); err != nil { + panic(err) + } + }() var points []float64 err = json.NewDecoder(f).Decode(&points)