-
Notifications
You must be signed in to change notification settings - Fork 18k
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
go/printer: Fprintf uses different settings than go fmt #16963
Comments
I've signed the CLA and happy to submit a fix, but not sure if this would count as a breaking API change, or is desirable. |
/cc @griesemer |
Changing this seems reasonable to me. In general, we shouldn't make breaking changes to the format, but since it would be to match what |
@griesemer - thoughts? Maybe I should just submit a patch? |
@kevinburke My apologies but I haven't looked into this yet as it doesn't seem urgent. I will look into this in the next couple of days. |
@kevinburke I agree there's a discrepancy. The intention behind the printer's default settings was to produce tab-aligned output. gofmt's fine-tuning (using blanks for all alignment but indentation) came later. (There was a long period of trial and error with gofmt's settings before it eventually settled to what we have now). I'd be somewhat reluctant to change the settings here simply because I don't know how much code depends on what's here now. Instead, I'd recommend that you use go/format (format.Node) instead of printer.Fprint. It has the same signature and it supposed to produce gofmt-compliant output. If you're ok with this answer I'll close this issue. Otherwise, please raise your objections. Thanks. |
Maybe documentation somewhere saying a short version of that? |
CL https://golang.org/cl/29790 mentions this issue. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.7
What operating system and processor architecture are you using (
go env
)?All
What did you do?
If I write a Go file with go/printer.Fprintf, structs get printed like this - I've replaced the tab characters with
\t
so it's clear what is going on.If you immediately run
go fmt ./...
on the file, some of the tabs are replaced by spaces:go/printer.Fprintf
uses the following default printer.Config argument:However,
go fmt
uses this config argument:What did you expect to see?
I expect the two "default" functions to print the file the same way
What did you see instead?
One prints with tabs in the middle and one doesn't. This led to a lot of thrash when running anything automated over the codebase; I noticed this first as part of the investigation for Shyp/bump_version#1.
Far more people run
go fmt
than write AST parsing/hacking functions, so it seems like the fix, if there is to be one, should be to haveprinter.Fprintf
match thego fmt
behavior.The text was updated successfully, but these errors were encountered: