Skip to content

Commit

Permalink
Merge pull request #711 from pjrt/multi-line-def-fix-defaults
Browse files Browse the repository at this point in the history
Fix bug in `verticalMultilineAtDefinitionSite` where defaulted parameters with parens would fail to split correctly.
  • Loading branch information
pjrt authored Feb 3, 2017
2 parents 4114ab2 + 1fdf140 commit 69cddd4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/scala/org/scalafmt/internal/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ class Router(formatOps: FormatOps) {
val oneLinePerArg = OneArgOneLineSplit(open).f
val paramGroupSplitter: PartialFunction[Decision, Decision] = {
// Indent seperators `)(` by `indentSep`
case Decision(t @ FormatToken(_, rp @ RightParen(), _), _) =>
case Decision(t @ FormatToken(_, rp @ RightParen(), _), _)
if owners(rp) == leftOwner =>
Decision(t,
Seq(
Split(Newline, 0)
Expand Down
45 changes: 45 additions & 0 deletions core/src/test/resources/test/VerticalMultiline.stat
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,51 @@ def format_![T <: Tree](
ev2: EC
): String

<<< should work with comments
def format_![T <: Tree](
code: String, // The code!
code2: String
)(implicit ev: Parse[T], // The Parser!!! Some very long comment that goes over limit
ex: D): String = 1
>>>
def format_![T <: Tree](
code: String, // The code!
code2: String
)(implicit ev: Parse[T], // The Parser!!! Some very long comment that goes over limit
ex: D
): String = 1

<<< should not modify into single line if it has comments
def format_!(
code: String, // The code!
code2: String
): String = 1
>>>
def format_!(
code: String, // The code!
code2: String
): String = 1

<<< should work with defaulted method
def format_![T <: Tree](
name: Name,
code: String = Defaults.code, updatedAt: Instant = Instant.now(),
user: User = new User { def someFunc(): RT = () },
createdAt: Instant = Default.getInstant(a)(b))
(implicit ev: Parse[T],
ev2: EC)
: String
>>>
def format_![T <: Tree](
name: Name,
code: String = Defaults.code,
updatedAt: Instant = Instant.now(),
user: User = new User { def someFunc(): RT = () },
createdAt: Instant = Default.getInstant(a)(b)
)(implicit ev: Parse[T],
ev2: EC
): String

<<< should not affect classes
final class UserProfile(name: String, age: Int, address: Address, profession: Profesion, school: School)
extends Profile with UserSettings
Expand Down

0 comments on commit 69cddd4

Please sign in to comment.