Go's dependency management mechanism treats vendor directory specially to import external packages.
Currently, the gofmt command formats files even if those are managed under the vendor.
I think gofmt command should ignore the files under the vendor.
How does it feel?
(I wrote PoC patch here: https://github.com/golang/go/compare/master...moznion:gofmt_ignore_vendor_dir?expand=1)
Have you tried go fmt? gofmt works on files and directories, not packages, so I'm not sure if it should treat vendor directories in a special way.
/cc @griesemer
Yes, I tried to use (and also I'm using) go fmt command. It usually works no problems.
However, in my understand go fmt is a subset of gofmt command so go fmt is limited in function compared with "gofmt".
Actually, go fmt --help said as follows:
To run gofmt with specific options, run gofmt itself.
Therefore, I feel it is convenient if gofmt also ignores the vendor (or provide such an option).
It is not a subset, it is a wrapper. The important difference between go fmt and gofmt is the list of packages passed to the binary by go fmt, a list that for example excludes vendored packages.
In addition to the discussion above.
gofmt is able to simplify code, that's a terrific feature.
There is need for formating and simplification code at the same time ( excluding vendor ) .
It would be great to enable somehow the simplification feature in go fmt in that case.
It is not a subset, it is a wrapper. The important difference between go fmt and gofmt is the list of packages passed to the binary by go fmt, a list that for example excludes vendored packages.
Yes, it鈥檚 right. My expression was wrong, but I understand the behavior of both.
There is need for formating and simplification code at the same time ( excluding vendor ) .
It would be great to enable somehow the simplification feature in go fmt in that case.
That is a good point.
I think that it is good if the function of the go fmt is expanded with options or other ways. I don't have a reason to stick to gofmt.
If there are plans to make such changes, I have an intention to contribute to it.
(Additionally, if that is the case; I feel I want a dryrun option for the go fmt command)
If there is a resolution to this, it should be to let go fmt have access to all the flags of gofmt, not to change gofmt to track changes in the go command.
If there is a resolution to this, it should be to let go fmt have access to all the flags of gofmt, not to change gofmt to track changes in the go command.
I agree this.
I tried writing a PcC code based on this opinion: https://github.com/golang/go/compare/master...moznion:fmt_gofmt_flag?expand=1
@moznion could you please send your changes using regular flow, otherwise I'm afraid it wouldn't be reviewed
https://golang.org/doc/contribute.html
@superstas Sure, I'll do that.
Change https://golang.org/cl/70030 mentions this issue: cmd/gofmt: Make all of gofmt's functions to be available fromgo fmtcommand
I really hope that vendor directories will diminish in importance once proper package management arrives. Let's just not do anything special here for gofmt of vendor directories.
Most helpful comment
I really hope that vendor directories will diminish in importance once proper package management arrives. Let's just not do anything special here for gofmt of vendor directories.