Skip to content

Commit

Permalink
PolicyOps: add exclude to PenalizeAllNewlines
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 25, 2024
1 parent b6c56c2 commit b7cc8ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1119,20 +1119,14 @@ class Router(formatOps: FormatOps) {
SingleLineBlock(close, noSyntaxNL = true)
else if (isBracket)
PenalizeAllNewlines(close, newlinePenalty, penalizeLambdas = false)
else {
val penalty =
if (!multipleArgs) newlinePenalty else Constants.ShouldBeNewline
policyWithExclude(
excludeBlocks,
Policy.End.OnLeft,
Policy.End.OnLeft,
)(PenalizeAllNewlines(
close,
penalty = penalty,
penalizeLambdas = multipleArgs,
noSyntaxNL = multipleArgs,
))
}
else PenalizeAllNewlines(
close,
penalty =
if (!multipleArgs) newlinePenalty else Constants.ShouldBeNewline,
penalizeLambdas = multipleArgs,
noSyntaxNL = multipleArgs,
exclude = excludeBlocks,
)

val preferNoSplit = !skipNoSplit && singleArgument &&
style.newlines.keepBreak(noBreak())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ object PolicyOps {
penalizeLambdas: Boolean = true,
noSyntaxNL: Boolean = false,
ignore: Boolean = false,
exclude: TokenRanges = TokenRanges.empty,
excludeLt: FT => Policy.End.WithPos = Policy.End.OnLeft,
excludeRt: FT => Policy.End.WithPos = Policy.End.OnLeft,
)(implicit fileLine: FileLine, style: ScalafmtConfig): Policy = Policy ?
(ignore || penalty <= 0) || new PenalizeAllNewlines(
(ignore || penalty <= 0) ||
policyWithExclude(exclude, excludeLt, excludeRt)(new PenalizeAllNewlines(
Policy.End < expire,
penalty,
penalizeLambdas,
noSyntaxNL,
)
))
}

def penalizeNewlineByNesting(before: FT, after: FT)(implicit
Expand Down

0 comments on commit b7cc8ec

Please sign in to comment.