Skip to content

cmd/gofmt: ignore wildcards in gofmt -r #7870

@joeshaw

Description

@joeshaw
go version go1.2.1 darwin/amd64

I love the wildcard feature of gofmt -r, but it is also idiomatic to use single
character identifiers in Go code.  This makes it difficult to perform rewrites in
certain cases.

Suppose you have a file like http://play.golang.org/p/_6CvVWgy1v and you wanted to
change only the instance of f.Write().  If you ran gofmt -d -r 'f.Write([]byte(x)) ->
f.WriteString(x)', you would write both the f.Write() and g.Write() due to f being
interpreted as a wildcard.

I have a patch which adds a -i argument to gofmt to prevent one or more identifiers from
being interpreted as a wildcard, which I'll submit shortly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions