Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router: price sole NL split in => <NL> at 1 #4371

Merged
merged 2 commits into from
Sep 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -533,24 +533,25 @@ class Router(formatOps: FormatOps) {
nlSplit(nft)(1),
)
implicit val beforeMultiline = style.newlines.getBeforeMultiline
def getNLOnlySplit(implicit l: FileLine) = Seq(nlSplit(nft)(0))
def getNLOnlySplit(cost: Int)(implicit l: FileLine) =
Seq(nlSplit(nft)(cost))
def getFolded(isKeep: Boolean)(implicit l: FileLine) = CtrlBodySplits
.foldedNonEmptyNonComment(body, nlSplit(nft), isKeep)
if (
isCaseBodyABlock(nft, owner) ||
getClosingIfCaseBodyEnclosedAsBlock(nft, owner).isDefined
) Seq(baseSplit)
else if (nft.right.is[T.KwCase]) getNLOnlySplit
else if (nft.right.is[T.KwCase]) getNLOnlySplit(0)
else if (hasBreak() && !beforeMultiline.ignoreSourceSplit)
if ((beforeMultiline eq Newlines.keep) && !bodyIsEmpty)
getFolded(isKeep = true).filter(_.isNL)
else getNLOnlySplit
else getNLOnlySplit(1)
else if (bodyIsEmpty)
if (rt.isAny[T.RightBrace, T.Semicolon])
Seq(baseSplit, nlSplit(nft)(1))
else getNLOnlySplit
else getNLOnlySplit(1)
else if (beforeMultiline eq Newlines.unfold)
if (style.newlines.unfold) getNLOnlySplit else withSlbSplit
if (style.newlines.unfold) getNLOnlySplit(0) else withSlbSplit
else if (
condIsDefined || beforeMultiline.eq(Newlines.classic) ||
getSingleStatExceptEndMarker(body).isEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9662,6 +9662,33 @@ object a {
}
}
}
<<< #4133 applies and selects with a partial function 1
maxColumn = 76
runner.parser = source
===
val fieldsCasts = from.fields.zip(to.fields).map {
case (fromField, toField) => nullSafeCastFunction(fromField.dataType, toField.dataType, ctx)
}
>>>
val fieldsCasts =
from.fields.zip(to.fields).map { case (fromField, toField) =>
nullSafeCastFunction(fromField.dataType, toField.dataType, ctx)
}
<<< #4133 applies and selects with a partial function 2
maxColumn = 76
===
val stats = Profiler.getStatistics().asScala.toSeq.map {
case (trace, count) => MethodCallTrace(trace.className, trace.methodName, trace.methodDescriptor) -> count.intValue
}
>>>
val stats =
Profiler.getStatistics().asScala.toSeq.map { case (trace, count) =>
MethodCallTrace(
trace.className,
trace.methodName,
trace.methodDescriptor
) -> count.intValue
}
<<< #4133 partial function within apply, short
rdd.map(
{case (id, count) => (count, id)})
Expand Down
26 changes: 26 additions & 0 deletions scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9061,6 +9061,32 @@ object a {
}
}
}
<<< #4133 applies and selects with a partial function 1
maxColumn = 76
runner.parser = source
===
val fieldsCasts = from.fields.zip(to.fields).map {
case (fromField, toField) => nullSafeCastFunction(fromField.dataType, toField.dataType, ctx)
}
>>>
val fieldsCasts = from.fields.zip(to.fields)
.map { case (fromField, toField) =>
nullSafeCastFunction(fromField.dataType, toField.dataType, ctx)
}
<<< #4133 applies and selects with a partial function 2
maxColumn = 76
===
val stats = Profiler.getStatistics().asScala.toSeq.map {
case (trace, count) => MethodCallTrace(trace.className, trace.methodName, trace.methodDescriptor) -> count.intValue
}
>>>
val stats = Profiler.getStatistics().asScala.toSeq.map {
case (trace, count) => MethodCallTrace(
trace.className,
trace.methodName,
trace.methodDescriptor
) -> count.intValue
}
<<< #4133 partial function within apply, short
rdd.map(
{case (id, count) => (count, id)})
Expand Down
26 changes: 26 additions & 0 deletions scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9459,6 +9459,32 @@ object a {
}
}
}
<<< #4133 applies and selects with a partial function 1
maxColumn = 76
runner.parser = source
===
val fieldsCasts = from.fields.zip(to.fields).map {
case (fromField, toField) => nullSafeCastFunction(fromField.dataType, toField.dataType, ctx)
}
>>>
val fieldsCasts = from.fields.zip(to.fields).map {
case (fromField, toField) =>
nullSafeCastFunction(fromField.dataType, toField.dataType, ctx)
}
<<< #4133 applies and selects with a partial function 2
maxColumn = 76
===
val stats = Profiler.getStatistics().asScala.toSeq.map {
case (trace, count) => MethodCallTrace(trace.className, trace.methodName, trace.methodDescriptor) -> count.intValue
}
>>>
val stats = Profiler.getStatistics().asScala.toSeq.map {
case (trace, count) => MethodCallTrace(
trace.className,
trace.methodName,
trace.methodDescriptor
) -> count.intValue
}
<<< #4133 partial function within apply, short
rdd.map(
{case (id, count) => (count, id)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9739,6 +9739,38 @@ object a {
}
}
}
<<< #4133 applies and selects with a partial function 1
maxColumn = 76
runner.parser = source
===
val fieldsCasts = from.fields.zip(to.fields).map {
case (fromField, toField) => nullSafeCastFunction(fromField.dataType, toField.dataType, ctx)
}
>>>
val fieldsCasts = from
.fields
.zip(to.fields)
.map { case (fromField, toField) =>
nullSafeCastFunction(fromField.dataType, toField.dataType, ctx)
}
<<< #4133 applies and selects with a partial function 2
maxColumn = 76
===
val stats = Profiler.getStatistics().asScala.toSeq.map {
case (trace, count) => MethodCallTrace(trace.className, trace.methodName, trace.methodDescriptor) -> count.intValue
}
>>>
val stats = Profiler
.getStatistics()
.asScala
.toSeq
.map { case (trace, count) =>
MethodCallTrace(
trace.className,
trace.methodName,
trace.methodDescriptor
) -> count.intValue
}
<<< #4133 partial function within apply, short
rdd.map(
{case (id, count) => (count, id)})
Expand Down
Loading