Skip to content
Permalink
Browse files

don't turn "var _ = x" into "_ := x"

As correctly pointed out by Michael McLoughlin, that turns the statement
invalid.

Fixes #32.
  • Loading branch information...
mvdan committed Jul 29, 2019
1 parent 63d17d2 commit 96300e3d49fbb3b7bc9c6dc74f8a5cc0ef46f84b
Showing with 9 additions and 1 deletion.
  1. +5 −1 internal/gofumpt.go
  2. +4 −0 testdata/scripts/short-decl.txt
@@ -231,13 +231,17 @@ func (f *fumpter) applyPre(c *astutil.Cursor) {
if spec.Type != nil {
break // e.g. var name Type
}
tok := token.ASSIGN
names := make([]ast.Expr, len(spec.Names))
for i, name := range spec.Names {
names[i] = name
if name.Name != "_" {
tok = token.DEFINE
}
}
c.Replace(&ast.AssignStmt{
Lhs: names,
Tok: token.DEFINE,
Tok: tok,
Rhs: spec.Values,
})

@@ -14,6 +14,8 @@ func f() {

var typeAndVar T = x

var _ = unused

var (
aligned = x
vars = y
@@ -33,6 +35,8 @@ func f() {

var typeAndVar T = x

_ = unused

var (
aligned = x
vars = y

0 comments on commit 96300e3

Please sign in to comment.
You can’t perform that action at this time.