Skip to content

Commit

Permalink
Update golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Mar 4, 2024
1 parent 5101eba commit 2c780f9
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
env:
GOFUMPT_VERSION: 0.3.1
GOLANGCI_LINT_VERSION: 1.49.0
GOLANGCI_LINT_VERSION: 1.56.2
jobs:
linux:
runs-on: ubuntu-latest
Expand Down
52 changes: 48 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
linters:
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- depguard
- containedctx
- contextcheck
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errorlint
- execinquery
- exportloopref
- forbidigo
- forcetypeassert
- gci
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gochecksumtype
- gocritic
- godot
- goerr113
Expand All @@ -24,33 +34,58 @@ linters:
- goprintffuncname
- gosec
- gosimple
- gosmopolitan
- govet
- grouper
- importas
- inamedparam
- ineffassign
- interfacebloat
- ireturn
- loggercheck
- makezero
- mirror
- misspell
- musttag
- nakedret
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- perfsprint
- prealloc
- predeclared
- promlinter
- protogetter
- reassign
- revive
- rowserrcheck
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- stylecheck
- tagalign
- tagliatelle
- tenv
- testableexamples
- testifylint
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- whitespace
- zerologlint
disable:
- cyclop
- depguard
- errname # FIXME renaming ErrXxx to XxxError will require a major version bump
- exhaustive
- exhaustivestruct
- exhaustruct
- funlen
- gochecknoglobals
- gocognit
Expand All @@ -60,12 +95,15 @@ linters:
- goheader
- gomnd
- lll
- maintidx
- nestif
- nlreturn
- nonamedreturns
- paralleltest
- rowserrcheck # https://github.com/golangci/golangci-lint/issues/2649
- sqlclosecheck # https://github.com/golangci/golangci-lint/issues/2649
- paralleltest
- testpackage
- testpackage
- varnamelen
- wastedassign # https://github.com/golangci/golangci-lint/issues/2649
- wrapcheck
- wsl
Expand All @@ -78,6 +116,12 @@ linters-settings:
- prefix(github.com/twpayne/go-geom)
goimports:
local-prefixes: github.com/twpayne/go-geom
ireturn:
allow:
- error
- stdlib
- ^github\.com/twpayne/go-geom\.T$
- ^github\.com/twpayne/go-kml/v3\.Element$

issues:
exclude-rules:
Expand Down
18 changes: 9 additions & 9 deletions bigxy/big_cga.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
// relative round-off error in big.Float precision numbers
var dpSafeEpsilon = 1e-15

// OrientationIndex returns the index of the direction of the point point relative to
// a vector specified by vectorOrigin-vectorEnd
// OrientationIndex returns the index of the direction of point relative
// to a vector specified by vectorOrigin-vectorEnd
//
// vectorOrigin - the origin point of the vector
// vectorEnd - the final point of the vector
// point - the point to compute the direction to
// vectorOrigin - the origin point of the vector vectorEnd - the final point of
// the vector point - the point to compute the direction to
//
// Returns CounterClockwise if point is counter-clockwise (left) from vectorOrigin-vectorEnd
// Returns Clockwise if point is clockwise (right) from vectorOrigin-vectorEnd
// Returns Collinear if point is collinear with vectorOrigin-vectorEnd
// Returns CounterClockwise if point is counter-clockwise (left) from
// vectorOrigin-vectorEnd. Returns Clockwise if point is clockwise (right) from
// vectorOrigin-vectorEnd. Returns Collinear if point is collinear with
// vectorOrigin-vectorEnd.
func OrientationIndex(vectorOrigin, vectorEnd, point geom.Coord) orientation.Type {
// fast filter for orientation index
// avoids use of slow extended-precision arithmetic in many cases
Expand All @@ -52,7 +52,7 @@ func OrientationIndex(vectorOrigin, vectorEnd, point geom.Coord) orientation.Typ
}

// Intersection computes the intersection point of the two lines using math.big.Float arithmetic.
// The lines are considered infinate in length. For example, (0,0), (1, 0) and (2, 1) (2, 2) will have intersection of (2, 0)
// The lines are considered infinite in length. For example, (0,0), (1, 0) and (2, 1) (2, 2) will have intersection of (2, 0)
// Currently does not handle case of parallel lines.
func Intersection(line1Start, line1End, line2Start, line2End geom.Coord) geom.Coord {
var denom1, denom2, denom, tmp1, tmp2 big.Float
Expand Down
3 changes: 1 addition & 2 deletions encoding/ewkbhex/ewkbhex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ewkbhex

import (
"encoding/hex"
"fmt"
"testing"

"github.com/alecthomas/assert/v2"
Expand Down Expand Up @@ -215,7 +214,7 @@ func Test(t *testing.T) {
xdr: "0020000003000010e60000000100000005c05314cc94c5c52c40440619d4a35817c05314cbfce5c52c4044061ca33b581bc05314c9819fc5294044061b580f5817c05314ca197fc52b4044061891335816c05314cc94c5c52c40440619d4a35817",
},
} {
t.Run(fmt.Sprintf("ndr:%s", tc.ndr), func(t *testing.T) {
t.Run("ndr:"+tc.ndr, func(t *testing.T) {
test(t, tc.g, tc.xdr, tc.ndr)
})
}
Expand Down
8 changes: 4 additions & 4 deletions encoding/geojson/geojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (e ErrDimensionalityTooLow) Error() string {
type ErrUnsupportedType string

func (e ErrUnsupportedType) Error() string {
return fmt.Sprintf("geojson: unsupported type: %s", string(e))
return "geojson: unsupported type: " + string(e)
}

// CRS is a deprecated field but still populated in some programs (e.g. PostGIS).
Expand Down Expand Up @@ -313,7 +313,7 @@ func EncodeGeometryWithBBox() EncodeGeometryOption {
// EncodeGeometryWithCRS adds the crs field to the Geometry GeoJSON encoding.
func EncodeGeometryWithCRS(crs *CRS) EncodeGeometryOption {
return EncodeGeometryOption{
onGeometryHandler: func(g *Geometry, t geom.T, opts ...EncodeGeometryOption) error {
onGeometryHandler: func(g *Geometry, _ geom.T, _ ...EncodeGeometryOption) error {
var err error
g.CRS = crs
return err
Expand All @@ -332,7 +332,7 @@ func EncodeGeometryWithMaxDecimalDigits(maxDecimalDigits int) EncodeGeometryOpti
// Encode encodes g as a GeoJSON geometry.
func Encode(g geom.T, opts ...EncodeGeometryOption) (*Geometry, error) {
if g == nil {
return nil, nil
return nil, nil //nolint:nilnil
}
ret, err := encode(g, opts...)
if err != nil {
Expand All @@ -351,7 +351,7 @@ func Encode(g geom.T, opts ...EncodeGeometryOption) (*Geometry, error) {
// encode encodes the geometry assuming it is not nil.
func encode(g geom.T, opts ...EncodeGeometryOption) (*Geometry, error) {
if g == nil {
return nil, nil
return nil, nil //nolint:nilnil
}
switch g := g.(type) {
case *geom.Point:
Expand Down
2 changes: 1 addition & 1 deletion encoding/igc/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (p *parser) parseB(line string) error {
func (p *parser) parseH(line string) error {
m := hRegexp.FindStringSubmatch(line)
if m == nil {
return fmt.Errorf("invalid H record")
return errors.New("invalid H record")
}
header := Header{
Source: m[1],
Expand Down
1 change: 1 addition & 0 deletions encoding/wkb/sql_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func Example_value_different_shapes() {
}

for _, s := range shapes {
s := s
result, err := db.Exec(`INSERT INTO objects (name, location) VALUES (?, ?);`, s.Name, &s.Geom)
if err != nil {
log.Fatal(err)
Expand Down
3 changes: 2 additions & 1 deletion encoding/wkb/wkb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package wkb
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"

Expand Down Expand Up @@ -265,7 +266,7 @@ func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T, opts ...wkbcommon.
case wkbcommon.EmptyPointHandlingNaN:
return wkbcommon.WriteEmptyPointAsNaN(w, byteOrder, g.Stride())
case wkbcommon.EmptyPointHandlingError:
return fmt.Errorf("cannot encode empty Point in WKB")
return errors.New("cannot encode empty Point in WKB")
default:
return fmt.Errorf("cannot encode empty Point in WKB (unknown option: %d)", wkbcommon.EmptyPointHandlingNaN)
}
Expand Down
5 changes: 2 additions & 3 deletions encoding/wkbhex/wkbhex_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package wkbhex

import (
"fmt"
"testing"

"github.com/alecthomas/assert/v2"
Expand Down Expand Up @@ -154,7 +153,7 @@ func Test(t *testing.T) {
},
} {
if tc.ndr != "" {
t.Run(fmt.Sprintf("ndr:%s", tc.ndr), func(t *testing.T) {
t.Run("ndr:"+tc.ndr, func(t *testing.T) {
t.Run("encode", func(t *testing.T) {
got, err := Encode(tc.g, wkb.NDR, tc.opts...)
assert.NoError(t, err)
Expand All @@ -168,7 +167,7 @@ func Test(t *testing.T) {
})
}
if tc.xdr != "" {
t.Run(fmt.Sprintf("xdr:%s", tc.xdr), func(t *testing.T) {
t.Run("xdr:"+tc.xdr, func(t *testing.T) {
t.Run("encode", func(t *testing.T) {
got, err := Encode(tc.g, wkb.XDR, tc.opts...)
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion encoding/wkt/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (l *wktLex) nextScannedPointMustBeEmpty() bool {

// setLexError is called by Lex when a lexing (tokenizing) error is detected.
func (l *wktLex) setLexError(expectedTokType string) {
l.Error(fmt.Sprintf("invalid %s", expectedTokType))
l.Error("invalid " + expectedTokType)
}

// setParseError is called when a context-sensitive error is detected during parsing.
Expand Down
4 changes: 2 additions & 2 deletions encoding/wkt/lex_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ func (e *SyntaxError) Error() string {
snippet := e.wkt[snipStart:snipEnd]
snippet = strings.ReplaceAll(snippet, "\t", " ")
err += strLinePrefix + snippet + strLineSuffix
err += fmt.Sprintf("%s^", strings.Repeat(" ", len(strLinePrefix)+snipPos))
err += strings.Repeat(" ", len(strLinePrefix)+snipPos) + "^"

// Print a hint, if applicable.
if e.hint != "" {
err += fmt.Sprintf("\nHINT: %s", e.hint)
err += "\nHINT: " + e.hint
}

return err
Expand Down
10 changes: 5 additions & 5 deletions encoding/wkt/wkt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,12 @@ LINE 1: POINT Z M (1 1 1 1)
desc: "invalid geometry type split over multiple lines",
input: `POINT
Z
Z (
M (
0
0
)`,
expectedErrStr: `syntax error: invalid keyword at line 3, pos 7
LINE 3: Z (
LINE 3: M (
^`,
},
{
Expand All @@ -964,9 +964,9 @@ LINE 1: ..., 0 0, 0 0, 0 0, 0 0, 0 0, 0 0}
// ParseError
{
desc: "invalid point",
input: "POINT POINT",
expectedErrStr: `syntax error: unexpected POINT, expecting '(' at line 1, pos 6
LINE 1: POINT POINT
input: "POINT P",
expectedErrStr: `syntax error: invalid keyword at line 1, pos 6
LINE 1: POINT P
^`,
},
{
Expand Down
2 changes: 1 addition & 1 deletion linearring.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewLinearRingFlat(layout Layout, flatCoords []float64) *LinearRing {
return g
}

// Area returns the the area.
// Area returns the area.
func (g *LinearRing) Area() float64 {
return doubleArea1(g.flatCoords, 0, len(g.flatCoords), g.stride) / 2
}
Expand Down
7 changes: 4 additions & 3 deletions sorting/sorting.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package sorting

import "github.com/twpayne/go-geom"

// FlatCoord is a sort.Interface implementation that will result in sorting the wrapped coords based on the
// the comparator function
// FlatCoord is a sort.Interface implementation that will result in sorting the
// wrapped coords based on the comparator function
//
// Note: this data struct cannot be used with its 0 values. it must be constructed using NewFlatCoordSorting
// Note: this data struct cannot be used with its 0 values. it must be
// constructed using NewFlatCoordSorting
type FlatCoord struct {
isLess IsLess
coords []float64
Expand Down
6 changes: 3 additions & 3 deletions xy/internal/hcoords/hcoords.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hcoords

import (
"fmt"
"errors"
"math"

"github.com/twpayne/go-geom"
Expand Down Expand Up @@ -31,11 +31,11 @@ func GetIntersection(line1End1, line1End2, line2End1, line2End2 geom.Coord) (geo
yIntersection := y / w

if math.IsNaN(xIntersection) || math.IsNaN(yIntersection) {
return nil, fmt.Errorf("intersection cannot be calculated using the h-coords implementation")
return nil, errors.New("intersection cannot be calculated using the h-coords implementation")
}

if math.IsInf(xIntersection, 0) || math.IsInf(yIntersection, 0) {
return nil, fmt.Errorf("intersection cannot be calculated using the h-coords implementation")
return nil, errors.New("intersection cannot be calculated using the h-coords implementation")
}

return geom.Coord{xIntersection, yIntersection}, nil
Expand Down
6 changes: 2 additions & 4 deletions xy/internal/robustdeterminate/robust_determinate.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func SignOfDet2x2(x1, y1, x2, y2 float64) Sign {
*/
if 0.0 < y1 {
if 0.0 < y2 {
if y1 <= y2 {
} else {
if y1 > y2 {
sign = Negative
swap = x1
x1 = x2
Expand Down Expand Up @@ -145,8 +144,7 @@ func SignOfDet2x2(x1, y1, x2, y2 float64) Sign {
*/
if 0.0 < x1 {
if 0.0 < x2 {
if x1 <= x2 {
} else {
if x1 > x2 {
return sign
}
} else {
Expand Down
Loading

0 comments on commit 2c780f9

Please sign in to comment.