diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index 5fd2a460..00000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: golangci-lint -on: - pull_request: -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: golangci-lint - uses: golangci/golangci-lint-action@v2.5.2 - with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v1.44.2 - only-new-issues: true - args: --timeout=5m diff --git a/.github/workflows/staticcheck.yml b/.github/workflows/staticcheck.yml new file mode 100644 index 00000000..d8a17e11 --- /dev/null +++ b/.github/workflows/staticcheck.yml @@ -0,0 +1,18 @@ +name: Staticcheck +on: + pull_request: + branches: [master] + +jobs: + ci: + name: lint + runs-on: ubuntu-latest + env: + GO111MODULE: on + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - uses: dominikh/staticcheck-action@v1.2.0 + with: + version: "2022.1" diff --git a/blas/testblas/benchautogen/autogen_bench_level1double.go b/blas/testblas/benchautogen/autogen_bench_level1double.go index 846005de..b216bf0b 100644 --- a/blas/testblas/benchautogen/autogen_bench_level1double.go +++ b/blas/testblas/benchautogen/autogen_bench_level1double.go @@ -292,14 +292,14 @@ type errFile struct { err error } -func (f errFile) Write(b []byte) { +func (f *errFile) Write(b []byte) { if f.err != nil { return } _, f.err = f.file.Write(b) } -func (f errFile) WriteString(s string) { +func (f *errFile) WriteString(s string) { if f.err != nil { return } diff --git a/graph/formats/rdf/check.go b/graph/formats/rdf/check.go index aabc28c6..f42e19a2 100644 --- a/graph/formats/rdf/check.go +++ b/graph/formats/rdf/check.go @@ -1,6 +1,6 @@ //line check.rl:1 -// Go code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. +// Code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. // Copyright ©2020 The Gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/graph/formats/rdf/check.rl b/graph/formats/rdf/check.rl index 966d78cb..57010620 100644 --- a/graph/formats/rdf/check.rl +++ b/graph/formats/rdf/check.rl @@ -1,4 +1,4 @@ -// Go code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. +// Code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. // Copyright ©2020 The Gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/graph/formats/rdf/extract.go b/graph/formats/rdf/extract.go index b93e6dec..418b4e91 100644 --- a/graph/formats/rdf/extract.go +++ b/graph/formats/rdf/extract.go @@ -1,6 +1,6 @@ //line extract.rl:1 -// Go code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. +// Code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. // Copyright ©2020 The Gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/graph/formats/rdf/extract.rl b/graph/formats/rdf/extract.rl index d43e1363..b36d1a21 100644 --- a/graph/formats/rdf/extract.rl +++ b/graph/formats/rdf/extract.rl @@ -1,4 +1,4 @@ -// Go code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. +// Code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. // Copyright ©2020 The Gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/graph/formats/rdf/iso_canonical.go b/graph/formats/rdf/iso_canonical.go index f80da64a..7a133849 100644 --- a/graph/formats/rdf/iso_canonical.go +++ b/graph/formats/rdf/iso_canonical.go @@ -282,11 +282,11 @@ func hashBNodes(statements []*Statement, h hash.Hash, zero []byte, hash0 map[str } case isIRI(t): h.Reset() - h.Write([]byte(t[1 : len(t)-1])) //nolint:errcheck + h.Write([]byte(t[1 : len(t)-1])) curr.set(t, h.Sum(nil)) default: h.Reset() - h.Write([]byte(t)) //nolint:errcheck + h.Write([]byte(t)) curr.set(t, h.Sum(nil)) } } @@ -515,7 +515,7 @@ func (b lexical) Swap(i, j int) { b[i], b[j] = b[j], b[i] } func hashTuple(h hash.Hash, t ...[]byte) []byte { h.Reset() for _, b := range t { - h.Write(b) //nolint:errcheck + h.Write(b) } return h.Sum(nil) } diff --git a/graph/formats/rdf/iso_canonical_test.go b/graph/formats/rdf/iso_canonical_test.go index 74b94b13..91c184f9 100644 --- a/graph/formats/rdf/iso_canonical_test.go +++ b/graph/formats/rdf/iso_canonical_test.go @@ -312,7 +312,7 @@ func hashBlanks(s []*Statement, h hash.Hash) ([]*Statement, map[string]string) { continue } h.Reset() - h.Write([]byte(t)) //nolint:errcheck + h.Write([]byte(t)) terms[t] = fmt.Sprintf("_:%0*x", 2*h.Size(), h.Sum(nil)) } } @@ -334,7 +334,7 @@ func mangleFirstIL(s []*Statement, h hash.Hash) ([]*Statement, map[string]string continue } h.Reset() - h.Write([]byte(t)) //nolint:errcheck + h.Write([]byte(t)) terms[t] = fmt.Sprintf(`"%0*x"`, 2*h.Size(), h.Sum(nil)) return relabelStatements(s, terms), terms } diff --git a/graph/formats/rdf/parse.go b/graph/formats/rdf/parse.go index 4c86d276..66f06bb2 100644 --- a/graph/formats/rdf/parse.go +++ b/graph/formats/rdf/parse.go @@ -1,6 +1,6 @@ //line parse.rl:1 -// Go code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. +// Code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. // Copyright ©2020 The Gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/graph/formats/rdf/parse.rl b/graph/formats/rdf/parse.rl index 7b3f77ef..5684d0ac 100644 --- a/graph/formats/rdf/parse.rl +++ b/graph/formats/rdf/parse.rl @@ -1,4 +1,4 @@ -// Go code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. +// Code generated by go generate gonum.org/v1/gonum/graph/formats/rdf; DO NOT EDIT. // Copyright ©2020 The Gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/graph/formats/rdf/urna.go b/graph/formats/rdf/urna.go index eee42711..311ef993 100644 --- a/graph/formats/rdf/urna.go +++ b/graph/formats/rdf/urna.go @@ -368,7 +368,7 @@ func (u *urna) hashNDegreeQuads(b string, names *issuer) ([]byte, *issuer) { // 5.5 final = append(final, chosenPath...) u.hash.Reset() - u.hash.Write(final) //nolint:errcheck + u.hash.Write(final) names = chosenIssuer // 5.6 } @@ -468,23 +468,23 @@ func (u *urna) hashRelatedBlank(term string, s *Statement, names *issuer, pos by // 2. u.hash.Reset() - u.hash.Write([]byte{pos}) //nolint:errcheck + u.hash.Write([]byte{pos}) if pos != 'g' { // 3. if u.label == "" { // URDNA2015: Term.Value retained the angle quotes // so we don't need to add them. - u.hash.Write([]byte(s.Predicate.Value)) //nolint:errcheck + u.hash.Write([]byte(s.Predicate.Value)) } else { // URGNA2012 does not delimit predicate by < and >. // https://json-ld.github.io/rdf-dataset-canonicalization/spec/index.html#urgna2012 // with reference to 4.7. - u.hash.Write([]byte(unquoteIRI(s.Predicate.Value))) //nolint:errcheck + u.hash.Write([]byte(unquoteIRI(s.Predicate.Value))) } } // 4. and 5. - u.hash.Write([]byte(b)) //nolint:errcheck + u.hash.Write([]byte(b)) return hex(u.hash.Sum(nil)) } diff --git a/graph/internal/set/set_test.go b/graph/internal/set/set_test.go index 9b4fdd5c..465d0b2e 100644 --- a/graph/internal/set/set_test.go +++ b/graph/internal/set/set_test.go @@ -46,10 +46,6 @@ func TestSameInt64s(t *testing.T) { func TestAddInt64s(t *testing.T) { s := make(Int64s) - if s == nil { - t.Fatal("Set cannot be created successfully") - } - if s.Count() != 0 { t.Error("Set somehow contains new elements upon creation") } @@ -183,10 +179,6 @@ func TestSameInts(t *testing.T) { func TestAddInts(t *testing.T) { s := make(Ints) - if s == nil { - t.Fatal("Set cannot be created successfully") - } - if s.Count() != 0 { t.Error("Set somehow contains new elements upon creation") } diff --git a/graph/iterator/map.go b/graph/iterator/map.go index 1ad91647..c2d92297 100644 --- a/graph/iterator/map.go +++ b/graph/iterator/map.go @@ -31,6 +31,7 @@ type emptyInterface struct { // Having a clone here allows us to embed a map iterator // inside type mapIter so that mapIters can be re-used // without doing any allocations. +//lint:ignore U1000 This is a verbatim copy of the runtime type. type hiter struct { key unsafe.Pointer elem unsafe.Pointer diff --git a/internal/asm/f64/axpy_test.go b/internal/asm/f64/axpy_test.go index 2483b8d0..7666e6c8 100644 --- a/internal/asm/f64/axpy_test.go +++ b/internal/asm/f64/axpy_test.go @@ -245,7 +245,7 @@ func TestAxpyIncTo(t *testing.T) { if inc.x*inc.y < 0 { want = test.wantRev } - var iW, incW int = 0, 1 + iW, incW := 0, 1 if inc.y*inc.dst < 0 { iW, incW = len(want)-1, -1 } diff --git a/internal/asm/f64/stubs_test.go b/internal/asm/f64/stubs_test.go index e79a56b5..89b30aa7 100644 --- a/internal/asm/f64/stubs_test.go +++ b/internal/asm/f64/stubs_test.go @@ -453,7 +453,7 @@ func TestDivTo(t *testing.T) { } func TestL1Dist(t *testing.T) { - var t_gd, s_gd float64 = -inf, inf + t_gd, s_gd := -inf, inf for j, v := range []struct { s, t []float64 expect float64 diff --git a/internal/asm/staticcheck.conf b/internal/asm/staticcheck.conf new file mode 100644 index 00000000..b6df475d --- /dev/null +++ b/internal/asm/staticcheck.conf @@ -0,0 +1 @@ +checks = ["inherit", "-U1000"] diff --git a/internal/cmplx64/cmath_test.go b/internal/cmplx64/cmath_test.go index a4178b1a..688bbeb8 100644 --- a/internal/cmplx64/cmath_test.go +++ b/internal/cmplx64/cmath_test.go @@ -17,6 +17,7 @@ import ( // The higher-precision values in vc26 were used to derive the // input arguments vc (see also comment below). For reference // only (do not delete). +//lint:ignore U1000 See comment above. var vc26 = []complex64{ (4.97901192488367350108546816 + 7.73887247457810456552351752i), (7.73887247457810456552351752 - 0.27688005719200159404635997i), diff --git a/lapack/testlapack/dgeev_bench.go b/lapack/testlapack/dgeev_bench.go index 0472ef35..1887d70b 100644 --- a/lapack/testlapack/dgeev_bench.go +++ b/lapack/testlapack/dgeev_bench.go @@ -13,9 +13,8 @@ import ( "gonum.org/v1/gonum/lapack" ) -var resultGeneral blas64.General - func DgeevBenchmark(b *testing.B, impl Dgeever) { + var resultGeneral blas64.General rnd := rand.New(rand.NewSource(1)) benchmarks := []struct { name string @@ -59,4 +58,7 @@ func DgeevBenchmark(b *testing.B, impl Dgeever) { resultGeneral = a }) } + if resultGeneral.Data == nil { + b.Error("unexpected nil data") + } } diff --git a/lapack/testlapack/dlangb_bench.go b/lapack/testlapack/dlangb_bench.go index 7e240892..d77363f5 100644 --- a/lapack/testlapack/dlangb_bench.go +++ b/lapack/testlapack/dlangb_bench.go @@ -6,6 +6,7 @@ package testlapack import ( "fmt" + "math" "testing" "golang.org/x/exp/rand" @@ -14,6 +15,7 @@ import ( ) func DlangbBenchmark(b *testing.B, impl Dlangber) { + var result float64 rnd := rand.New(rand.NewSource(1)) for _, bm := range []struct { n, k int @@ -83,4 +85,7 @@ func DlangbBenchmark(b *testing.B, impl Dlangber) { }) } } + if math.IsNaN(result) { + b.Error("unexpected NaN result") + } } diff --git a/lapack/testlapack/dlantb_bench.go b/lapack/testlapack/dlantb_bench.go index cfc46cc3..b05f81ab 100644 --- a/lapack/testlapack/dlantb_bench.go +++ b/lapack/testlapack/dlantb_bench.go @@ -6,6 +6,7 @@ package testlapack import ( "fmt" + "math" "testing" "golang.org/x/exp/rand" @@ -14,9 +15,8 @@ import ( "gonum.org/v1/gonum/lapack" ) -var result float64 - func DlantbBenchmark(b *testing.B, impl Dlantber) { + var result float64 rnd := rand.New(rand.NewSource(1)) for _, bm := range []struct { n, k int @@ -51,4 +51,7 @@ func DlantbBenchmark(b *testing.B, impl Dlantber) { } } } + if math.IsNaN(result) { + b.Error("unexpected NaN result") + } } diff --git a/lapack/testlapack/fortran.go b/lapack/testlapack/fortran.go index 0d5f653b..f7ae4d38 100644 --- a/lapack/testlapack/fortran.go +++ b/lapack/testlapack/fortran.go @@ -11,9 +11,11 @@ import ( // This file implements types for helping to convert to Fortran testing capabilities. +//lint:file-ignore U1000 A number of functions are here that may be used in future. + // fortran64 is a float64 type that prints as a double precision constant in // Fortran format. -type fortran64 float64 //nolint:unused +type fortran64 float64 func (f fortran64) String() string { // Replace exponent with D @@ -24,7 +26,6 @@ func (f fortran64) String() string { // printFortranArray prints a Go slice as an array that can be copied into a // fortran script. -//nolint:deadcode,unused func printFortranArray(z []float64, name string) { fmt.Printf("%s(1:%d) = (/%v, &\n", name, len(z), fortran64(z[0])) for i := 1; i < len(z)-1; i++ { diff --git a/lapack/testlapack/general.go b/lapack/testlapack/general.go index e17e9cae..1e2ae0ea 100644 --- a/lapack/testlapack/general.go +++ b/lapack/testlapack/general.go @@ -917,7 +917,7 @@ func constructQPBidiagonal(vect lapack.ApplyOrtho, m, n, nb int, a []float64, ld // printRowise prints the matrix with one row per line. This is useful for debugging. // If beyond is true, it prints beyond the final column to lda. If false, only // the columns are printed. -//nolint:deadcode,unused +//lint:ignore U1000 This is useful for debugging. func printRowise(a []float64, m, n, lda int, beyond bool) { for i := 0; i < m; i++ { end := n @@ -1113,6 +1113,7 @@ func isSchurCanonicalGeneral(t blas64.General) bool { // schurBlockEigenvalues returns the two eigenvalues of the 2×2 matrix [a b; c d] // that must be in Schur canonical form. +//lint:ignore U1000 This is useful for debugging. func schurBlockEigenvalues(a, b, c, d float64) (ev1, ev2 complex128) { if !isSchurCanonical(a, b, c, d) { panic("block not in Schur canonical form") diff --git a/mat/cholesky_test.go b/mat/cholesky_test.go index d535d5e8..de10a4bb 100644 --- a/mat/cholesky_test.go +++ b/mat/cholesky_test.go @@ -460,7 +460,7 @@ func TestCholeskySymRankOne(t *testing.T) { 0, 0, 6, 10, 0, 0, 0, 20, }), - alpha: -1 / 2, + alpha: -0.5, x: []float64{0, 0, 0, 1}, wantOk: true, }, diff --git a/mat/index_no_bound_checks.go b/mat/index_no_bound_checks.go index df8594e3..33512880 100644 --- a/mat/index_no_bound_checks.go +++ b/mat/index_no_bound_checks.go @@ -319,15 +319,6 @@ func (t *TriBandDense) SetTriBand(i, j int, v float64) { t.mat.Data[i*t.mat.Stride+pj] = v } -func (t *TriBandDense) setTriBand(i, j int, v float64) { - var kl int - if !t.isUpper() { - kl = t.mat.K - } - pj := j + kl - i - t.mat.Data[i*t.mat.Stride+pj] = v -} - // At returns the element at row i, column j. func (d *DiagDense) At(i, j int) float64 { if uint(i) >= uint(d.mat.N) { diff --git a/mat/list_test.go b/mat/list_test.go index ba813ebd..677f02e6 100644 --- a/mat/list_test.go +++ b/mat/list_test.go @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//nolint:deadcode,unused +//lint:file-ignore U1000 A number of functions are here that may be used in future. + package mat import ( diff --git a/mat/shadow.go b/mat/shadow.go index 8a941c7f..4fc24c34 100644 --- a/mat/shadow.go +++ b/mat/shadow.go @@ -207,6 +207,7 @@ func (s *SymBandDense) checkOverlap(a blas64.General) bool { return checkOverlap(generalFromSymmetricBand(s.RawSymBand()), a) } +//lint:ignore U1000 This will be used when we do shadow checks for banded matrices. func (s *SymBandDense) checkOverlapMatrix(a Matrix) bool { if s == a { return false diff --git a/mat/triband.go b/mat/triband.go index bbce37d6..bffe93fb 100644 --- a/mat/triband.go +++ b/mat/triband.go @@ -324,6 +324,7 @@ func (t *TriBandDense) reuseAsZeroed(n, k int, kind TriKind) { // with the given bandwidth and orientation. If the receiver is not empty, // reuseAsZeroed checks that the receiver has the correct size, bandwidth and // orientation. +//lint:ignore U1000 This will be used later. func (t *TriBandDense) reuseAsNonZeroed(n, k int, kind TriKind) { // reuseAsNonZeroed must be kept in sync with reuseAsZeroed. if n == 0 { diff --git a/mathext/internal/amos/staticcheck.conf b/mathext/internal/amos/staticcheck.conf new file mode 100644 index 00000000..e7e254ff --- /dev/null +++ b/mathext/internal/amos/staticcheck.conf @@ -0,0 +1 @@ +checks = [] diff --git a/mathext/internal/cephes/staticcheck.conf b/mathext/internal/cephes/staticcheck.conf new file mode 100644 index 00000000..e7e254ff --- /dev/null +++ b/mathext/internal/cephes/staticcheck.conf @@ -0,0 +1 @@ +checks = [] diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 00000000..25dda336 --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1 @@ +checks = ["inherit", "-ST1012"]