Repository: mgechev/revive
Pull request #423 (2020-05-18 18:18:00)

Update golang.org/x/tools commit hash to 57a9e44
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [golang.org/x/tools](https://togithub.com/golang/tools) | require | digest | `d3bf790` -> `57a9e44` |

---

### Renovate configuration

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

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

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

:no_bell: **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#mgechev/revive).


Patch:
diff --git a/go.mod b/go.mod
index a5ea3c3..0addf61 100644
--- a/go.mod
+++ b/go.mod
@@ -10,5 +10,5 @@ require (
 	github.com/mitchellh/go-homedir v1.1.0
 	github.com/olekukonko/tablewriter v0.0.4
 	github.com/pkg/errors v0.9.1
-	golang.org/x/tools v0.0.0-20200515220128-d3bf790afa53
+	golang.org/x/tools v0.0.0-20200519205726-57a9e4404bf7
 )
diff --git a/go.sum b/go.sum
index 243f257..4b24b48 100644
--- a/go.sum
+++ b/go.sum
@@ -60,6 +60,8 @@ golang.org/x/tools v0.0.0-20200515204822-0aa9f2fd802d h1:fSQ/iFu/nVJ6KPZPwuRObBU
 golang.org/x/tools v0.0.0-20200515204822-0aa9f2fd802d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
 golang.org/x/tools v0.0.0-20200515220128-d3bf790afa53 h1:vmsb6v0zUdmUlXfwKaYrHPPRCV0lHq/IwNIf0ASGjyQ=
 golang.org/x/tools v0.0.0-20200515220128-d3bf790afa53/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
+golang.org/x/tools v0.0.0-20200519205726-57a9e4404bf7 h1:nm4zDh9WvH4jiuUpMY5RUsvOwrtTVVAsUaCdLW71hfY=
+golang.org/x/tools v0.0.0-20200519205726-57a9e4404bf7/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
 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-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
diff --git a/rule/empty-block.go b/rule/empty-block.go
index 4eb0ce8..fbec4d9 100644
--- a/rule/empty-block.go
+++ b/rule/empty-block.go
@@ -2,7 +2,6 @@ package rule
 
 import (
 	"go/ast"
-	"go/types"
 
 	"github.com/mgechev/revive/lint"
 )
@@ -18,12 +17,7 @@ func (r *EmptyBlockRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure
 		failures = append(failures, failure)
 	}
 
-	err := file.Pkg.TypeCheck()
-	if err != nil {
-		panic("unable to type check " + file.Name + ":" + err.Error())
-	}
-
-	w := lintEmptyBlock{make(map[*ast.BlockStmt]bool, 0), file.Pkg, onFailure}
+	w := lintEmptyBlock{make(map[*ast.BlockStmt]bool, 0), onFailure}
 	ast.Walk(w, file.AST)
 	return failures
 }
@@ -35,7 +29,6 @@ func (r *EmptyBlockRule) Name() string {
 
 type lintEmptyBlock struct {
 	ignore    map[*ast.BlockStmt]bool
-	pkg       *lint.Package
 	onFailure func(lint.Failure)
 }
 
@@ -48,10 +41,14 @@ func (w lintEmptyBlock) Visit(node ast.Node) ast.Visitor {
 		w.ignore[n.Body] = true
 		return w
 	case *ast.RangeStmt:
-		t := w.pkg.TypeOf(n.X)
-
-		if _, ok := t.(*types.Chan); ok {
-			w.ignore[n.Body] = true
+		if len(n.Body.List) == 0 {
+			w.onFailure(lint.Failure{
+				Confidence: 0.9,
+				Node:       n,
+				Category:   "logic",
+				Failure:    "this block is empty, you can remove it",
+			})
+			return nil // skip visiting the range subtree (it will produce a duplicated failure)
 		}
 	case *ast.BlockStmt:
 		if !w.ignore[n] && len(n.List) == 0 {


Test patch:
diff --git a/testdata/empty-block.go b/testdata/empty-block.go
index 81b7262..d750157 100644
--- a/testdata/empty-block.go
+++ b/testdata/empty-block.go
@@ -35,9 +35,9 @@ func g(f func() bool) {
 
 	}
 
-	// issue 386
+	// issue 386, then overwritten by issue 416
 	var c = make(chan int)
-	for range c {
+	for range c { // MATCH /this block is empty, you can remove it/
 	}
 
 	var s = "a string"