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

Commit

Permalink
fix several linting warnings (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
codyoss committed Dec 27, 2019
1 parent de9f6c5 commit 29da289
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- 'README'
- '^docs:'
- '^test:'
- 'README'
14 changes: 7 additions & 7 deletions gomock/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (c *Call) String() string {
func (c *Call) matches(args []interface{}) error {
if !c.methodType.IsVariadic() {
if len(args) != len(c.args) {
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d",
return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: %d",
c.origin, len(args), len(c.args))
}

Expand All @@ -307,30 +307,30 @@ func (c *Call) matches(args []interface{}) error {
}

return fmt.Errorf(
"Expected call at %s doesn't match the argument at index %d.\nGot: %v\nWant: %v",
"expected call at %s doesn't match the argument at index %d.\nGot: %v\nWant: %v",
c.origin, i, got, m,
)
}
}
} else {
if len(c.args) < c.methodType.NumIn()-1 {
return fmt.Errorf("Expected call at %s has the wrong number of matchers. Got: %d, want: %d",
return fmt.Errorf("expected call at %s has the wrong number of matchers. Got: %d, want: %d",
c.origin, len(c.args), c.methodType.NumIn()-1)
}
if len(c.args) != c.methodType.NumIn() && len(args) != len(c.args) {
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d",
return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: %d",
c.origin, len(args), len(c.args))
}
if len(args) < len(c.args)-1 {
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d",
return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d",
c.origin, len(args), len(c.args)-1)
}

for i, m := range c.args {
if i < c.methodType.NumIn()-1 {
// Non-variadic args
if !m.Matches(args[i]) {
return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
return fmt.Errorf("expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v",
c.origin, strconv.Itoa(i), args[i], m)
}
continue
Expand Down Expand Up @@ -403,7 +403,7 @@ func (c *Call) dropPrereqs() (preReqs []*Call) {
return
}

func (c *Call) call(args []interface{}) []func([]interface{}) []interface{} {
func (c *Call) call() []func([]interface{}) []interface{} {
c.numCalls++
return c.actions
}
Expand Down
6 changes: 3 additions & 3 deletions gomock/callset.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac
for _, call := range expected {
err := call.matches(args)
if err != nil {
fmt.Fprintf(&callsErrors, "\n%v", err)
_, _ = fmt.Fprintf(&callsErrors, "\n%v", err)
} else {
return call, nil
}
Expand All @@ -83,12 +83,12 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac
exhausted := cs.exhausted[key]
for _, call := range exhausted {
if err := call.matches(args); err != nil {
fmt.Fprintf(&callsErrors, "\n%v", err)
_, _ = fmt.Fprintf(&callsErrors, "\n%v", err)
}
}

if len(expected)+len(exhausted) == 0 {
fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
_, _ = fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method)
}

return nil, fmt.Errorf(callsErrors.String())
Expand Down
2 changes: 1 addition & 1 deletion gomock/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf
ctrl.expectedCalls.Remove(preReqCall)
}

actions := expected.call(args)
actions := expected.call()
if expected.exhausted() {
ctrl.expectedCalls.Remove(expected)
}
Expand Down
4 changes: 2 additions & 2 deletions gomock/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func TestMaxTimes1(t *testing.T) {
ctrl.Call(subject, "FooMethod", "argument")
ctrl.Finish()

//It fails if there are more
// It fails if there are more
reporter, ctrl := createFixtures(t)
subject = new(Subject)
ctrl.RecordCall(subject, "FooMethod", "argument").MaxTimes(1)
Expand Down Expand Up @@ -757,7 +757,7 @@ func TestVariadicNoMatch(t *testing.T) {
ctrl.RecordCall(s, "VariadicMethod", 0)
rep.assertFatal(func() {
ctrl.Call(s, "VariadicMethod", 1)
}, "Expected call at", "doesn't match the argument at index 0",
}, "expected call at", "doesn't match the argument at index 0",
"Got: 1\nWant: is equal to 0")
ctrl.Call(s, "VariadicMethod", 0)
ctrl.Finish()
Expand Down
2 changes: 1 addition & 1 deletion gomock/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func GotFormatterAdapter(s GotFormatter, m Matcher) Matcher {

type anyMatcher struct{}

func (anyMatcher) Matches(x interface{}) bool {
func (anyMatcher) Matches(interface{}) bool {
return true
}

Expand Down
22 changes: 11 additions & 11 deletions mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func parseMockNames(names string) map[string]string {
}

func usage() {
io.WriteString(os.Stderr, usageText)
_, _ = io.WriteString(os.Stderr, usageText)
flag.PrintDefaults()
}

Expand Down Expand Up @@ -305,14 +305,14 @@ func (g *generator) Generate(pkg *model.Package, pkgName string, outputPackagePa
g.p("")
g.p("import (")
g.in()
for path, pkg := range g.packageMap {
if path == outputPackagePath {
for pkgPath, pkg := range g.packageMap {
if pkgPath == outputPackagePath {
continue
}
g.p("%v %q", pkg, path)
g.p("%v %q", pkg, pkgPath)
}
for _, path := range pkg.DotImports {
g.p(". %q", path)
for _, pkgPath := range pkg.DotImports {
g.p(". %q", pkgPath)
}
g.out()
g.p(")")
Expand Down Expand Up @@ -357,9 +357,9 @@ func (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePa
g.p("")

// TODO: Re-enable this if we can import the interface reliably.
//g.p("// Verify that the mock satisfies the interface at compile time.")
//g.p("var _ %v = (*%v)(nil)", typeName, mockType)
//g.p("")
// g.p("// Verify that the mock satisfies the interface at compile time.")
// g.p("var _ %v = (*%v)(nil)", typeName, mockType)
// g.p("")

g.p("// New%v creates a new mock instance", mockType)
g.p("func New%v(ctrl *gomock.Controller) *%v {", mockType, mockType)
Expand Down Expand Up @@ -387,9 +387,9 @@ func (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePa
func (g *generator) GenerateMockMethods(mockType string, intf *model.Interface, pkgOverride string) {
for _, m := range intf.Methods {
g.p("")
g.GenerateMockMethod(mockType, m, pkgOverride)
_ = g.GenerateMockMethod(mockType, m, pkgOverride)
g.p("")
g.GenerateMockRecorderMethod(mockType, m)
_ = g.GenerateMockRecorderMethod(mockType, m)
}
}

Expand Down
19 changes: 10 additions & 9 deletions mockgen/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Package struct {

// Print writes the package name and its exported interfaces.
func (pkg *Package) Print(w io.Writer) {
fmt.Fprintf(w, "package %s\n", pkg.Name)
_, _ = fmt.Fprintf(w, "package %s\n", pkg.Name)
for _, intf := range pkg.Interfaces {
intf.Print(w)
}
Expand All @@ -58,7 +58,7 @@ type Interface struct {

// Print writes the interface name and its methods.
func (intf *Interface) Print(w io.Writer) {
fmt.Fprintf(w, "interface %s\n", intf.Name)
_, _ = fmt.Fprintf(w, "interface %s\n", intf.Name)
for _, m := range intf.Methods {
m.Print(w)
}
Expand All @@ -79,19 +79,19 @@ type Method struct {

// Print writes the method name and its signature.
func (m *Method) Print(w io.Writer) {
fmt.Fprintf(w, " - method %s\n", m.Name)
_, _ = fmt.Fprintf(w, " - method %s\n", m.Name)
if len(m.In) > 0 {
fmt.Fprintf(w, " in:\n")
_, _ = fmt.Fprintf(w, " in:\n")
for _, p := range m.In {
p.Print(w)
}
}
if m.Variadic != nil {
fmt.Fprintf(w, " ...:\n")
_, _ = fmt.Fprintf(w, " ...:\n")
m.Variadic.Print(w)
}
if len(m.Out) > 0 {
fmt.Fprintf(w, " out:\n")
_, _ = fmt.Fprintf(w, " out:\n")
for _, p := range m.Out {
p.Print(w)
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func (p *Parameter) Print(w io.Writer) {
if n == "" {
n = `""`
}
fmt.Fprintf(w, " - %v: %v\n", n, p.Type.String(nil, ""))
_, _ = fmt.Fprintf(w, " - %v: %v\n", n, p.Type.String(nil, ""))
}

// Type is a Go type.
Expand Down Expand Up @@ -264,6 +264,7 @@ func (nt *NamedType) String(pm map[string]string, pkgOverride string) string {

return nt.Type
}

func (nt *NamedType) addImports(im map[string]bool) {
if nt.Package != "" {
im[nt.Package] = true
Expand All @@ -283,8 +284,8 @@ func (pt *PointerType) addImports(im map[string]bool) { pt.Type.addImports(im) }
// PredeclaredType is a predeclared type such as "int".
type PredeclaredType string

func (pt PredeclaredType) String(pm map[string]string, pkgOverride string) string { return string(pt) }
func (pt PredeclaredType) addImports(im map[string]bool) {}
func (pt PredeclaredType) String(map[string]string, string) string { return string(pt) }
func (pt PredeclaredType) addImports(map[string]bool) {}

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

Expand Down
12 changes: 6 additions & 6 deletions mockgen/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func parseFile(source string) (*model.Package, error) {
if err != nil {
return nil, err
}
for path := range dotImports {
pkg.DotImports = append(pkg.DotImports, path)
for pkgPath := range dotImports {
pkg.DotImports = append(pkg.DotImports, pkgPath)
}
return pkg, nil
}
Expand Down Expand Up @@ -161,18 +161,18 @@ func (p *fileParser) addAuxInterfacesFromFile(pkg string, file *ast.File) {
func (p *fileParser) parseFile(importPath string, file *ast.File) (*model.Package, error) {
allImports, dotImports := importsOfFile(file)
// Don't stomp imports provided by -imports. Those should take precedence.
for pkg, path := range allImports {
for pkg, pkgPath := range allImports {
if _, ok := p.imports[pkg]; !ok {
p.imports[pkg] = path
p.imports[pkg] = pkgPath
}
}
// Add imports from auxiliary files, which might be needed for embedded interfaces.
// Don't stomp any other imports.
for _, f := range p.auxFiles {
auxImports, _ := importsOfFile(f)
for pkg, path := range auxImports {
for pkg, pkgPath := range auxImports {
if _, ok := p.imports[pkg]; !ok {
p.imports[pkg] = path
p.imports[pkg] = pkgPath
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mockgen/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func reflect(importPath string, symbols []string) (*model.Package, error) {
}

if *progOnly {
os.Stdout.Write(program)
_, _ = os.Stdout.Write(program)
os.Exit(0)
}

Expand Down

0 comments on commit 29da289

Please sign in to comment.