Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Add a CI check for go vet and go lint (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesselang authored and codyoss committed Dec 13, 2019
1 parent 112dfb8 commit 41e7e9a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
17 changes: 17 additions & 0 deletions ci/check_go_lint.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions ci/check_go_mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gomock/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions mockgen/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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)
Expand Down

0 comments on commit 41e7e9a

Please sign in to comment.