Skip to content

Commit

Permalink
Router: increase penalty for NL before colon
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 2, 2024
1 parent 2073393 commit bef58bf
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1368,16 +1368,18 @@ class Router(formatOps: FormatOps) {
)
}
bopSplits.getOrElse {
val penalizeNewlines =
PenalizeAllNewlines(expire, Constants.BracketPenalty)
def penalizeNewlines(extra: Int)(implicit fileLine: FileLine) =
PenalizeAllNewlines(expire, Constants.BracketPenalty + extra)
val indent = style.indent.getDefnSite(leftOwner)
val nlPenalty = 2 + treeDepth(returnType)
Seq(
Split(style.newlines.keepBreak(hasBreak()), 0)(sameLineSplit)
.withPolicy(penalizeNewlines),
.withPolicy(penalizeNewlines(0)),
// Spark style guide allows this:
// https://github.com/databricks/scala-style-guide#indent
Split(Newline, Constants.SparkColonNewline)
.withIndent(indent, expire, After).withPolicy(penalizeNewlines),
Split(Newline, Constants.SparkColonNewline + nlPenalty)
.withIndent(indent, expire, After)
.withPolicy(penalizeNewlines(nlPenalty)),
)
}
case FormatToken(_: T.Colon, _, ColonDeclTpeLeft(returnType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9856,17 +9856,17 @@ object Multipart {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
//
- ): Flow[MultipartFormData.Part[
- Source_ByteString
- ], ByteString, NotUsed] = {
+ )
+ : Flow[MultipartFormData.Part[
+ Source_ByteString
+ ], ByteString, NotUsed] = {
//
object Multipart {
def format(
//
): Flow[
MultipartFormData.Part[Source_ByteString],
ByteString,
NotUsed
] = {
//
}
}
<<< #4133 overflowing complex result type 2
preset = default
maxColumn = 80
Expand All @@ -9880,14 +9880,16 @@ object Multipart {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
//
- ): GraphStage[FlowShape[MultipartFormData.Part[
- Source[ByteString, _]
- ], Source[ByteString, Any]]] =
+ )
+ : GraphStage[FlowShape[MultipartFormData.Part[
+ Source[ByteString, _]
+ ], Source[ByteString, Any]]] =
new GraphStage[FlowShape[MultipartFormData.Part[
object Multipart {
private def streamed(
//
): GraphStage[FlowShape[
MultipartFormData.Part[Source[ByteString, _]],
Source[ByteString, Any]
]] =
new GraphStage[FlowShape[MultipartFormData.Part[
Source[ByteString, _]
], Source[ByteString, Any]]] {
//
}
}
46 changes: 24 additions & 22 deletions scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9252,17 +9252,17 @@ object Multipart {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
//
- ): Flow[MultipartFormData.Part[
- Source_ByteString
- ], ByteString, NotUsed] = {
+ )
+ : Flow[MultipartFormData.Part[
+ Source_ByteString
+ ], ByteString, NotUsed] = {
//
object Multipart {
def format(
//
): Flow[
MultipartFormData.Part[Source_ByteString],
ByteString,
NotUsed
] = {
//
}
}
<<< #4133 overflowing complex result type 2
preset = default
maxColumn = 80
Expand All @@ -9276,14 +9276,16 @@ object Multipart {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
//
- ): GraphStage[FlowShape[MultipartFormData.Part[
- Source[ByteString, _]
- ], Source[ByteString, Any]]] =
+ )
+ : GraphStage[FlowShape[MultipartFormData.Part[
+ Source[ByteString, _]
+ ], Source[ByteString, Any]]] =
new GraphStage[FlowShape[MultipartFormData.Part[
object Multipart {
private def streamed(
//
): GraphStage[FlowShape[
MultipartFormData.Part[Source[ByteString, _]],
Source[ByteString, Any]
]] =
new GraphStage[FlowShape[MultipartFormData.Part[
Source[ByteString, _]
], Source[ByteString, Any]]] {
//
}
}
46 changes: 24 additions & 22 deletions scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9653,17 +9653,17 @@ object Multipart {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
//
- ): Flow[MultipartFormData.Part[
- Source_ByteString
- ], ByteString, NotUsed] = {
+ )
+ : Flow[MultipartFormData.Part[
+ Source_ByteString
+ ], ByteString, NotUsed] = {
//
object Multipart {
def format(
//
): Flow[
MultipartFormData.Part[Source_ByteString],
ByteString,
NotUsed
] = {
//
}
}
<<< #4133 overflowing complex result type 2
preset = default
maxColumn = 80
Expand All @@ -9677,14 +9677,16 @@ object Multipart {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
//
- ): GraphStage[FlowShape[MultipartFormData.Part[
- Source[ByteString, _]
- ], Source[ByteString, Any]]] =
+ )
+ : GraphStage[FlowShape[MultipartFormData.Part[
+ Source[ByteString, _]
+ ], Source[ByteString, Any]]] =
new GraphStage[FlowShape[MultipartFormData.Part[
object Multipart {
private def streamed(
//
): GraphStage[FlowShape[
MultipartFormData.Part[Source[ByteString, _]],
Source[ByteString, Any]
]] =
new GraphStage[FlowShape[MultipartFormData.Part[
Source[ByteString, _]
], Source[ByteString, Any]]] {
//
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9949,17 +9949,17 @@ object Multipart {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
//
- ): Flow[MultipartFormData.Part[
- Source_ByteString
- ], ByteString, NotUsed] = {
+ )
+ : Flow[MultipartFormData.Part[
+ Source_ByteString
+ ], ByteString, NotUsed] = {
//
object Multipart {
def format(
//
): Flow[
MultipartFormData.Part[Source_ByteString],
ByteString,
NotUsed
] = {
//
}
}
<<< #4133 overflowing complex result type 2
preset = default
maxColumn = 80
Expand All @@ -9973,14 +9973,16 @@ object Multipart {
}
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
//
- ): GraphStage[FlowShape[MultipartFormData.Part[
- Source[ByteString, _]
- ], Source[ByteString, Any]]] =
+ )
+ : GraphStage[FlowShape[MultipartFormData.Part[
+ Source[ByteString, _]
+ ], Source[ByteString, Any]]] =
new GraphStage[FlowShape[MultipartFormData.Part[
object Multipart {
private def streamed(
//
): GraphStage[FlowShape[
MultipartFormData.Part[Source[ByteString, _]],
Source[ByteString, Any]
]] =
new GraphStage[FlowShape[MultipartFormData.Part[
Source[ByteString, _]
], Source[ByteString, Any]]] {
//
}
}

0 comments on commit bef58bf

Please sign in to comment.