diff --git a/.travis.yml b/.travis.yml index 5a54a241..34539ba4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,12 @@ env: - GO111MODULE=on script: + - go vet ./... - go build ./... - go install github.com/golang/mock/mockgen + - GO111MODULE=off go get -u golang.org/x/lint/golint - ./ci/check_go_fmt.sh + - ./ci/check_go_lint.sh - ./ci/check_go_generate.sh - ./ci/check_go_mod.sh - go test -v ./... diff --git a/ci/check_go_lint.sh b/ci/check_go_lint.sh new file mode 100755 index 00000000..78333075 --- /dev/null +++ b/ci/check_go_lint.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# This script is used by CI to check if the code passes golint. + +set -u + +if ! command -v golint >/dev/null; then + echo "error: golint not found; go get -u golang.org/x/lint/golint" >&2 + exit 1 +fi + +GOLINT_OUTPUT=$(IFS=$'\n'; golint ./... | grep -v "mockgen/internal/.*\|sample/.*") +if [[ -n "${GOLINT_OUTPUT}" ]]; then + echo "${GOLINT_OUTPUT}" + echo + echo "The go source files aren't passing golint." + exit 1 +fi diff --git a/ci/check_go_mod.sh b/ci/check_go_mod.sh index 56e79127..262f74c5 100755 --- a/ci/check_go_mod.sh +++ b/ci/check_go_mod.sh @@ -7,6 +7,7 @@ go mod tidy if [ ! -z "$(git status --porcelain)" ]; then git status + git diff echo echo "The go.mod is not up to date." exit 1 diff --git a/gomock/call.go b/gomock/call.go index 826f45d2..7bdeab94 100644 --- a/gomock/call.go +++ b/gomock/call.go @@ -389,7 +389,7 @@ func (c *Call) matches(args []interface{}) error { // Check that the call is not exhausted. if c.exhausted() { - return fmt.Errorf("Expected call at %s has already been called the max number of times.", c.origin) + return fmt.Errorf("expected call at %s has already been called the max number of times", c.origin) } return nil diff --git a/mockgen/model/model.go b/mockgen/model/model.go index 8113e3d3..b93e062a 100644 --- a/mockgen/model/model.go +++ b/mockgen/model/model.go @@ -33,6 +33,7 @@ type Package struct { DotImports []string } +// Print writes the package name and its exported interfaces. func (pkg *Package) Print(w io.Writer) { fmt.Fprintf(w, "package %s\n", pkg.Name) for _, intf := range pkg.Interfaces { @@ -55,6 +56,7 @@ type Interface struct { Methods []*Method } +// Print writes the interface name and its methods. func (intf *Interface) Print(w io.Writer) { fmt.Fprintf(w, "interface %s\n", intf.Name) for _, m := range intf.Methods { @@ -75,6 +77,7 @@ type Method struct { Variadic *Parameter // may be nil } +// Print writes the method name and its signature. func (m *Method) Print(w io.Writer) { fmt.Fprintf(w, " - method %s\n", m.Name) if len(m.In) > 0 { @@ -113,6 +116,7 @@ type Parameter struct { Type Type } +// Print writes a method parameter. func (p *Parameter) Print(w io.Writer) { n := p.Name if n == "" { @@ -183,6 +187,7 @@ func (ct *ChanType) addImports(im map[string]bool) { ct.Type.addImports(im) } // ChanDir is a channel direction. type ChanDir int +// Constants for channel directions. const ( RecvDir ChanDir = 1 SendDir ChanDir = 2 @@ -255,9 +260,9 @@ func (nt *NamedType) String(pm map[string]string, pkgOverride string) string { prefix := pm[nt.Package] if prefix != "" { return prefix + "." + nt.Type - } else { - return nt.Type } + + return nt.Type } func (nt *NamedType) addImports(im map[string]bool) { if nt.Package != "" { @@ -283,6 +288,8 @@ func (pt PredeclaredType) addImports(im map[string]bool) // The following code is intended to be called by the program generated by ../reflect.go. +// InterfaceFromInterfaceType returns a pointer to an interface for the +// given reflection interface type. func InterfaceFromInterfaceType(it reflect.Type) (*Interface, error) { if it.Kind() != reflect.Interface { return nil, fmt.Errorf("%v is not an interface", it)