diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index 7642645ff3..fe6f299840 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -1281,6 +1281,17 @@ class FormatOps( enclosed: Boolean = true, ): Option[SelectLike] = findPrevSelectAndApply(tree.qual, enclosed)._1 + @tailrec + final def findFirstSelect( + tree: Tree, + enclosed: Boolean, + select: Option[SelectLike] = None, + ): Option[SelectLike] = findPrevSelectAndApply(tree, enclosed) match { + case (x @ Some(prevSelect), _) => + findFirstSelect(prevSelect.qual, enclosed, x) + case _ => select + } + @tailrec private def findLastApplyAndNextSelectEnclosed( tree: Tree, @@ -2161,7 +2172,9 @@ class FormatOps( case x: Term.Block => getBlockWithNonSingleTermStat(x) case x: Tree.CasesBlock => Some(x) case _ => None - }).flatMap(x => WithStats(nft, x.stats.headOption, b, Some(t))) + }).fold(getMaybeFewerBracesSelectSplits(b))(x => + WithStats(nft, x.stats.headOption, b, Some(t)), + ) case _ => BlockImpl.create(nft) } } @@ -2350,6 +2363,40 @@ class FormatOps( getSplits(tree, forceNL, danglingKeyword) } + private def getMaybeFewerBracesSelectSplits(body: Tree)(implicit + ft: FT, + style: ScalafmtConfig, + ) = findFirstSelect(body, enclosed = true).filter(_.qual match { + case q @ (_: Term.ForClause | _: Term.ApplyInfix | + _: Term.SelectPostfix) => !isEnclosedInMatching(q) + case _ => false + }).map { selectLike => + new OptionalBracesRegion { + def splits: Option[Seq[Split]] = { + val noFbIndent = style.getFewerBraces() == Indents.FewerBraces.never + val indentLen = + if (noFbIndent) style.indent.getSignificant + else style.indent.main + style.indent.getSignificant + val dot = prev(prevNonCommentBefore(selectLike.nameFt)) + val beforeDot = prevNonCommentSameLine(dot) + val policy = Policy.End <= beforeDot ==> + Policy.onRight(dot, "NL-NOIND-SELECT") { + case Decision(`beforeDot`, ss) => ss.flatMap { s => + if ((dot eq beforeDot) && !s.isNL) None + else Some(s.deActivateFor(SplitTag.SelectChainFirstNL)) + } + case Decision(_, ss) => ss + .map(_.deActivateFor(SplitTag.SelectChainFirstNL)) + } + val nlSplit = Split(Newline2x(ft), 1, policy = policy) + .withIndent(indentLen, beforeDot, ExpiresOn.After) + Some(Seq(nlSplit)) + } + def rightBrace: Option[FT] = treeLast(body) + def owner: Option[Tree] = body.parent + } + } + private class WithStats private ( nft: FT, body: Tree, diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 65d09a8b0e..cf644b84bb 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -1735,6 +1735,8 @@ class Router(formatOps: FormatOps) { p.casesBlock case p: Term.NewAnonymous => getHeadOpt(p.templ.body) .exists(_.left.is[T.Colon]) + case _: Term.ForClause | _: Term.ApplyInfix | + _: Term.SelectPostfix => true case _ => false }) && !isEnclosedInMatching(tree) val fewerBracesLike = checkFewerBraces(thisSelect.qual) diff --git a/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces.stat b/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces.stat index 14fd767915..6eb599cea5 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces.stat @@ -2329,8 +2329,9 @@ indent.fewerBraces = never >>> @main def main() = val first = - for i <- 0 to 10 - yield i.head + for i <- 0 to 10 + yield i + .head println(first) <<< #4614 for-yield then apply, never indent.fewerBraces = never @@ -2344,9 +2345,9 @@ indent.fewerBraces = never >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) + for i <- 0 to 10 + yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, never indent.fewerBraces = never @@ -2361,10 +2362,10 @@ indent.fewerBraces = never >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) - .last + for i <- 0 to 10 + yield i + .map(_ * 2) + .last println(first) <<< #4614 for-yield then select, always indent.fewerBraces = always @@ -2378,8 +2379,9 @@ indent.fewerBraces = always >>> @main def main() = val first = - for i <- 0 to 10 - yield i.head + for i <- 0 to 10 + yield i + .head println(first) <<< #4614 for-yield then apply, always indent.fewerBraces = always @@ -2393,9 +2395,9 @@ indent.fewerBraces = always >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) + for i <- 0 to 10 + yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, always indent.fewerBraces = always @@ -2410,10 +2412,10 @@ indent.fewerBraces = always >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) - .last + for i <- 0 to 10 + yield i + .map(_ * 2) + .last println(first) <<< #4614 for-yield then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2427,8 +2429,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = val first = - for i <- 0 to 10 - yield i.head + for i <- 0 to 10 + yield i + .head println(first) <<< #4614 for-yield then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2442,9 +2445,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) + for i <- 0 to 10 + yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2459,10 +2462,10 @@ indent.fewerBraces = beforeSelect >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) - .last + for i <- 0 to 10 + yield i + .map(_ * 2) + .last println(first) <<< #4614 infix then select, never indent.fewerBraces = never @@ -2476,8 +2479,9 @@ indent.fewerBraces = never >>> @main def main() = val first = - foo :: bar :: - baz.head + foo :: bar :: + baz + .head println(first) <<< #4614 infix then apply, never indent.fewerBraces = never @@ -2489,12 +2493,12 @@ indent.fewerBraces = never .map(_ * 2) println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) +@main def main() = + val first = + foo :: bar :: baz -- .map(_ * 2) -+ .map(_ * 2) - println(first) + .map(_ * 2) + println(first) <<< #4614 infix then apply and select, never indent.fewerBraces = never === @@ -2506,14 +2510,13 @@ indent.fewerBraces = never .last println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) +@main def main() = + val first = + foo :: bar :: baz -- .map(_ * 2) -- .last -+ .map(_ * 2) -+ .last - println(first) + .map(_ * 2) + .last + println(first) <<< #4614 infix then select, always indent.fewerBraces = always === @@ -2526,8 +2529,9 @@ indent.fewerBraces = always >>> @main def main() = val first = - foo :: bar :: - baz.head + foo :: bar :: + baz + .head println(first) <<< #4614 infix then apply, always indent.fewerBraces = always @@ -2539,12 +2543,12 @@ indent.fewerBraces = always .map(_ * 2) println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .map(_ * 2) -+ .map(_ * 2) - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .map(_ * 2) + println(first) <<< #4614 infix then apply and select, always indent.fewerBraces = always === @@ -2556,14 +2560,13 @@ indent.fewerBraces = always .last println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .map(_ * 2) -- .last -+ .map(_ * 2) -+ .last - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .map(_ * 2) + .last + println(first) <<< #4614 infix then select, beforeSelect indent.fewerBraces = beforeSelect === @@ -2576,8 +2579,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = val first = - foo :: bar :: - baz.head + foo :: bar :: + baz + .head println(first) <<< #4614 infix then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2589,12 +2593,12 @@ indent.fewerBraces = beforeSelect .map(_ * 2) println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .map(_ * 2) -+ .map(_ * 2) - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .map(_ * 2) + println(first) <<< #4614 infix then apply and select, beforeSelect indent.fewerBraces = beforeSelect === @@ -2606,14 +2610,13 @@ indent.fewerBraces = beforeSelect .last println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .map(_ * 2) -- .last -+ .map(_ * 2) -+ .last - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .map(_ * 2) + .last + println(first) <<< #4614 postfix then select, never indent.fewerBraces = never === @@ -2623,16 +2626,10 @@ indent.fewerBraces = never .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main def main() = - val first = - foo bar.head - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar.head + foo bar + .head println(first) <<< #4614 postfix then apply, never indent.fewerBraces = never @@ -2643,17 +2640,10 @@ indent.fewerBraces = never .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, never indent.fewerBraces = never @@ -2665,19 +2655,11 @@ indent.fewerBraces = never .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - .last - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) - .last + foo bar + .map(_ * 2) + .last println(first) <<< #4614 postfix then select, always indent.fewerBraces = always @@ -2688,16 +2670,10 @@ indent.fewerBraces = always .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main def main() = - val first = - foo bar.head - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar.head + foo bar + .head println(first) <<< #4614 postfix then apply, always indent.fewerBraces = always @@ -2708,17 +2684,10 @@ indent.fewerBraces = always .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, always indent.fewerBraces = always @@ -2730,19 +2699,11 @@ indent.fewerBraces = always .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - .last - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) - .last + foo bar + .map(_ * 2) + .last println(first) <<< #4614 postfix then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2753,16 +2714,10 @@ indent.fewerBraces = beforeSelect .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = val first = - foo bar.head - ^ - println(first) -====== full result: ====== -@main def main() = - val first = - foo bar.head + foo bar + .head println(first) <<< #4614 postfix then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2773,17 +2728,10 @@ indent.fewerBraces = beforeSelect .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2795,17 +2743,9 @@ indent.fewerBraces = beforeSelect .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - .last - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) - .last + foo bar + .map(_ * 2) + .last println(first) diff --git a/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_fold.stat b/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_fold.stat index 5b168398b8..d95fc2f4c8 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_fold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_fold.stat @@ -2057,7 +2057,9 @@ indent.fewerBraces = never >>> @main def main() = - val first = for i <- 0 to 10 yield i.head + val first = + for i <- 0 to 10 yield i + .head println(first) <<< #4614 for-yield then apply, never indent.fewerBraces = never @@ -2071,7 +2073,9 @@ indent.fewerBraces = never >>> @main def main() = - val first = for i <- 0 to 10 yield i.map(_ * 2) + val first = + for i <- 0 to 10 yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, never indent.fewerBraces = never @@ -2086,7 +2090,9 @@ indent.fewerBraces = never >>> @main def main() = - val first = for i <- 0 to 10 yield i.map(_ * 2).last + val first = + for i <- 0 to 10 yield i + .map(_ * 2).last println(first) <<< #4614 for-yield then select, always indent.fewerBraces = always @@ -2100,7 +2106,9 @@ indent.fewerBraces = always >>> @main def main() = - val first = for i <- 0 to 10 yield i.head + val first = + for i <- 0 to 10 yield i + .head println(first) <<< #4614 for-yield then apply, always indent.fewerBraces = always @@ -2114,7 +2122,9 @@ indent.fewerBraces = always >>> @main def main() = - val first = for i <- 0 to 10 yield i.map(_ * 2) + val first = + for i <- 0 to 10 yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, always indent.fewerBraces = always @@ -2129,7 +2139,9 @@ indent.fewerBraces = always >>> @main def main() = - val first = for i <- 0 to 10 yield i.map(_ * 2).last + val first = + for i <- 0 to 10 yield i + .map(_ * 2).last println(first) <<< #4614 for-yield then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2143,7 +2155,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = - val first = for i <- 0 to 10 yield i.head + val first = + for i <- 0 to 10 yield i + .head println(first) <<< #4614 for-yield then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2157,7 +2171,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = - val first = for i <- 0 to 10 yield i.map(_ * 2) + val first = + for i <- 0 to 10 yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2172,7 +2188,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = - val first = for i <- 0 to 10 yield i.map(_ * 2).last + val first = + for i <- 0 to 10 yield i + .map(_ * 2).last println(first) <<< #4614 infix then select, never indent.fewerBraces = never @@ -2186,7 +2204,9 @@ indent.fewerBraces = never >>> @main def main() = - val first = foo :: bar :: baz.head + val first = + foo :: bar :: baz + .head println(first) <<< #4614 infix then apply, never indent.fewerBraces = never @@ -2200,7 +2220,9 @@ indent.fewerBraces = never >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2) + val first = + foo :: bar :: baz + .map(_ * 2) println(first) <<< #4614 infix then apply and select, never indent.fewerBraces = never @@ -2215,7 +2237,9 @@ indent.fewerBraces = never >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2).last + val first = + foo :: bar :: baz + .map(_ * 2).last println(first) <<< #4614 infix then select, always indent.fewerBraces = always @@ -2229,7 +2253,9 @@ indent.fewerBraces = always >>> @main def main() = - val first = foo :: bar :: baz.head + val first = + foo :: bar :: baz + .head println(first) <<< #4614 infix then apply, always indent.fewerBraces = always @@ -2243,7 +2269,9 @@ indent.fewerBraces = always >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2) + val first = + foo :: bar :: baz + .map(_ * 2) println(first) <<< #4614 infix then apply and select, always indent.fewerBraces = always @@ -2258,7 +2286,9 @@ indent.fewerBraces = always >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2).last + val first = + foo :: bar :: baz + .map(_ * 2).last println(first) <<< #4614 infix then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2272,7 +2302,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = - val first = foo :: bar :: baz.head + val first = + foo :: bar :: baz + .head println(first) <<< #4614 infix then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2286,7 +2318,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2) + val first = + foo :: bar :: baz + .map(_ * 2) println(first) <<< #4614 infix then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2301,7 +2335,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2).last + val first = + foo :: bar :: baz + .map(_ * 2).last println(first) <<< #4614 postfix then select, never indent.fewerBraces = never @@ -2312,16 +2348,11 @@ indent.fewerBraces = never .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = - val first = foo bar.head - ^ - println(first) -====== full result: ====== -@main -def main() = - val first = foo bar.head + val first = + foo bar + .head println(first) <<< #4614 postfix then apply, never indent.fewerBraces = never @@ -2332,16 +2363,11 @@ indent.fewerBraces = never .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = - val first = foo bar.map(_ * 2) - ^ - println(first) -====== full result: ====== -@main -def main() = - val first = foo bar.map(_ * 2) + val first = + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, never indent.fewerBraces = never @@ -2353,16 +2379,11 @@ indent.fewerBraces = never .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main -def main() = - val first = foo bar.map(_ * 2).last - ^ - println(first) -====== full result: ====== @main def main() = - val first = foo bar.map(_ * 2).last + val first = + foo bar + .map(_ * 2).last println(first) <<< #4614 postfix then select, always indent.fewerBraces = always @@ -2373,16 +2394,11 @@ indent.fewerBraces = always .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = - val first = foo bar.head - ^ - println(first) -====== full result: ====== -@main -def main() = - val first = foo bar.head + val first = + foo bar + .head println(first) <<< #4614 postfix then apply, always indent.fewerBraces = always @@ -2393,16 +2409,11 @@ indent.fewerBraces = always .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = - val first = foo bar.map(_ * 2) - ^ - println(first) -====== full result: ====== -@main -def main() = - val first = foo bar.map(_ * 2) + val first = + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, always indent.fewerBraces = always @@ -2414,16 +2425,11 @@ indent.fewerBraces = always .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main -def main() = - val first = foo bar.map(_ * 2).last - ^ - println(first) -====== full result: ====== @main def main() = - val first = foo bar.map(_ * 2).last + val first = + foo bar + .map(_ * 2).last println(first) <<< #4614 postfix then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2434,16 +2440,11 @@ indent.fewerBraces = beforeSelect .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main -def main() = - val first = foo bar.head - ^ - println(first) -====== full result: ====== @main def main() = - val first = foo bar.head + val first = + foo bar + .head println(first) <<< #4614 postfix then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2454,16 +2455,11 @@ indent.fewerBraces = beforeSelect .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = - val first = foo bar.map(_ * 2) - ^ - println(first) -====== full result: ====== -@main -def main() = - val first = foo bar.map(_ * 2) + val first = + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2475,14 +2471,9 @@ indent.fewerBraces = beforeSelect .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main -def main() = - val first = foo bar.map(_ * 2).last - ^ - println(first) -====== full result: ====== @main def main() = - val first = foo bar.map(_ * 2).last + val first = + foo bar + .map(_ * 2).last println(first) diff --git a/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_keep.stat b/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_keep.stat index 9eef5916e8..13f4e691f9 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_keep.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_keep.stat @@ -2305,9 +2305,9 @@ indent.fewerBraces = never >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .head + for i <- 0 to 10 + yield i + .head println(first) <<< #4614 for-yield then apply, never indent.fewerBraces = never @@ -2321,9 +2321,9 @@ indent.fewerBraces = never >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) + for i <- 0 to 10 + yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, never indent.fewerBraces = never @@ -2338,10 +2338,10 @@ indent.fewerBraces = never >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) - .last + for i <- 0 to 10 + yield i + .map(_ * 2) + .last println(first) <<< #4614 for-yield then select, always indent.fewerBraces = always @@ -2355,9 +2355,9 @@ indent.fewerBraces = always >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .head + for i <- 0 to 10 + yield i + .head println(first) <<< #4614 for-yield then apply, always indent.fewerBraces = always @@ -2371,9 +2371,9 @@ indent.fewerBraces = always >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) + for i <- 0 to 10 + yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, always indent.fewerBraces = always @@ -2388,10 +2388,10 @@ indent.fewerBraces = always >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) - .last + for i <- 0 to 10 + yield i + .map(_ * 2) + .last println(first) <<< #4614 for-yield then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2405,9 +2405,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .head + for i <- 0 to 10 + yield i + .head println(first) <<< #4614 for-yield then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2421,9 +2421,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) + for i <- 0 to 10 + yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2438,10 +2438,10 @@ indent.fewerBraces = beforeSelect >>> @main def main() = val first = - for i <- 0 to 10 - yield i - .map(_ * 2) - .last + for i <- 0 to 10 + yield i + .map(_ * 2) + .last println(first) <<< #4614 infix then select, never indent.fewerBraces = never @@ -2453,12 +2453,12 @@ indent.fewerBraces = never .head println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) +@main def main() = + val first = + foo :: bar :: baz -- .head -+ .head - println(first) + .head + println(first) <<< #4614 infix then apply, never indent.fewerBraces = never === @@ -2469,12 +2469,12 @@ indent.fewerBraces = never .map(_ * 2) println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) +@main def main() = + val first = + foo :: bar :: baz -- .map(_ * 2) -+ .map(_ * 2) - println(first) + .map(_ * 2) + println(first) <<< #4614 infix then apply and select, never indent.fewerBraces = never === @@ -2486,14 +2486,13 @@ indent.fewerBraces = never .last println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) +@main def main() = + val first = + foo :: bar :: baz -- .map(_ * 2) -- .last -+ .map(_ * 2) -+ .last - println(first) + .map(_ * 2) + .last + println(first) <<< #4614 infix then select, always indent.fewerBraces = always === @@ -2504,12 +2503,12 @@ indent.fewerBraces = always .head println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .head -+ .head - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .head + println(first) <<< #4614 infix then apply, always indent.fewerBraces = always === @@ -2520,12 +2519,12 @@ indent.fewerBraces = always .map(_ * 2) println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .map(_ * 2) -+ .map(_ * 2) - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .map(_ * 2) + println(first) <<< #4614 infix then apply and select, always indent.fewerBraces = always === @@ -2537,14 +2536,13 @@ indent.fewerBraces = always .last println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .map(_ * 2) -- .last -+ .map(_ * 2) -+ .last - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .map(_ * 2) + .last + println(first) <<< #4614 infix then select, beforeSelect indent.fewerBraces = beforeSelect === @@ -2555,12 +2553,12 @@ indent.fewerBraces = beforeSelect .head println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .head -+ .head - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .head + println(first) <<< #4614 infix then apply, beforeSelect indent.fewerBraces = beforeSelect === @@ -2571,12 +2569,12 @@ indent.fewerBraces = beforeSelect .map(_ * 2) println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .map(_ * 2) -+ .map(_ * 2) - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .map(_ * 2) + println(first) <<< #4614 infix then apply and select, beforeSelect indent.fewerBraces = beforeSelect === @@ -2588,14 +2586,13 @@ indent.fewerBraces = beforeSelect .last println(first) >>> -Idempotency violated -=> Diff (- obtained, + expected) - baz -- .map(_ * 2) -- .last -+ .map(_ * 2) -+ .last - println(first) +@main def main() = + val first = + foo :: bar :: + baz + .map(_ * 2) + .last + println(first) <<< #4614 postfix then select, never indent.fewerBraces = never === @@ -2605,17 +2602,10 @@ indent.fewerBraces = never .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .head - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .head + foo bar + .head println(first) <<< #4614 postfix then apply, never indent.fewerBraces = never @@ -2626,17 +2616,10 @@ indent.fewerBraces = never .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, never indent.fewerBraces = never @@ -2648,19 +2631,11 @@ indent.fewerBraces = never .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - .last - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) - .last + foo bar + .map(_ * 2) + .last println(first) <<< #4614 postfix then select, always indent.fewerBraces = always @@ -2671,17 +2646,10 @@ indent.fewerBraces = always .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .head - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .head + foo bar + .head println(first) <<< #4614 postfix then apply, always indent.fewerBraces = always @@ -2692,17 +2660,10 @@ indent.fewerBraces = always .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, always indent.fewerBraces = always @@ -2714,19 +2675,11 @@ indent.fewerBraces = always .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - .last - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) - .last + foo bar + .map(_ * 2) + .last println(first) <<< #4614 postfix then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2737,17 +2690,10 @@ indent.fewerBraces = beforeSelect .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .head - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .head + foo bar + .head println(first) <<< #4614 postfix then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2758,17 +2704,10 @@ indent.fewerBraces = beforeSelect .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2780,17 +2719,9 @@ indent.fewerBraces = beforeSelect .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found - val first = - foo bar - .map(_ * 2) - ^ - .last - println(first) -====== full result: ====== @main def main() = val first = - foo bar - .map(_ * 2) - .last + foo bar + .map(_ * 2) + .last println(first) diff --git a/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_unfold.stat b/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_unfold.stat index 2f58deec55..66a50913ef 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_unfold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/FewerBraces_unfold.stat @@ -2338,8 +2338,9 @@ indent.fewerBraces = never @main def main() = val first = - for i <- 0 to 10 - yield i.head + for i <- 0 to 10 + yield i + .head println(first) <<< #4614 for-yield then apply, never indent.fewerBraces = never @@ -2354,8 +2355,9 @@ indent.fewerBraces = never @main def main() = val first = - for i <- 0 to 10 - yield i.map(_ * 2) + for i <- 0 to 10 + yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, never indent.fewerBraces = never @@ -2371,8 +2373,10 @@ indent.fewerBraces = never @main def main() = val first = - for i <- 0 to 10 - yield i.map(_ * 2).last + for i <- 0 to 10 + yield i + .map(_ * 2) + .last println(first) <<< #4614 for-yield then select, always indent.fewerBraces = always @@ -2387,8 +2391,9 @@ indent.fewerBraces = always @main def main() = val first = - for i <- 0 to 10 - yield i.head + for i <- 0 to 10 + yield i + .head println(first) <<< #4614 for-yield then apply, always indent.fewerBraces = always @@ -2403,8 +2408,9 @@ indent.fewerBraces = always @main def main() = val first = - for i <- 0 to 10 - yield i.map(_ * 2) + for i <- 0 to 10 + yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, always indent.fewerBraces = always @@ -2420,8 +2426,10 @@ indent.fewerBraces = always @main def main() = val first = - for i <- 0 to 10 - yield i.map(_ * 2).last + for i <- 0 to 10 + yield i + .map(_ * 2) + .last println(first) <<< #4614 for-yield then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2436,8 +2444,9 @@ indent.fewerBraces = beforeSelect @main def main() = val first = - for i <- 0 to 10 - yield i.head + for i <- 0 to 10 + yield i + .head println(first) <<< #4614 for-yield then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2452,8 +2461,9 @@ indent.fewerBraces = beforeSelect @main def main() = val first = - for i <- 0 to 10 - yield i.map(_ * 2) + for i <- 0 to 10 + yield i + .map(_ * 2) println(first) <<< #4614 for-yield then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2469,8 +2479,10 @@ indent.fewerBraces = beforeSelect @main def main() = val first = - for i <- 0 to 10 - yield i.map(_ * 2).last + for i <- 0 to 10 + yield i + .map(_ * 2) + .last println(first) <<< #4614 infix then select, never indent.fewerBraces = never @@ -2484,7 +2496,9 @@ indent.fewerBraces = never >>> @main def main() = - val first = foo :: bar :: baz.head + val first = + foo :: bar :: baz + .head println(first) <<< #4614 infix then apply, never indent.fewerBraces = never @@ -2498,7 +2512,9 @@ indent.fewerBraces = never >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2) + val first = + foo :: bar :: baz + .map(_ * 2) println(first) <<< #4614 infix then apply and select, never indent.fewerBraces = never @@ -2513,7 +2529,10 @@ indent.fewerBraces = never >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2).last + val first = + foo :: bar :: baz + .map(_ * 2) + .last println(first) <<< #4614 infix then select, always indent.fewerBraces = always @@ -2527,7 +2546,9 @@ indent.fewerBraces = always >>> @main def main() = - val first = foo :: bar :: baz.head + val first = + foo :: bar :: baz + .head println(first) <<< #4614 infix then apply, always indent.fewerBraces = always @@ -2541,7 +2562,9 @@ indent.fewerBraces = always >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2) + val first = + foo :: bar :: baz + .map(_ * 2) println(first) <<< #4614 infix then apply and select, always indent.fewerBraces = always @@ -2556,7 +2579,10 @@ indent.fewerBraces = always >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2).last + val first = + foo :: bar :: baz + .map(_ * 2) + .last println(first) <<< #4614 infix then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2570,7 +2596,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = - val first = foo :: bar :: baz.head + val first = + foo :: bar :: baz + .head println(first) <<< #4614 infix then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2584,7 +2612,9 @@ indent.fewerBraces = beforeSelect >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2) + val first = + foo :: bar :: baz + .map(_ * 2) println(first) <<< #4614 infix then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2599,7 +2629,10 @@ indent.fewerBraces = beforeSelect >>> @main def main() = - val first = foo :: bar :: baz.map(_ * 2).last + val first = + foo :: bar :: baz + .map(_ * 2) + .last println(first) <<< #4614 postfix then select, never indent.fewerBraces = never @@ -2610,16 +2643,11 @@ indent.fewerBraces = never .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main -def main() = - val first = foo bar.head - ^ - println(first) -====== full result: ====== @main def main() = - val first = foo bar.head + val first = + foo bar + .head println(first) <<< #4614 postfix then apply, never indent.fewerBraces = never @@ -2630,16 +2658,11 @@ indent.fewerBraces = never .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main -def main() = - val first = foo bar.map(_ * 2) - ^ - println(first) -====== full result: ====== @main def main() = - val first = foo bar.map(_ * 2) + val first = + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, never indent.fewerBraces = never @@ -2651,16 +2674,12 @@ indent.fewerBraces = never .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = - val first = foo bar.map(_ * 2).last - ^ - println(first) -====== full result: ====== -@main -def main() = - val first = foo bar.map(_ * 2).last + val first = + foo bar + .map(_ * 2) + .last println(first) <<< #4614 postfix then select, always indent.fewerBraces = always @@ -2671,16 +2690,11 @@ indent.fewerBraces = always .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = - val first = foo bar.head - ^ - println(first) -====== full result: ====== -@main -def main() = - val first = foo bar.head + val first = + foo bar + .head println(first) <<< #4614 postfix then apply, always indent.fewerBraces = always @@ -2691,16 +2705,11 @@ indent.fewerBraces = always .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main -def main() = - val first = foo bar.map(_ * 2) - ^ - println(first) -====== full result: ====== @main def main() = - val first = foo bar.map(_ * 2) + val first = + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, always indent.fewerBraces = always @@ -2712,16 +2721,12 @@ indent.fewerBraces = always .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = - val first = foo bar.map(_ * 2).last - ^ - println(first) -====== full result: ====== -@main -def main() = - val first = foo bar.map(_ * 2).last + val first = + foo bar + .map(_ * 2) + .last println(first) <<< #4614 postfix then select, beforeSelect indent.fewerBraces = beforeSelect @@ -2732,16 +2737,11 @@ indent.fewerBraces = beforeSelect .head println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main -def main() = - val first = foo bar.head - ^ - println(first) -====== full result: ====== @main def main() = - val first = foo bar.head + val first = + foo bar + .head println(first) <<< #4614 postfix then apply, beforeSelect indent.fewerBraces = beforeSelect @@ -2752,16 +2752,11 @@ indent.fewerBraces = beforeSelect .map(_ * 2) println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found -@main -def main() = - val first = foo bar.map(_ * 2) - ^ - println(first) -====== full result: ====== @main def main() = - val first = foo bar.map(_ * 2) + val first = + foo bar + .map(_ * 2) println(first) <<< #4614 postfix then apply and select, beforeSelect indent.fewerBraces = beforeSelect @@ -2773,14 +2768,10 @@ indent.fewerBraces = beforeSelect .last println(first) >>> -test does not parse: [dialect scala3] `;` expected but `.` found @main def main() = - val first = foo bar.map(_ * 2).last - ^ - println(first) -====== full result: ====== -@main -def main() = - val first = foo bar.map(_ * 2).last + val first = + foo bar + .map(_ * 2) + .last println(first) diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala index 670e69e851..3d4399f93f 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -144,7 +144,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions { val explored = Debug.explored.get() logger.debug(s"Total explored: $explored") if (!onlyUnit && !onlyManual) - assertEquals(explored, 1192570, "total explored") + assertEquals(explored, 1193368, "total explored") val results = debugResults.result() // TODO(olafur) don't block printing out test results. // I don't want to deal with scalaz's Tasks :'(