Repository: mgechev/revive
Pull request #527 (2021-05-25 19:49:31)

Update module golang.org/x/tools to v0.1.2
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [golang.org/x/tools](https://togithub.com/golang/tools) | require | patch | `v0.1.1` -> `v0.1.2` |

---

### Release Notes

<details>
<summary>golang/tools</summary>

### [`v0.1.2`](https://togithub.com/golang/tools/compare/v0.1.1...v0.1.2)

[Compare Source](https://togithub.com/golang/tools/compare/v0.1.1...v0.1.2)

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻️ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/mgechev/revive).


Patch:
diff --git a/go.mod b/go.mod
index 5dac74b..acb9145 100644
--- a/go.mod
+++ b/go.mod
@@ -11,5 +11,5 @@ require (
 	github.com/mitchellh/go-homedir v1.1.0
 	github.com/olekukonko/tablewriter v0.0.5
 	github.com/pkg/errors v0.9.1
-	golang.org/x/tools v0.1.1
+	golang.org/x/tools v0.1.2
 )
diff --git a/go.sum b/go.sum
index 43968c5..36e1819 100644
--- a/go.sum
+++ b/go.sum
@@ -66,6 +66,8 @@ golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
 golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
 golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
 golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
+golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=
+golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
diff --git a/rule/context-as-argument.go b/rule/context-as-argument.go
index 0ed28a8..6502a07 100644
--- a/rule/context-as-argument.go
+++ b/rule/context-as-argument.go
@@ -45,16 +45,19 @@ func (w lintContextArguments) Visit(n ast.Node) ast.Visitor {
 	}
 	// A context.Context should be the first parameter of a function.
 	// 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:] {
-		if isPkgDot(arg.Type, "context", "Context") {
+		argIsCtx := isPkgDot(arg.Type, "context", "Context")
+		if argIsCtx && !previousArgIsCtx {
 			w.onFailure(lint.Failure{
-				Node:       fn,
+				Node:       arg,
 				Category:   "arg-order",
 				Failure:    "context.Context should be the first parameter of a function",
 				Confidence: 0.9,
 			})
 			break // only flag one
 		}
+		previousArgIsCtx = argIsCtx
 	}
 	return w
 }


Test patch:
diff --git a/testdata/golint/context-as-argument.go b/testdata/golint/context-as-argument.go
index 5580e60..62e152c 100644
--- a/testdata/golint/context-as-argument.go
+++ b/testdata/golint/context-as-argument.go
@@ -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
 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/