diff --git a/.goreleaser.yml b/.goreleaser.yml index e3cdc393..edf9277d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -37,6 +37,6 @@ changelog: sort: asc filters: exclude: - - '^docs:' - - '^test:' - - 'README' + - '^docs:' + - '^test:' + - 'README' diff --git a/gomock/call.go b/gomock/call.go index 7bdeab94..7345f654 100644 --- a/gomock/call.go +++ b/gomock/call.go @@ -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)) } @@ -307,22 +307,22 @@ 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) } @@ -330,7 +330,7 @@ func (c *Call) matches(args []interface{}) error { 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 @@ -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 } diff --git a/gomock/callset.go b/gomock/callset.go index c44a8a58..b046b525 100644 --- a/gomock/callset.go +++ b/gomock/callset.go @@ -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 } @@ -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()) diff --git a/gomock/controller.go b/gomock/controller.go index 75f23502..d7c3c656 100644 --- a/gomock/controller.go +++ b/gomock/controller.go @@ -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) } diff --git a/gomock/controller_test.go b/gomock/controller_test.go index c0d42c86..c22908b8 100644 --- a/gomock/controller_test.go +++ b/gomock/controller_test.go @@ -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) @@ -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() diff --git a/gomock/matchers.go b/gomock/matchers.go index 7aa43a6d..70efc75c 100644 --- a/gomock/matchers.go +++ b/gomock/matchers.go @@ -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 } diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index a0d483f5..70bc55f1 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -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() } @@ -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(")") @@ -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) @@ -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) } } diff --git a/mockgen/model/model.go b/mockgen/model/model.go index b93e062a..9c143cfc 100644 --- a/mockgen/model/model.go +++ b/mockgen/model/model.go @@ -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) } @@ -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) } @@ -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) } @@ -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. @@ -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 @@ -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. diff --git a/mockgen/parse.go b/mockgen/parse.go index 1fe16c5e..b0403e58 100644 --- a/mockgen/parse.go +++ b/mockgen/parse.go @@ -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 } @@ -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 } } } diff --git a/mockgen/reflect.go b/mockgen/reflect.go index 21a1b3d6..15f819ce 100644 --- a/mockgen/reflect.go +++ b/mockgen/reflect.go @@ -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) }