Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions _fixtures/chained_args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fixtures

import "strings"

type Logger struct{}

func (l Logger) Str(k, v string) Logger { return l }
func (l Logger) Msgf(format string, args ...interface{}) {}

func Map[T, U any](collection []T, fn func(T, int) U) []U {
return nil
}

func testChainedArgs() {
messages := []string{}
l := Logger{}

// Long argument inside a chained method call - should split the arguments
l.Str("key", strings.Join(Map(messages, func(message string, _ int) string { return message + message + message }), ",")).
Msgf("Message with format %s", "arg")
}

21 changes: 21 additions & 0 deletions _fixtures/chained_args__exp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fixtures

import "strings"

type Logger struct{}

func (l Logger) Str(k, v string) Logger { return l }
func (l Logger) Msgf(format string, args ...interface{}) {}

func Map[T, U any](collection []T, fn func(T, int) U) []U {
return nil
}

func testChainedArgs() {
messages := []string{}
l := Logger{}

// Long argument inside a chained method call - should split the arguments
l.Str("key", strings.Join(Map(messages, func(message string, _ int) string { return message + message + message }), ",")).
Msgf("Message with format %s", "arg")
}
11 changes: 9 additions & 2 deletions _fixtures/chained_calls__exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ func ChainedCalls() {
NewChain().ChainCall(
"a really really really really really long argument4",
"another really really really really really long argument4",
fmt.Sprintf("%v", "this is a long method"),
fmt.Sprintf(
"%v",
"this is a long method",
),
).
ChainCall("a really really really really really long argument5", "another really really really really really long argument5", "a third really really really really really long argument5").
ChainCall(
"a really really really really really long argument5",
"another really really really really really long argument5",
"a third really really really really really long argument5",
).
ChainCall("a", "b", fmt.Sprintf("%v", "this is a long method"))
NewChain().ChainCall("a", "b", "c").ChainCall("d", "e", "f")
NewChain().ChainCall("a", "b", "c").
Expand Down
24 changes: 24 additions & 0 deletions _fixtures/composite_lit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fixtures

type Request struct {
Entity string
Fields []string
VersionCheck bool
}

func update(ctx string, req Request) error {
return nil
}

func testCompositeLit() {
// Struct literal with long field line that should be split
update(
"ctx",
Request{
Entity: "enrollment", Fields: []string{"field1", "field2", "field3", "field4"}, VersionCheck: true,
},
)

// Struct literal with nested long slice
update("ctx", Request{Entity: "test", Fields: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}, VersionCheck: false})
}
33 changes: 33 additions & 0 deletions _fixtures/composite_lit__exp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package fixtures

type Request struct {
Entity string
Fields []string
VersionCheck bool
}

func update(ctx string, req Request) error {
return nil
}

func testCompositeLit() {
// Struct literal with long field line that should be split
update(
"ctx",
Request{
Entity: "enrollment",
Fields: []string{"field1", "field2", "field3", "field4"},
VersionCheck: true,
},
)

// Struct literal with nested long slice
update(
"ctx",
Request{
Entity: "test",
Fields: []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"},
VersionCheck: false,
},
)
}
18 changes: 18 additions & 0 deletions _fixtures/for_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fixtures

func getValue(a, b, c, d, e string) int {
return 0
}

func testForInit() {
// For statement with long init clause
for i := getValue("argument1", "argument2", "argument3", "argument4", "argument5"); i < 10; i++ {
println(i)
}

// For with long condition
for j := 0; j < getValue("value1", "value2", "value3", "value4", "value5"); j++ {
println(j)
}
}

23 changes: 23 additions & 0 deletions _fixtures/for_init__exp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fixtures

func getValue(a, b, c, d, e string) int {
return 0
}

func testForInit() {
// For statement with long init clause
for i := getValue(
"argument1",
"argument2",
"argument3",
"argument4",
"argument5",
); i < 10; i++ {
println(i)
}

// For with long condition
for j := 0; j < getValue("value1", "value2", "value3", "value4", "value5"); j++ {
println(j)
}
}
24 changes: 24 additions & 0 deletions _fixtures/func_lit_body.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fixtures

type LongTypeName struct {
Value int
}

func (l LongTypeName) Compare(other LongTypeName) int {
return l.Value - other.Value
}

func SortFunc[T any](collection []T, fn func(T, T) int) {}

func testFuncLitBody() {
// Function literal with long body that should be expanded
items := []LongTypeName{}
SortFunc(
items,
func(a, b LongTypeName) int { return a.Compare(b) + a.Compare(b) + a.Compare(b) + a.Compare(b) },
)

// Single line function literal that fits - should stay as is
SortFunc(items, func(a, b LongTypeName) int { return a.Compare(b) })
}

25 changes: 25 additions & 0 deletions _fixtures/func_lit_body__exp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fixtures

type LongTypeName struct {
Value int
}

func (l LongTypeName) Compare(other LongTypeName) int {
return l.Value - other.Value
}

func SortFunc[T any](collection []T, fn func(T, T) int) {}

func testFuncLitBody() {
// Function literal with long body that should be expanded
items := []LongTypeName{}
SortFunc(
items,
func(a, b LongTypeName) int {
return a.Compare(b) + a.Compare(b) + a.Compare(b) + a.Compare(b)
},
)

// Single line function literal that fits - should stay as is
SortFunc(items, func(a, b LongTypeName) int { return a.Compare(b) })
}
20 changes: 20 additions & 0 deletions _fixtures/if_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package fixtures

func doSomething(a, b, c, d, e string) error {
return nil
}

func testIfInit() {
// If statement with long init clause
if err := doSomething("argument1", "argument2", "argument3", "argument4", "argument5"); err != nil {
println(err)
}

// Nested if with long init
if x := doSomething("value1", "value2", "value3", "value4", "value5"); x == nil {
if y := doSomething("nested1", "nested2", "nested3", "nested4", "nested5"); y == nil {
println("both nil")
}
}
}

25 changes: 25 additions & 0 deletions _fixtures/if_init__exp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fixtures

func doSomething(a, b, c, d, e string) error {
return nil
}

func testIfInit() {
// If statement with long init clause
if err := doSomething(
"argument1",
"argument2",
"argument3",
"argument4",
"argument5",
); err != nil {
println(err)
}

// Nested if with long init
if x := doSomething("value1", "value2", "value3", "value4", "value5"); x == nil {
if y := doSomething("nested1", "nested2", "nested3", "nested4", "nested5"); y == nil {
println("both nil")
}
}
}
18 changes: 18 additions & 0 deletions _fixtures/switch_init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fixtures

func getType(a, b, c, d, e, f string) int {
return 0
}

func testSwitchInit() {
// Switch statement with long init clause
switch v := getType("argument1", "argument2", "argument3", "argument4", "argument5", "argument6"); v {
case 1:
println("one")
case 2:
println("two")
default:
println("other")
}
}

24 changes: 24 additions & 0 deletions _fixtures/switch_init__exp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fixtures

func getType(a, b, c, d, e, f string) int {
return 0
}

func testSwitchInit() {
// Switch statement with long init clause
switch v := getType(
"argument1",
"argument2",
"argument3",
"argument4",
"argument5",
"argument6",
); v {
case 1:
println("one")
case 2:
println("two")
default:
println("other")
}
}
6 changes: 6 additions & 0 deletions annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func HasAnnotationRecursive(node dst.Node) bool {
return true
}
}
case *dst.CompositeLit:
for _, elt := range n.Elts {
if HasAnnotation(elt) {
return true
}
}
}

return false
Expand Down
Loading