diff --git a/_fixtures/struct_split.go b/_fixtures/struct_split.go new file mode 100644 index 0000000..b30618c --- /dev/null +++ b/_fixtures/struct_split.go @@ -0,0 +1,5 @@ +package fixtures + +var _ = &mybigtype{ + arg1: "biglongstring1", arg2: longfunctioncall(param1), arg3: []string{"list1"}, arg4: bigvariable, +} diff --git a/_fixtures/struct_split__exp.go b/_fixtures/struct_split__exp.go new file mode 100644 index 0000000..2bd9ddb --- /dev/null +++ b/_fixtures/struct_split__exp.go @@ -0,0 +1,8 @@ +package fixtures + +var _ = &mybigtype{ + arg1: "biglongstring1", + arg2: longfunctioncall(param1), + arg3: []string{"list1"}, + arg4: bigvariable, +} diff --git a/annotation.go b/annotation.go index 0790a30..f93557b 100644 --- a/annotation.go +++ b/annotation.go @@ -2,10 +2,12 @@ package main import ( "fmt" + "reflect" "strconv" "strings" "github.com/dave/dst" + log "github.com/sirupsen/logrus" ) const annotationPrefix = "// __golines:shorten:" @@ -51,6 +53,12 @@ func HasAnnotationRecursive(node dst.Node) bool { } switch n := node.(type) { + case *dst.CompositeLit: + for _, elt := range n.Elts { + if HasAnnotationRecursive(elt) { + return true + } + } case *dst.FuncDecl: if n.Type != nil && n.Type.Params != nil { for _, item := range n.Type.Params.List { @@ -79,6 +87,8 @@ func HasAnnotationRecursive(node dst.Node) bool { return true } } + default: + log.Debugf("Couldn't analyze type for annotations: %+v", reflect.TypeOf(n)) } return false diff --git a/shortener.go b/shortener.go index 144d78f..4d32c46 100644 --- a/shortener.go +++ b/shortener.go @@ -527,7 +527,7 @@ func (s *Shortener) formatExpr(expr dst.Expr, force bool, isChain bool) { s.formatExpr(e.Fun, shouldShorten, isChain) } case *dst.CompositeLit: - if shouldShorten { + if shouldShorten || HasAnnotationRecursive(e) { for i, element := range e.Elts { if i == 0 { element.Decorations().Before = dst.NewLine