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

Commit 29da289

Browse files
authoredDec 27, 2019
fix several linting warnings (#374)
1 parent de9f6c5 commit 29da289

File tree

10 files changed

+45
-44
lines changed

10 files changed

+45
-44
lines changed
 

‎.goreleaser.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ changelog:
3737
sort: asc
3838
filters:
3939
exclude:
40-
- '^docs:'
41-
- '^test:'
42-
- 'README'
40+
- '^docs:'
41+
- '^test:'
42+
- 'README'

‎gomock/call.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (c *Call) String() string {
295295
func (c *Call) matches(args []interface{}) error {
296296
if !c.methodType.IsVariadic() {
297297
if len(args) != len(c.args) {
298-
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d",
298+
return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: %d",
299299
c.origin, len(args), len(c.args))
300300
}
301301

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

309309
return fmt.Errorf(
310-
"Expected call at %s doesn't match the argument at index %d.\nGot: %v\nWant: %v",
310+
"expected call at %s doesn't match the argument at index %d.\nGot: %v\nWant: %v",
311311
c.origin, i, got, m,
312312
)
313313
}
314314
}
315315
} else {
316316
if len(c.args) < c.methodType.NumIn()-1 {
317-
return fmt.Errorf("Expected call at %s has the wrong number of matchers. Got: %d, want: %d",
317+
return fmt.Errorf("expected call at %s has the wrong number of matchers. Got: %d, want: %d",
318318
c.origin, len(c.args), c.methodType.NumIn()-1)
319319
}
320320
if len(c.args) != c.methodType.NumIn() && len(args) != len(c.args) {
321-
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d",
321+
return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: %d",
322322
c.origin, len(args), len(c.args))
323323
}
324324
if len(args) < len(c.args)-1 {
325-
return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d",
325+
return fmt.Errorf("expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d",
326326
c.origin, len(args), len(c.args)-1)
327327
}
328328

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

406-
func (c *Call) call(args []interface{}) []func([]interface{}) []interface{} {
406+
func (c *Call) call() []func([]interface{}) []interface{} {
407407
c.numCalls++
408408
return c.actions
409409
}

‎gomock/callset.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac
7272
for _, call := range expected {
7373
err := call.matches(args)
7474
if err != nil {
75-
fmt.Fprintf(&callsErrors, "\n%v", err)
75+
_, _ = fmt.Fprintf(&callsErrors, "\n%v", err)
7676
} else {
7777
return call, nil
7878
}
@@ -83,12 +83,12 @@ func (cs callSet) FindMatch(receiver interface{}, method string, args []interfac
8383
exhausted := cs.exhausted[key]
8484
for _, call := range exhausted {
8585
if err := call.matches(args); err != nil {
86-
fmt.Fprintf(&callsErrors, "\n%v", err)
86+
_, _ = fmt.Fprintf(&callsErrors, "\n%v", err)
8787
}
8888
}
8989

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

9494
return nil, fmt.Errorf(callsErrors.String())

‎gomock/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf
209209
ctrl.expectedCalls.Remove(preReqCall)
210210
}
211211

212-
actions := expected.call(args)
212+
actions := expected.call()
213213
if expected.exhausted() {
214214
ctrl.expectedCalls.Remove(expected)
215215
}

‎gomock/controller_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ func TestMaxTimes1(t *testing.T) {
426426
ctrl.Call(subject, "FooMethod", "argument")
427427
ctrl.Finish()
428428

429-
//It fails if there are more
429+
// It fails if there are more
430430
reporter, ctrl := createFixtures(t)
431431
subject = new(Subject)
432432
ctrl.RecordCall(subject, "FooMethod", "argument").MaxTimes(1)
@@ -757,7 +757,7 @@ func TestVariadicNoMatch(t *testing.T) {
757757
ctrl.RecordCall(s, "VariadicMethod", 0)
758758
rep.assertFatal(func() {
759759
ctrl.Call(s, "VariadicMethod", 1)
760-
}, "Expected call at", "doesn't match the argument at index 0",
760+
}, "expected call at", "doesn't match the argument at index 0",
761761
"Got: 1\nWant: is equal to 0")
762762
ctrl.Call(s, "VariadicMethod", 0)
763763
ctrl.Finish()

‎gomock/matchers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func GotFormatterAdapter(s GotFormatter, m Matcher) Matcher {
8989

9090
type anyMatcher struct{}
9191

92-
func (anyMatcher) Matches(x interface{}) bool {
92+
func (anyMatcher) Matches(interface{}) bool {
9393
return true
9494
}
9595

‎mockgen/mockgen.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func parseMockNames(names string) map[string]string {
158158
}
159159

160160
func usage() {
161-
io.WriteString(os.Stderr, usageText)
161+
_, _ = io.WriteString(os.Stderr, usageText)
162162
flag.PrintDefaults()
163163
}
164164

@@ -305,14 +305,14 @@ func (g *generator) Generate(pkg *model.Package, pkgName string, outputPackagePa
305305
g.p("")
306306
g.p("import (")
307307
g.in()
308-
for path, pkg := range g.packageMap {
309-
if path == outputPackagePath {
308+
for pkgPath, pkg := range g.packageMap {
309+
if pkgPath == outputPackagePath {
310310
continue
311311
}
312-
g.p("%v %q", pkg, path)
312+
g.p("%v %q", pkg, pkgPath)
313313
}
314-
for _, path := range pkg.DotImports {
315-
g.p(". %q", path)
314+
for _, pkgPath := range pkg.DotImports {
315+
g.p(". %q", pkgPath)
316316
}
317317
g.out()
318318
g.p(")")
@@ -357,9 +357,9 @@ func (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePa
357357
g.p("")
358358

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

364364
g.p("// New%v creates a new mock instance", mockType)
365365
g.p("func New%v(ctrl *gomock.Controller) *%v {", mockType, mockType)
@@ -387,9 +387,9 @@ func (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePa
387387
func (g *generator) GenerateMockMethods(mockType string, intf *model.Interface, pkgOverride string) {
388388
for _, m := range intf.Methods {
389389
g.p("")
390-
g.GenerateMockMethod(mockType, m, pkgOverride)
390+
_ = g.GenerateMockMethod(mockType, m, pkgOverride)
391391
g.p("")
392-
g.GenerateMockRecorderMethod(mockType, m)
392+
_ = g.GenerateMockRecorderMethod(mockType, m)
393393
}
394394
}
395395

‎mockgen/model/model.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Package struct {
3535

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

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

8080
// Print writes the method name and its signature.
8181
func (m *Method) Print(w io.Writer) {
82-
fmt.Fprintf(w, " - method %s\n", m.Name)
82+
_, _ = fmt.Fprintf(w, " - method %s\n", m.Name)
8383
if len(m.In) > 0 {
84-
fmt.Fprintf(w, " in:\n")
84+
_, _ = fmt.Fprintf(w, " in:\n")
8585
for _, p := range m.In {
8686
p.Print(w)
8787
}
8888
}
8989
if m.Variadic != nil {
90-
fmt.Fprintf(w, " ...:\n")
90+
_, _ = fmt.Fprintf(w, " ...:\n")
9191
m.Variadic.Print(w)
9292
}
9393
if len(m.Out) > 0 {
94-
fmt.Fprintf(w, " out:\n")
94+
_, _ = fmt.Fprintf(w, " out:\n")
9595
for _, p := range m.Out {
9696
p.Print(w)
9797
}
@@ -122,7 +122,7 @@ func (p *Parameter) Print(w io.Writer) {
122122
if n == "" {
123123
n = `""`
124124
}
125-
fmt.Fprintf(w, " - %v: %v\n", n, p.Type.String(nil, ""))
125+
_, _ = fmt.Fprintf(w, " - %v: %v\n", n, p.Type.String(nil, ""))
126126
}
127127

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

265265
return nt.Type
266266
}
267+
267268
func (nt *NamedType) addImports(im map[string]bool) {
268269
if nt.Package != "" {
269270
im[nt.Package] = true
@@ -283,8 +284,8 @@ func (pt *PointerType) addImports(im map[string]bool) { pt.Type.addImports(im) }
283284
// PredeclaredType is a predeclared type such as "int".
284285
type PredeclaredType string
285286

286-
func (pt PredeclaredType) String(pm map[string]string, pkgOverride string) string { return string(pt) }
287-
func (pt PredeclaredType) addImports(im map[string]bool) {}
287+
func (pt PredeclaredType) String(map[string]string, string) string { return string(pt) }
288+
func (pt PredeclaredType) addImports(map[string]bool) {}
288289

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

‎mockgen/parse.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ func parseFile(source string) (*model.Package, error) {
101101
if err != nil {
102102
return nil, err
103103
}
104-
for path := range dotImports {
105-
pkg.DotImports = append(pkg.DotImports, path)
104+
for pkgPath := range dotImports {
105+
pkg.DotImports = append(pkg.DotImports, pkgPath)
106106
}
107107
return pkg, nil
108108
}
@@ -161,18 +161,18 @@ func (p *fileParser) addAuxInterfacesFromFile(pkg string, file *ast.File) {
161161
func (p *fileParser) parseFile(importPath string, file *ast.File) (*model.Package, error) {
162162
allImports, dotImports := importsOfFile(file)
163163
// Don't stomp imports provided by -imports. Those should take precedence.
164-
for pkg, path := range allImports {
164+
for pkg, pkgPath := range allImports {
165165
if _, ok := p.imports[pkg]; !ok {
166-
p.imports[pkg] = path
166+
p.imports[pkg] = pkgPath
167167
}
168168
}
169169
// Add imports from auxiliary files, which might be needed for embedded interfaces.
170170
// Don't stomp any other imports.
171171
for _, f := range p.auxFiles {
172172
auxImports, _ := importsOfFile(f)
173-
for pkg, path := range auxImports {
173+
for pkg, pkgPath := range auxImports {
174174
if _, ok := p.imports[pkg]; !ok {
175-
p.imports[pkg] = path
175+
p.imports[pkg] = pkgPath
176176
}
177177
}
178178
}

‎mockgen/reflect.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func reflect(importPath string, symbols []string) (*model.Package, error) {
145145
}
146146

147147
if *progOnly {
148-
os.Stdout.Write(program)
148+
_, _ = os.Stdout.Write(program)
149149
os.Exit(0)
150150
}
151151

0 commit comments

Comments
 (0)
This repository has been archived.