Skip to content

Conversation

@mwalkerrvw
Copy link

@mwalkerrvw mwalkerrvw commented Dec 12, 2025

… literals

NOTE: I haven't manually verified these changes. I asked Cursor to make them and they addressed the cases I had that golines was previously missing

This change fixes golines not properly splitting long lines in several cases:

  1. If/for/switch statements with initialization clauses

    • Previously, 'if err := longFunctionCall(...); err != nil' would not split the function call arguments even when the line exceeded max length
    • Now properly handles st.Init for IfStmt, ForStmt, and SwitchStmt
  2. Struct literal elements after parent has been split

    • When a struct literal was already on its own line but its field initializers were too long, they weren't being split
    • Added CompositeLit support to HasAnnotationRecursive to detect when elements have annotations
    • Updated CompositeLit handling to check HasAnnotationRecursive

Added test fixtures for all new cases:

  • if_init.go: if statements with long init clauses
  • for_init.go: for statements with long init clauses
  • switch_init.go: switch statements with long init clauses
  • composite_lit.go: struct literals with long field lines

Co-authored-by: Cursor (claude-4.5-opus-high)

… literals

This change fixes golines not properly splitting long lines in several cases:

1. If/for/switch statements with initialization clauses
   - Previously, 'if err := longFunctionCall(...); err != nil' would not
     split the function call arguments even when the line exceeded max length
   - Now properly handles st.Init for IfStmt, ForStmt, and SwitchStmt

2. Struct literal elements after parent has been split
   - When a struct literal was already on its own line but its field
     initializers were too long, they weren't being split
   - Added CompositeLit support to HasAnnotationRecursive to detect when
     elements have annotations
   - Updated CompositeLit handling to check HasAnnotationRecursive

Added test fixtures for all new cases:
- if_init.go: if statements with long init clauses
- for_init.go: for statements with long init clauses
- switch_init.go: switch statements with long init clauses
- composite_lit.go: struct literals with long field lines

Co-authored-by: Cursor (claude-4.5-opus-high)
Single-line function literals like 'func(a, b T) int { return longExpr }'
were not being expanded when the line exceeded max length.

Now expands the body statements onto separate lines when needed:
  func(a, b T) int {
      return longExpr
  }

Added test fixture: func_lit_body.go

Co-authored-by: Cursor (claude-4.5-opus-high)
When a chained method call line is still too long after splitting at dots,
the arguments within that call are now also split onto separate lines.

Previously, arguments in chained calls were always processed with
shouldShorten=false, meaning they would never be split even when the line
exceeded max length.

The fix:
- Continue processing in annotateLongLines even when line length hasn't
  decreased (was causing premature stop)
- Check for annotations on the SelectorExpr and method Ident, not just
  the CallExpr (DST attaches mid-chain comments to the Ident)
- Split arguments when the specific method call is annotated as too long

Added test fixture: chained_args.go
Updated: chained_calls__exp.go (now correctly splits more long lines)

Co-authored-by: Cursor (claude-4.5-opus-high)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant