Skip to content

Commit

Permalink
Wrap Long List of Method Paramters
Browse files Browse the repository at this point in the history
  • Loading branch information
cwarden committed Dec 15, 2023
1 parent 11d239f commit 202dce3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions formatter/visitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,11 +1265,19 @@ func (v *FormatVisitor) VisitFormalParameters(ctx *parser.FormalParametersContex
if list == nil {
return "()"
}
wrap := v.wrap || (len(ctx.GetText()) > 40 && len(list.AllFormalParameter()) > 2) || len(ctx.GetText()) > 60
for _, p := range list.AllFormalParameter() {
params = append(params, v.visitRule(p).(string))
if wrap {
params = append(params, v.indent(v.visitRule(p).(string)))
} else {
params = append(params, v.visitRule(p).(string))
}
}
if wrap {
return fmt.Sprintf("(\n%s\n)", strings.Join(params, ",\n"))
} else {
return fmt.Sprintf("(%s)", strings.Join(params, ", "))
}
val := fmt.Sprintf("(%s)", strings.Join(params, ", "))
return val
}

func (v *FormatVisitor) VisitAnnotation(ctx *parser.AnnotationContext) interface{} {
Expand Down

0 comments on commit 202dce3

Please sign in to comment.