mirror of
https://github.com/mgechev/revive.git
synced 2024-11-28 08:49:11 +02:00
fix 525 (#526)
This commit is contained in:
parent
052235cc63
commit
97ef50d9f7
@ -45,16 +45,19 @@ func (w lintContextArguments) Visit(n ast.Node) ast.Visitor {
|
|||||||
}
|
}
|
||||||
// A context.Context should be the first parameter of a function.
|
// A context.Context should be the first parameter of a function.
|
||||||
// Flag any that show up after the first.
|
// Flag any that show up after the first.
|
||||||
|
previousArgIsCtx := isPkgDot(fn.Type.Params.List[0].Type, "context", "Context")
|
||||||
for _, arg := range fn.Type.Params.List[1:] {
|
for _, arg := range fn.Type.Params.List[1:] {
|
||||||
if isPkgDot(arg.Type, "context", "Context") {
|
argIsCtx := isPkgDot(arg.Type, "context", "Context")
|
||||||
|
if argIsCtx && !previousArgIsCtx {
|
||||||
w.onFailure(lint.Failure{
|
w.onFailure(lint.Failure{
|
||||||
Node: fn,
|
Node: arg,
|
||||||
Category: "arg-order",
|
Category: "arg-order",
|
||||||
Failure: "context.Context should be the first parameter of a function",
|
Failure: "context.Context should be the first parameter of a function",
|
||||||
Confidence: 0.9,
|
Confidence: 0.9,
|
||||||
})
|
})
|
||||||
break // only flag one
|
break // only flag one
|
||||||
}
|
}
|
||||||
|
previousArgIsCtx = argIsCtx
|
||||||
}
|
}
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
4
testdata/golint/context-as-argument.go
vendored
4
testdata/golint/context-as-argument.go
vendored
@ -22,3 +22,7 @@ func y(s string, ctx context.Context) { // MATCH /context.Context should be the
|
|||||||
// An invalid context.Context location with more than 2 args
|
// An invalid context.Context location with more than 2 args
|
||||||
func y(s string, r int, ctx context.Context, x int) { // MATCH /context.Context should be the first parameter of a function/
|
func y(s string, r int, ctx context.Context, x int) { // MATCH /context.Context should be the first parameter of a function/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func y(ctx1 context.Context, ctx2 context.Context, x int) {}
|
||||||
|
|
||||||
|
func y(ctx1 context.Context, ctx2 context.Context, x int, ctx3 context.Context) {} // MATCH /context.Context should be the first parameter of a function/
|
||||||
|
Loading…
Reference in New Issue
Block a user