Skip to content

Add --expand mode #57

Description

@abemedia

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.

  1. Try fully condensed
  2. If it doesn't fit, expand params (keep returns and type params condensed)
  3. If it still doesn't fit, also expand returns
  4. 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,
) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions