Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with 'go fmt' in loading files #26

Closed
Freeaqingme opened this issue Jun 29, 2019 · 2 comments
Closed

Incompatibility with 'go fmt' in loading files #26

Freeaqingme opened this issue Jun 29, 2019 · 2 comments

Comments

@Freeaqingme
Copy link

Freeaqingme commented Jun 29, 2019

My Makefile used to say do this:

 .PHONY: fmt
 fmt:
       go get golang.org/x/tools/cmd/goimports
       ./bin/goimports -w .
       go fmt ./...

I've now substituted that by:

 .PHONY: fmt
 fmt:
       go get mvdan.cc/gofumpt
       go get mvdan.cc/gofumpt/gofumports
       ./bin/gofumports -w .
       ./bin/gofumpt  ./...

When I run make fmt, I get this output:

$ make fmt
go get mvdan.cc/gofumpt
go: finding mvdan.cc/gofumpt latest
go get mvdan.cc/gofumpt/gofumports
go: finding mvdan.cc/gofumpt/gofumports latest
go: finding mvdan.cc/gofumpt latest
./bin/gofumports -w .
./bin/gofumpt  ./...
stat ./...: no such file or directory
Makefile:26: recipe for target 'fmt' failed
make: *** [fmt] Error 2

It appears however as if gofumpt did reformat quite a bunch of files nonetheless, but still it should not generate an error.

@Freeaqingme Freeaqingme changed the title Incompatibility with 'go fmt' Incompatibility with 'go fmt' in loading files Jun 29, 2019
@mvdan
Copy link
Owner

mvdan commented Jun 29, 2019

Perhaps the README is unclear - this is a gofmt replacement, not a go fmt replacement. go fmt works on packages, while gofmt works on files and directories.

A drop-in replacement for go fmt would be quite a lot of work, as I'd have to copy a huge chunk of code from the go tool. It's also a bit unnecessary, because I believe that go fmt ends up calling gofmt under the hood.

You likely want to do gofumpt -w . instead just like you do with goimports. Note that running the two tools is a bit redundant, though - gofumports -w . should be everything you need.

@mvdan mvdan closed this as completed Jun 29, 2019
@Freeaqingme
Copy link
Author

Thanks for clarifying. '-w .' works just fine indeed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants