Skip to content

Commit

Permalink
Enable more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstace committed Oct 12, 2023
1 parent 9c7e8e0 commit b8e8b68
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
47 changes: 24 additions & 23 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ linters:
- varcheck

- cyclop # Due to the nature of simplefeatures, cyclomatic complexity is going to be high.
- maintidx # Due to the nature of simplefeatures, cyclomatic complexity is going to be high.
- exhaustive # Switches on geometry type are often purposefully non-exhaustive.
- exhaustruct # Too opinionated.
- forbidigo # Overly prescriptive.
Expand All @@ -54,31 +55,28 @@ linters:
- nonamedreturns # Too opinionated.
- paralleltest # Most tests are CPU bound, so parallel tests don't make sense.
- prealloc # Too many false positives.
- dupl # Too opinionated.
- errname # Too opinionated.
- forcetypeassert # Too opinionated.
- gochecknoglobals # Too opinionated.
- goconst # Too opinionated.
- gochecknoinits # Too opinionated.
- gomnd # Too opinionated.
- gocognit # Too opinionated.
- varnamelen # Too opinionated.
- nlreturn # Too opinionated.
- goerr113 # Too opinionated.
#- wsl # Too opinionated.
- wrapcheck # Too opinionated.

# Disabled because they're currently not passing cleanly.
- dupl
- errcheck
- errname
- errorlint
- forcetypeassert
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- goerr113
- gomnd
- maintidx
- nlreturn
- nolintlint
- predeclared
- errorlint # Too much work to fix issues (maybe later).
- stylecheck # Too much work to fix issues (maybe later).
- testpackage # Too much work to fix issues (maybe later).
- errcheck # Too much work to fix issues (maybe later).
- unparam # Too much work to fix issues (maybe later).

# TODO: when I enable this, it ends up enabling wsl???
- revive
- stylecheck
- testpackage
- unconvert
- unparam
- varnamelen
- wrapcheck
- wsl

enable:
- asasalint
Expand Down Expand Up @@ -124,7 +122,9 @@ linters:
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- predeclared
- promlinter
- reassign
- rowserrcheck
Expand All @@ -136,6 +136,7 @@ linters:
- testableexamples
- thelper
- tparallel
- unconvert
- unused
- usestdlibvars
- wastedassign
Expand Down
2 changes: 1 addition & 1 deletion geom/twkb_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func (p *twkbParser) parsePointCountAndArray() ([]float64, int, error) {
// Utilise and update the running memory of the previous reference point.
// The returned array will contain numPoints * the number of dimensions values.
func (p *twkbParser) parsePointArray(numPoints int) ([]float64, error) {
coords := make([]float64, numPoints*int(p.dimensions))
coords := make([]float64, numPoints*p.dimensions)
c := 0
for i := 0; i < numPoints; i++ {
for d := 0; d < p.dimensions; d++ {
Expand Down
1 change: 0 additions & 1 deletion geom/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func expectTrue(tb testing.TB, got bool) {
expectBoolEq(tb, got, true)
}

//nolint:deadcode,unused
func expectFalse(tb testing.TB, got bool) {
tb.Helper()
expectBoolEq(tb, got, false)
Expand Down
2 changes: 1 addition & 1 deletion geom/xy.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (w XY) Cross(o XY) float64 {
// Avoid fused multiply-add by explicitly converting intermediate products
// to float64. This ensures that the cross product is *exactly* zero for
// all linearly dependent inputs.
return float64(w.X*o.Y) - float64(w.Y*o.X)
return float64(w.X*o.Y) - float64(w.Y*o.X) //nolint:unconvert
}

// Midpoint returns the midpoint of this and another XY.
Expand Down
18 changes: 9 additions & 9 deletions internal/cmprefimpl/cmppg/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
)

func checkWKTParse(t *testing.T, pg PostGIS, candidates []string) {
var any bool
var found bool
for i, wkt := range candidates {
any = true
found = true
t.Run(fmt.Sprintf("CheckWKTParse_%d", i), func(t *testing.T) {
// The simple feature library accepts LINEARRING WKTs. However,
// postgis doesn't accept them. A workaround for this is to just
Expand All @@ -36,21 +36,21 @@ func checkWKTParse(t *testing.T, pg PostGIS, candidates []string) {
}
})
}
if !any {
if !found {
// We know there are some valid WKT strings, so if this happens then
// something is wrong with the extraction or conversion logic.
t.Errorf("could not extract any WKTs")
}
}

func checkWKBParse(t *testing.T, pg PostGIS, candidates []string) {
var any bool
var found bool
for i, wkb := range candidates {
buf, err := hexStringToBytes(wkb)
if err != nil {
continue
}
any = true
found = true
t.Run(fmt.Sprintf("CheckWKBParse_%d", i), func(t *testing.T) {
if len(wkb) >= 10 {
if strings.HasPrefix(wkb, "0108000000") {
Expand All @@ -72,7 +72,7 @@ func checkWKBParse(t *testing.T, pg PostGIS, candidates []string) {
}
})
}
if !any {
if !found {
// We know there are some valid hex strings, so if this happens then
// something is wrong with the extraction or conversion logic.
t.Errorf("could not extract any WKBs")
Expand All @@ -95,7 +95,7 @@ func hexStringToBytes(s string) ([]byte, error) {
}

func checkGeoJSONParse(t *testing.T, pg PostGIS, candidates []string) {
var any bool
var found bool
for i, geojson := range candidates {
if geojson == `{"type":"Point","coordinates":[]}` {
// From https://tools.ietf.org/html/rfc7946#section-3.1:
Expand All @@ -121,7 +121,7 @@ func checkGeoJSONParse(t *testing.T, pg PostGIS, candidates []string) {
// PostGIS erroneously accepts MultiPoints with empty positions.
continue
}
any = true
found = true
t.Run(fmt.Sprintf("CheckGeoJSONParse_%d", i), func(t *testing.T) {
_, sfErr := geom.UnmarshalGeoJSON([]byte(geojson))
isValid, reason := pg.GeoJSONIsValidWithReason(t, geojson)
Expand All @@ -134,7 +134,7 @@ func checkGeoJSONParse(t *testing.T, pg PostGIS, candidates []string) {
}
})
}
if !any {
if !found {
// We know there are some valid geojson strings, so if this happens
// then something is wrong with the extraction or conversion logic.
t.Errorf("could not extract any geojsons")
Expand Down

0 comments on commit b8e8b68

Please sign in to comment.