Add --expand mode
Add an Expand bool field to Config and an --expand CLI flag.
Call arguments, arrays, slices, unkeyed structs
With --expand: if the condensed form doesn't fit within MaxLen, expand to one element per line.
// fits on one line - condense
f(a, b, c)
// doesn't fit - expand
f(
a,
b,
c,
)
Keyed structs and maps (first-element rule)
With --expand:
- First element on same line + fits within
MaxLen - condense
- First element on same line + doesn't fit - expand to one field per line
- First element on own line - expand to one field per line
// first element on same line & fits - condense
Person{Name: "John", Age: 30}
// first element on same line & doesn't fit / first element on own line - expand
Person{
Name: "John",
Age: 30,
}
Function signatures
With --expand: try to find the most condensed signature that fits within MaxLen. Start fully condensed, then progressively expand components. Condensing is prioritised for type params first, then returns, then params - so params are expanded first when space is needed.
- Try fully condensed
- If it doesn't fit, expand params (keep returns and type params condensed)
- If it still doesn't fit, also expand returns
- If it still doesn't fit, also expand type params
// fits on one line - fully condensed
func process(ctx context.Context, input string) (string, error) {
// doesn't fit - expand params, keep returns condensed
func process(
ctx context.Context,
input string,
) (string, error) {
// still doesn't fit - also expand returns
func process(
ctx context.Context,
input string,
) (
string,
error,
) {
Add
--expandmodeAdd an
Expand boolfield toConfigand an--expandCLI flag.Call arguments, arrays, slices, unkeyed structs
With
--expand: if the condensed form doesn't fit withinMaxLen, expand to one element per line.Keyed structs and maps (first-element rule)
With
--expand:MaxLen- condenseFunction signatures
With
--expand: try to find the most condensed signature that fits withinMaxLen. Start fully condensed, then progressively expand components. Condensing is prioritised for type params first, then returns, then params - so params are expanded first when space is needed.