From 4aa8656eb0d5e590e3a4311346475e65deb226bb Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sun, 13 Jan 2019 10:12:52 -0800 Subject: [PATCH] lint: fix issues in examples (#49) --- .golangci.yml | 2 ++ examples/args/args.go | 2 ++ examples/fnv1a/fnv_test.go | 4 +++- examples/returns/returns.go | 1 + examples/sha1/sha1.go | 12 +++++++----- examples/stadtx/LICENSE | 2 +- examples/stadtx/fork.sh | 2 +- examples/stadtx/stadtx.go | 2 +- examples/stadtx/stadtx_test.go | 2 +- script/generate | 2 +- script/lint | 3 ++- 11 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 76c7c4ab..c07a4bee 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,3 +21,5 @@ issues: exclude: # errcheck: Almost all programs ignore errors on these functions and in most cases it's ok - Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked + # gocritic: unlambda with builtins is invalid. + - ' with `(len|cap|real|imag)`' diff --git a/examples/args/args.go b/examples/args/args.go index 5c1d313c..679bc613 100644 --- a/examples/args/args.go +++ b/examples/args/args.go @@ -1,5 +1,6 @@ package args +// Struct is a struct containing various datatypes, to help demonstrate struct field access. type Struct struct { Byte byte Int8 int8 @@ -15,6 +16,7 @@ type Struct struct { Complex128 complex128 } +// Sub is a sub-struct of Struct, to demonstrate nested datastructure accesses. type Sub struct { A uint64 B [3]byte diff --git a/examples/fnv1a/fnv_test.go b/examples/fnv1a/fnv_test.go index dceb1aa3..1cc369f0 100644 --- a/examples/fnv1a/fnv_test.go +++ b/examples/fnv1a/fnv_test.go @@ -11,7 +11,9 @@ import ( func TestHash64(t *testing.T) { expect := func(data []byte) uint64 { h := fnv.New64a() - h.Write(data) + if _, err := h.Write(data); err != nil { + t.Fatal(err) + } return h.Sum64() } if err := quick.CheckEqual(Hash64, expect, nil); err != nil { diff --git a/examples/returns/returns.go b/examples/returns/returns.go index dcfd52a8..99c147a4 100644 --- a/examples/returns/returns.go +++ b/examples/returns/returns.go @@ -1,5 +1,6 @@ package returns +// Struct is used to deomonstrate writing struct return values. type Struct struct { Word uint16 Point [2]float64 diff --git a/examples/sha1/sha1.go b/examples/sha1/sha1.go index a1159fda..bb944c7d 100644 --- a/examples/sha1/sha1.go +++ b/examples/sha1/sha1.go @@ -4,11 +4,13 @@ import ( "encoding/binary" ) -const ( - Size = 20 - BlockSize = 64 -) +// Size of a SHA-1 checksum in bytes. +const Size = 20 + +// BlockSize is the block size of SHA-1 in bytes. +const BlockSize = 64 +// Sum returns the SHA-1 checksum of data. func Sum(data []byte) [Size]byte { n := len(data) h := [5]uint32{0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0} @@ -21,7 +23,7 @@ func Sum(data []byte) [Size]byte { // Final block. tmp := make([]byte, BlockSize) - copy(tmp[:], data) + copy(tmp, data) tmp[len(data)] = 0x80 if len(data) >= 56 { diff --git a/examples/stadtx/LICENSE b/examples/stadtx/LICENSE index 1d3a458a..bd92ca27 100644 --- a/examples/stadtx/LICENSE +++ b/examples/stadtx/LICENSE @@ -1,4 +1,4 @@ -// Downloaded from https://raw.githubusercontent.com/demerphq/BeagleHash/5f8620b953230e5b16171b745155fc3b0ef8f75e/LICENSE +// Code generated by downloading from https://raw.githubusercontent.com/demerphq/BeagleHash/5f8620b953230e5b16171b745155fc3b0ef8f75e/LICENSE. DO NOT EDIT. GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 diff --git a/examples/stadtx/fork.sh b/examples/stadtx/fork.sh index 62e99564..681429b8 100755 --- a/examples/stadtx/fork.sh +++ b/examples/stadtx/fork.sh @@ -4,7 +4,7 @@ dl() { url=$1 filename=$(basename $1) { - echo "// Downloaded from ${url}" + echo "// Code generated by downloading from ${url}. DO NOT EDIT." echo curl -L ${url} } > ${filename} diff --git a/examples/stadtx/stadtx.go b/examples/stadtx/stadtx.go index 7cda5308..e83adf38 100644 --- a/examples/stadtx/stadtx.go +++ b/examples/stadtx/stadtx.go @@ -1,4 +1,4 @@ -// Downloaded from https://github.com/dgryski/go-stadtx/raw/3c3d9b328c24a9b5ecd370654cd6e9d60a85752d/stadtx.go +// Code generated by downloading from https://github.com/dgryski/go-stadtx/raw/3c3d9b328c24a9b5ecd370654cd6e9d60a85752d/stadtx.go. DO NOT EDIT. // Package stadtx implements Stadtx Hash /* diff --git a/examples/stadtx/stadtx_test.go b/examples/stadtx/stadtx_test.go index 1a31ce1b..cccb791e 100644 --- a/examples/stadtx/stadtx_test.go +++ b/examples/stadtx/stadtx_test.go @@ -1,4 +1,4 @@ -// Downloaded from https://github.com/dgryski/go-stadtx/raw/3c3d9b328c24a9b5ecd370654cd6e9d60a85752d/stadtx_test.go +// Code generated by downloading from https://github.com/dgryski/go-stadtx/raw/3c3d9b328c24a9b5ecd370654cd6e9d60a85752d/stadtx_test.go. DO NOT EDIT. package stadtx diff --git a/script/generate b/script/generate index 52c77f1a..34e8dec4 100755 --- a/script/generate +++ b/script/generate @@ -8,7 +8,7 @@ post=$(go list ./... | grep -E 'avo/(examples|tests)') go install ./internal/cmd/avogen # Attempt to delete generated files, to prove we can recreate them. -grep -REl 'Code generated.*DO NOT EDIT\.$' . | grep -v '.md$' | xargs rm -v +grep -RE '^// Code generated.*DO NOT EDIT\.$' . | grep -v download | cut -d: -f1 | grep -v '.md$' | xargs rm -v # Generate once. go generate -v -x ${core} diff --git a/script/lint b/script/lint index 275a27e1..500b4c2d 100755 --- a/script/lint +++ b/script/lint @@ -10,4 +10,5 @@ find . -name '*.s' | xargs asmfmt -w test -z "$(git status --porcelain)" # Run suite of golangci-lint checks. -golangci-lint run +# (Provide examples directory explicitly since it is skipped by default.) +golangci-lint run ./... ./examples/...