Open dbarnett opened 7 years ago
FWIW, goimports is more than a "formatter" and technically is not a "gofmt executable". If we run into a lot of other gotchas like this we may want to reconsider how we're hacking goimports support into codefmt.
Another idea is to cd before running goimports (or whatever tool is configured in gofmt_executable), but it's a bit of a hack when there's already a --srcdir
option supported and might have corner case issues (like if you're writing a new file in a subdirectory that doesn't exist yet).
BTW, despite its name, --srcdir
accepts the full file path including filename, not just the dir (at least since 2016). We should make it invoke goimports --srcdir=foo/bar.go
instead of goimports --srcdir=foo/
.
When using goimports via our gofmt formatter as suggested in the docs, the goimports path-based inference doesn't work because we don't tell goimports about the path. It does support a
--srcdir
argument we could pass.We'd have to make it conditional and detect
basename(gofmt_executable) == 'goimports'
or something like that because gofmt doesn't support any--srcdir
arg.