This repository was archived by the owner on Dec 19, 2025. It is now read-only.
Fix line splitting for statements with init clauses and nested struct…#179
Open
mwalkerrvw wants to merge 3 commits into
Open
Fix line splitting for statements with init clauses and nested struct…#179mwalkerrvw wants to merge 3 commits into
mwalkerrvw wants to merge 3 commits into
Conversation
… 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… 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:
If/for/switch statements with initialization clauses
Struct literal elements after parent has been split
Added test fixtures for all new cases:
Co-authored-by: Cursor (claude-4.5-opus-high)