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

Commit 41e7e9a

Browse files
jesselangcodyoss
authored andcommittedDec 13, 2019
Add a CI check for go vet and go lint (#345)
1 parent 112dfb8 commit 41e7e9a

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed
 

Diff for: ‎.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ env:
99
- GO111MODULE=on
1010

1111
script:
12+
- go vet ./...
1213
- go build ./...
1314
- go install github.com/golang/mock/mockgen
15+
- GO111MODULE=off go get -u golang.org/x/lint/golint
1416
- ./ci/check_go_fmt.sh
17+
- ./ci/check_go_lint.sh
1518
- ./ci/check_go_generate.sh
1619
- ./ci/check_go_mod.sh
1720
- go test -v ./...

Diff for: ‎ci/check_go_lint.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# This script is used by CI to check if the code passes golint.
3+
4+
set -u
5+
6+
if ! command -v golint >/dev/null; then
7+
echo "error: golint not found; go get -u golang.org/x/lint/golint" >&2
8+
exit 1
9+
fi
10+
11+
GOLINT_OUTPUT=$(IFS=$'\n'; golint ./... | grep -v "mockgen/internal/.*\|sample/.*")
12+
if [[ -n "${GOLINT_OUTPUT}" ]]; then
13+
echo "${GOLINT_OUTPUT}"
14+
echo
15+
echo "The go source files aren't passing golint."
16+
exit 1
17+
fi

Diff for: ‎ci/check_go_mod.sh

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ go mod tidy
77

88
if [ ! -z "$(git status --porcelain)" ]; then
99
git status
10+
git diff
1011
echo
1112
echo "The go.mod is not up to date."
1213
exit 1

Diff for: ‎gomock/call.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func (c *Call) matches(args []interface{}) error {
389389

390390
// Check that the call is not exhausted.
391391
if c.exhausted() {
392-
return fmt.Errorf("Expected call at %s has already been called the max number of times.", c.origin)
392+
return fmt.Errorf("expected call at %s has already been called the max number of times", c.origin)
393393
}
394394

395395
return nil

Diff for: ‎mockgen/model/model.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Package struct {
3333
DotImports []string
3434
}
3535

36+
// Print writes the package name and its exported interfaces.
3637
func (pkg *Package) Print(w io.Writer) {
3738
fmt.Fprintf(w, "package %s\n", pkg.Name)
3839
for _, intf := range pkg.Interfaces {
@@ -55,6 +56,7 @@ type Interface struct {
5556
Methods []*Method
5657
}
5758

59+
// Print writes the interface name and its methods.
5860
func (intf *Interface) Print(w io.Writer) {
5961
fmt.Fprintf(w, "interface %s\n", intf.Name)
6062
for _, m := range intf.Methods {
@@ -75,6 +77,7 @@ type Method struct {
7577
Variadic *Parameter // may be nil
7678
}
7779

80+
// Print writes the method name and its signature.
7881
func (m *Method) Print(w io.Writer) {
7982
fmt.Fprintf(w, " - method %s\n", m.Name)
8083
if len(m.In) > 0 {
@@ -113,6 +116,7 @@ type Parameter struct {
113116
Type Type
114117
}
115118

119+
// Print writes a method parameter.
116120
func (p *Parameter) Print(w io.Writer) {
117121
n := p.Name
118122
if n == "" {
@@ -183,6 +187,7 @@ func (ct *ChanType) addImports(im map[string]bool) { ct.Type.addImports(im) }
183187
// ChanDir is a channel direction.
184188
type ChanDir int
185189

190+
// Constants for channel directions.
186191
const (
187192
RecvDir ChanDir = 1
188193
SendDir ChanDir = 2
@@ -255,9 +260,9 @@ func (nt *NamedType) String(pm map[string]string, pkgOverride string) string {
255260
prefix := pm[nt.Package]
256261
if prefix != "" {
257262
return prefix + "." + nt.Type
258-
} else {
259-
return nt.Type
260263
}
264+
265+
return nt.Type
261266
}
262267
func (nt *NamedType) addImports(im map[string]bool) {
263268
if nt.Package != "" {
@@ -283,6 +288,8 @@ func (pt PredeclaredType) addImports(im map[string]bool)
283288

284289
// The following code is intended to be called by the program generated by ../reflect.go.
285290

291+
// InterfaceFromInterfaceType returns a pointer to an interface for the
292+
// given reflection interface type.
286293
func InterfaceFromInterfaceType(it reflect.Type) (*Interface, error) {
287294
if it.Kind() != reflect.Interface {
288295
return nil, fmt.Errorf("%v is not an interface", it)

0 commit comments

Comments
 (0)
This repository has been archived.