diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 776b697..27ed0b2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,11 +12,11 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a - - uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 + - uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 with: - version: v1.62.2 + version: v2.8.0 test: strategy: matrix: @@ -25,8 +25,8 @@ jobs: - oldstable runs-on: ubuntu-latest steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 with: go-version: ${{ matrix.go-version }} - name: build diff --git a/.golangci.yml b/.golangci.yml index fefe36d..9135bf8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,156 +1,173 @@ +version: "2" run: - go: '1.23' - + go: "1.24" linters: enable: - - asasalint - - asciicheck - - bidichk - - bodyclose - - canonicalheader - - containedctx - - contextcheck - - copyloopvar - - decorder - - dogsled - - dupl - - dupword - - durationcheck - - err113 - - errcheck - - errchkjson - - errname - - errorlint - - fatcontext - - forbidigo - - forcetypeassert - - gci - - ginkgolinter - - gocheckcompilerdirectives - - gochecknoinits - - gochecksumtype - - goconst - - gocritic - - godot - - gofmt - - gofumpt - - goheader - - goimports - - gomoddirectives - - gomodguard - - goprintffuncname - - gosec - - gosimple - - gosmopolitan - - govet - - grouper - - iface - - importas - - inamedparam - - ineffassign - - interfacebloat - - intrange - - ireturn - - lll - - loggercheck - - makezero - - mirror - - misspell - - musttag - - nilerr - - noctx - - nolintlint - - nosprintfhostport - - perfsprint - - prealloc - - predeclared - - promlinter - - protogetter - - reassign - - recvcheck - - revive - - rowserrcheck - - sloglint - - spancheck - - sqlclosecheck - - staticcheck - - stylecheck - - tagalign - - tagliatelle - - tenv - - testableexamples - - testifylint - - thelper - - typecheck - - unconvert - - unparam - - unused - - usestdlibvars - - wastedassign - - whitespace - - zerologlint - disable: - - cyclop - - depguard - - exhaustive - - exhaustruct - - funlen - - gochecknoglobals - - gocognit - - gocyclo - - godox - - maintidx - - nakedret - - nestif - - nilnil - - nlreturn - - nonamedreturns - - paralleltest - - testpackage - - tparallel - - varnamelen - - wrapcheck - - wsl - -linters-settings: - forbidigo: - forbid: - - ^fmt\.Print.*$ - - ^ioutil\..*$ - - ^os\.(DirEntry|FileInfo|FileMode|Is.*|Mode.*)$ - gci: - sections: - - standard - - default - - prefix(github.com/twpayne/go-shapefile) - gofumpt: - extra-rules: true - module-path: github.com/twpayne/go-shapefile - goimports: - local-prefixes: github.com/twpayne/go-shapefile - gosec: - excludes: - - G115 - ireturn: - allow: - - empty - - error - - github\.com/twpayne/go-geom\.T - - stdlib - misspell: - locale: US - stylecheck: - checks: - - all - -issues: - include: - - EXC0011 # include issues about comments from `stylecheck` - exclude-rules: - - linters: + - arangolint + - asasalint + - asciicheck + - bidichk + - bodyclose + - canonicalheader + - containedctx + - contextcheck + - copyloopvar + - decorder + - dogsled + - dupl + - dupword + - durationcheck + - embeddedstructfieldcheck - err113 - text: do not define dynamic errors, use wrapped static errors instead - - linters: + - errchkjson + - errname + - errorlint + - exptostd + - fatcontext + - forbidigo + - forcetypeassert + - funcorder + - ginkgolinter + - gocheckcompilerdirectives + - gochecknoinits + - gochecksumtype + - goconst + - gocritic + - godot + - goheader + - gomoddirectives + - gomodguard + - goprintffuncname - gosec + - gosmopolitan + - grouper + - iface + - importas + - inamedparam + - interfacebloat + - intrange + - iotamixing + - ireturn - lll - path: _test\.go$ + - loggercheck + - makezero + - mirror + - misspell + - modernize + - musttag + - nilerr + - nilnesserr + - nilnil + - noctx + - nolintlint + - nosprintfhostport + - perfsprint + - prealloc + - predeclared + - promlinter + - protogetter + - reassign + - recvcheck + - rowserrcheck + - sloglint + - spancheck + - sqlclosecheck + - staticcheck + - tagalign + - tagliatelle + - testableexamples + - testifylint + - thelper + - unconvert + - unparam + - unqueryvet + - usestdlibvars + - usetesting + - wastedassign + - whitespace + - zerologlint + disable: + - cyclop + - depguard + - exhaustive + - exhaustruct + - funlen + - gochecknoglobals + - gocognit + - gocyclo + - godox + - maintidx + - nakedret + - nestif + - nilnil + - nlreturn + - nonamedreturns + - paralleltest + - revive + - testpackage + - tparallel + - varnamelen + - wrapcheck + - wsl + settings: + forbidigo: + forbid: + - pattern: ^fmt\.Print.*$ + - pattern: ^ioutil\..*$ + - pattern: ^os\.(DirEntry|FileInfo|FileMode|Is.*|Mode.*)$ + gosec: + excludes: + - G115 + ireturn: + allow: + - empty + - error + - github\.com/twpayne/go-geom\.T + - stdlib + misspell: + locale: US + staticcheck: + checks: + - all + exclusions: + generated: lax + presets: + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - err113 + text: do not define dynamic errors, use wrapped static errors instead + - linters: + - gosec + - lll + path: _test\.go$ + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + settings: + gci: + sections: + - standard + - default + - prefix(github.com/twpayne/go-shapefile) + gofumpt: + module-path: github.com/twpayne/go-shapefile + extra-rules: true + goimports: + local-prefixes: + - github.com/twpayne/go-shapefile + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/dbf.go b/dbf.go index 283ffcd..143be4e 100644 --- a/dbf.go +++ b/dbf.go @@ -77,6 +77,7 @@ type DBFFieldDescriptor struct { // See https://www.clicketyclick.dk/databases/xbase/format/dbf.html. type DBF struct { DBFHeader + FieldDescriptors []*DBFFieldDescriptor Records [][]any } @@ -190,7 +191,7 @@ func ReadDBF(r io.Reader, _ int64, options *ReadDBFOptions) (*DBF, error) { // Ignore missing end of file marker. case err != nil: return nil, err - case data[0] != '\x1a': + case len(data) == 0 || data[0] != '\x1a': return nil, fmt.Errorf("%d: invalid end of file marker", data[0]) } diff --git a/go.mod b/go.mod index 6c1a300..1757613 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module github.com/twpayne/go-shapefile -go 1.23 +go 1.24.0 require ( github.com/alecthomas/assert/v2 v2.10.0 - github.com/twpayne/go-geom v1.5.7 - golang.org/x/net v0.33.0 - golang.org/x/text v0.21.0 + github.com/twpayne/go-geom v1.6.1 + golang.org/x/net v0.49.0 + golang.org/x/text v0.33.0 ) require ( diff --git a/go.sum b/go.sum index 6c0e4b6..ce57cbf 100644 --- a/go.sum +++ b/go.sum @@ -4,9 +4,9 @@ github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= -github.com/twpayne/go-geom v1.5.7 h1:7fdceDUr03/MP7rAKOaTV6x9njMiQdxB/D0PDzMTCDc= -github.com/twpayne/go-geom v1.5.7/go.mod h1:y4fTAQtLedXW8eG2Yo4tYrIGN1yIwwKkmA+K3iSHKBA= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +github.com/twpayne/go-geom v1.6.1 h1:iLE+Opv0Ihm/ABIcvQFGIiFBXd76oBIar9drAwHFhR4= +github.com/twpayne/go-geom v1.6.1/go.mod h1:Kr+Nly6BswFsKM5sd31YaoWS5PeDDH2NftJTK7Gd028= +golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= +golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= +golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= +golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= diff --git a/scanner_test.go b/scanner_test.go index 6350ee0..dd68167 100644 --- a/scanner_test.go +++ b/scanner_test.go @@ -152,8 +152,8 @@ func TestReadScanner(t *testing.T) { assert.NoError(t, err) assert.NotZero(t, shapefile) - assert.Equal(t, tc.expectedShapeType, shapefile.SHP.SHxHeader.ShapeType) - assert.Equal(t, tc.expectedBounds, shapefile.SHP.SHxHeader.Bounds) + assert.Equal(t, tc.expectedShapeType, shapefile.SHP.ShapeType) + assert.Equal(t, tc.expectedBounds, shapefile.SHP.Bounds) assert.Equal(t, tc.expectedRecordsLen, shapefile.NumRecords()) assert.Equal(t, tc.expectedGeom0, shapefile.SHP.Records[0].Geom) @@ -176,8 +176,8 @@ func TestReadScanner(t *testing.T) { } if tc.hasSHX { - assert.Equal(t, tc.expectedShapeType, shapefile.SHP.SHxHeader.ShapeType) - assert.Equal(t, tc.expectedBounds, shapefile.SHP.SHxHeader.Bounds) + assert.Equal(t, tc.expectedShapeType, shapefile.SHP.ShapeType) + assert.Equal(t, tc.expectedBounds, shapefile.SHP.Bounds) assert.Equal(t, shapefile.NumRecords(), tc.expectedRecordsLen) } }) @@ -376,8 +376,8 @@ func TestReadScannerFSAndZipFile(t *testing.T) { t.Run(tc.filename, func(t *testing.T) { testShapefile := func(t *testing.T, shapefile *Shapefile) { t.Helper() - assert.Equal(t, tc.expectedShapeType, shapefile.SHP.SHxHeader.ShapeType) - assert.Equal(t, tc.expectedBounds, shapefile.SHP.SHxHeader.Bounds) + assert.Equal(t, tc.expectedShapeType, shapefile.SHP.ShapeType) + assert.Equal(t, tc.expectedBounds, shapefile.SHP.Bounds) assert.Equal(t, shapefile.NumRecords(), tc.expectedRecordsLen) if tc.expectedDBFRecord0Fields != nil { diff --git a/shp.go b/shp.go index 34579eb..07681fb 100644 --- a/shp.go +++ b/shp.go @@ -32,6 +32,7 @@ type ReadSHPOptions struct { // A SHP is a .shp file. type SHP struct { SHxHeader + Records []*SHPRecord } diff --git a/shx.go b/shx.go index 54a42dd..13aa90d 100644 --- a/shx.go +++ b/shx.go @@ -10,6 +10,7 @@ import ( // An SHX is a .shx file. type SHX struct { SHxHeader + Records []SHXRecord } diff --git a/util.go b/util.go index ed5a943..5bf9fcc 100644 --- a/util.go +++ b/util.go @@ -7,8 +7,7 @@ import ( func isMacOSXPath(p string) bool { dir, _ := filepath.Split(p) - pathElements := strings.Split(dir, string(filepath.Separator)) - for _, elem := range pathElements { + for elem := range strings.SplitSeq(dir, string(filepath.Separator)) { if elem == "__MACOSX" { return true }