Skip to content

Commit

Permalink
lint: fix issues in examples (mmcloughlin#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcloughlin committed Jan 13, 2019
1 parent 943d5f0 commit 4aa8656
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)`'
2 changes: 2 additions & 0 deletions examples/args/args.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion examples/fnv1a/fnv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions examples/returns/returns.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package returns

// Struct is used to deomonstrate writing struct return values.
type Struct struct {
Word uint16
Point [2]float64
Expand Down
12 changes: 7 additions & 5 deletions examples/sha1/sha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion examples/stadtx/LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/stadtx/fork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion examples/stadtx/stadtx.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/stadtx/stadtx_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion script/generate
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -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/...

0 comments on commit 4aa8656

Please sign in to comment.