-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/gofmt: inconsistent formatting of spacing around operators #34426
Comments
I believe that this is by design, but has nothing to do with the I'll leave it open in case @griesemer has anything to add. |
This has been like this probably since the early days of gofmt. For comparison, formatting of various expressions:
I agree that there's little difference between a list of composite literal elements and parameter lists and this is an inconsistency. It's not clear that we should change it as it would cause quite a bit of churn. If we do, we may want to combine it with some more gofmt cleanups/improvements. |
Related: #11497 |
Concatenating strings in an assignment requires spaces around the |
Well here's a sloppy patch for the issue. It's enabled with a somewhat arbitrary "-o" option. Personally, I think gofmt should have a library of configurable style options and then expose each of the predefined options such that they can be mutated. For example, Attempting to dictate to the masses precisely how thine code shall be formatted is a bad practice. There's nothing wrong with standards and style guides, but not allowing for alternatives comes off as a bit dictatorial or rigid.
|
I just bumped into this one due to a merge request I was doing that the manager pointed at all the squashed + operators in a section of code - I use gofmt pretty much religiously - and actually from a little probing and looking I've discovered that this unwanted squashing together (I think most will agree it's not as readable) only happens inside a parameter list for a function call and only if there is more than one parameter. I guess the logic is that this groups the parameters more clearly, but I don't think it should be done this way. I also don't think it will 'break' as much code as it (as far as I can tell) only affects function calls and structured literals (I think yes also struct and slice literals). I'm in the process of persuading my manager that gofmt solves more problems than it creates, I don't imagine this is a high priority. In any case, many go users use gofmt as a preparation step before running a linter, but it would only be linters that would break CI/CD pipelines, but, because it would be a pervasive, though trivial change I can understand why it might be considered to be a 2.0 change. But because gofmt does it I doubt there is one linter that flags this concatenation as an error. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, tested with
format
button on https://play.golang.org/p/Ei6Hu4QqAHaWhat operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Operators inside function calls are inconsistently formatted depending if they are inside
append
or not.What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: