segmentio / golines

A golang formatter that fixes long lines
MIT License
916 stars 58 forks source link

golines does not shorten index expressions in declarations #128

Open bgimby opened 5 months ago

bgimby commented 5 months ago

golines will shorten a declaration like this:

foo := longlistfunc(bigarg, otherbigarg, verylongarg, veryverylongarg, veryveryverylongarg, extremelylongarg)

to

foo := longlistfunc(
    bigarg,
    otherbigarg,
    verylongarg,
    veryverylongarg,
    veryveryverylongarg,
    extremelylongarg,
)

I would expect it to similarly shorten a declaration like

foo := longlistfunc(bigarg, otherbigarg, verylongarg, veryverylongarg, veryveryverylongarg, extremelylongarg)[0]

to

foo := longlistfunc(
    bigarg,
    otherbigarg,
    verylongarg,
    veryverylongarg,
    veryveryverylongarg,
    extremelylongarg,
)[0]

but it is left alone. This appears to be due to formatExpr not supporting index expressions. It results in a debug message like

Got an expression type that can't be shortened: *dst.IndexExpr
mlschechter commented 3 weeks ago

Also seeing this bug; it's very confusing, and causing issues with the use of the golangci-lint linter lll.

@yolken-segment - Is there anything preventing a fix for this issue from moving forward?