Skip to content

Commit

Permalink
Break line if def equals is at columns + 1
Browse files Browse the repository at this point in the history
  • Loading branch information
aeons committed May 31, 2017
1 parent 3910e5a commit 225c62e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/src/main/scala/org/scalafmt/internal/FormatOps.scala
Expand Up @@ -187,14 +187,17 @@ class FormatOps(val tree: Tree, val initStyle: ScalafmtConfig) {
@tailrec
final def rhsOptimalToken(start: FormatToken): Token = start.right match {
case Comma() | LeftParen() | RightParen() | RightBracket() | Semicolon() |
RightArrow()
RightArrow() | Equals()
if next(start) != start &&
!owners(start.right).tokens.headOption.contains(start.right) &&
!startsNewBlock(start.right) &&
newlinesBetween(start.between) == 0 =>
rhsOptimalToken(next(start))
case _ => start.left
}

final def startsNewBlock(t: Token): Boolean =
owners(t).tokens.headOption.contains(t)

/**
* js.native is very special in Scala.js.
*
Expand Down
30 changes: 30 additions & 0 deletions core/src/test/resources/newlines/OffByOneParameterlessMethod.stat
@@ -0,0 +1,30 @@
style = defaultWithAlign
newlines.sometimesBeforeColonInMethodReturnType = false
maxColumn = 32
<<< equals is at column + 1
object Test {
//-----------------------------|
def test: Either[String, Int] = Right(0)
}
>>>
object Test {
//-----------------------------|
def test: Either[String,
Int] =
Right(0)
}
<<< SKIP left brace is at column + 1
object Test {
//-----------------------------|
def ab: Either[String, Int] = {
Right(0)
}
}
>>>
object Test {
//-----------------------------|
def ab: Either[String,
Int] = {
Right(0)
}
}

0 comments on commit 225c62e

Please sign in to comment.