Skip to content

Commit

Permalink
FormatOps: force config style for all call sites
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jul 25, 2022
1 parent 154fe02 commit a1f7c1a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1157,12 +1157,12 @@ class FormatOps(
case FormatToken(
left: T.LeftParen,
_,
FormatToken.LeftOwner(app: Term.Apply)
FormatToken.LeftOwner(app @ CallArgsForConfigStyle(args))
)
if app.args.lengthCompare(minArgs) >= 0 &&
if args.lengthCompare(minArgs) >= 0 &&
distance(left, matching(left)) > maxDistance =>
forces += app
app.args.foreach { arg =>
args.foreach { arg =>
clearQueues += hash(tokens.getHead(arg).left)
}
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,15 @@ object TreeOps {
splitCallIntoParts.lift(tree)
}

object CallArgsForConfigStyle {
def unapply(tree: Tree): Option[Seq[Tree]] = Some(tree match {
case t: Term.Apply => t.args
case t: Init => t.argss.flatten
case t: Term.ApplyUsing => t.args
case _ => Seq.empty
}).filter(_.nonEmpty)
}

type DefnParts = (Seq[Mod], Name, Seq[Type.Param], Seq[Seq[Term.Param]])
val splitDefnIntoParts: PartialFunction[Tree, DefnParts] = {
// types
Expand Down
43 changes: 42 additions & 1 deletion scalafmt-tests/src/test/resources/default/Apply.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1854,4 +1854,45 @@ object a {
}
}
>>>
FormatTests:54 [e]: org.scalafmt.Error$SearchStateExploded: Search state exploded on ',∙rs[750:759]', line 31
object a {
def createFoo(rs: ResultSet): Foo = {
new Foo(
rs.getDouble(1),
rs.getDouble(2),
rs.getDouble(3),
rs.getDouble(4),
rs.getDouble(5),
rs.getDouble(6),
rs.getDouble(7),
rs.getDouble(8),
rs.getDouble(9),
rs.getDouble(10),
rs.getDouble(11),
rs.getDouble(12),
rs.getDouble(13),
rs.getDouble(14),
rs.getDouble(15),
rs.getDouble(16),
rs.getDouble(17),
rs.getDouble(18),
rs.getDouble(19),
rs.getDouble(20),
rs.getDouble(21),
rs.getDouble(22),
rs.getDouble(23),
rs.getDouble(24),
rs.getDouble(25),
rs.getDouble(26),
rs.getDouble(27),
rs.getDouble(28),
rs.getDouble(29),
rs.getDouble(30),
rs.getDouble(31),
rs.getDouble(32),
rs.getDouble(33),
rs.getDouble(34),
rs.getDouble(35),
rs.getDouble(36)
)
}
}

0 comments on commit a1f7c1a

Please sign in to comment.