Ask questionsbreak long lines when it's appropriate to do so
Howdie, love your work, and just stumbled across this which also looks awesome :)
I use prettier with JavaScript, and cargo fmt with Rust, and they both automatically (and consistently) break up long lines
Example func:
func somethingTooLong(ctx context.Context, longArgument string, anotherOne func(time.Duration) bool) (int, error) {
// foo
}
func somethingTooLong(
ctx context.Context,
longArgument string,
anotherOne func(time.Duration) bool
) (int, error) {
// foo
}
gofmt doesn't do this, but it also doesn't undo it where I've done this manually, so at least this particular example is gofmt-compatible
Answer
questions
mvdan
I've been trying to keep the env var on at all times, and I've been finding it's a tiny bit too aggressive - especially on indented code. For example, it did this change:
typeInfo := info.TypeOf(x)
- if typeInfo != types.Typ[types.String] && typeInfo != types.Typ[types.UntypedString] {
+ if typeInfo != types.Typ[types.String] &&
+ typeInfo != types.Typ[types.UntypedString] {
return true
}
This definitely feels wrong. The indented line does reach to column 110 if we count tabs as 8 columns, but the non-indented line is just 86 characters, and we end up with two tiny lines of 41 and 44 non-indented characters.
The new format is not wrong per se, but I lean towards the old format, and I don't think there's anything wrong with it. I think it falls under "goes over the limit, but splitting the line isn't better".
I'll probably tweak the heuristic to be a bit less aggressive on indented lines.
Related questions
No questions were found.