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

Extra newlines are inserted when `newlines.alwaysBeforeTopLevelStatements` is enabled #933

Closed
kdarkhan opened this Issue May 18, 2017 · 0 comments

Comments

1 participant
@kdarkhan

kdarkhan commented May 18, 2017

  • Version: 0.7.0-RC1
  • Integration: both sbt and cli versions
  • Configuration:
newlines.alwaysBeforeTopLevelStatements = true
maxColumn = 100

Steps

I ran scalafmt like this:

scalafmt -i -f input_file.scala --config scalafmt.conf

Problem

Scalafmt formats code like this:

object hello {

  def world: Future[_] = {
    for {
      _ <- {

        val testObject = Constructor(
          fieldOne = valueOne,
          fieldTwo = None
        )
        returnFuture(testObject)
      }
    } yield ()
  }

  def worldTwo: Unit = {
    something match {
      case (first, second, third) =>

        val someObject = Constructor(hello,
                                     world,
                                     other,
                                     other,
                                     asdfjasdf,
                                     adfasdfasdfasdf,
                                     asdfasdfasdf,
                                     asdfasdf)
        someObject.doSomething()
    }
  }
}

Expectation

I would like the formatted output to look like this:

object hello {

  def world: Future[_] = {
    for {
      _ <- {
        val testObject = Constructor(
          fieldOne = valueOne,
          fieldTwo = None
        )
        returnFuture(testObject)
      }
    } yield ()
  }

  def worldTwo: Unit = {
    something match {
      case (first, second, third) =>
        val someObject = Constructor(hello,
                                     world,
                                     other,
                                     other,
                                     asdfjasdf,
                                     adfasdfasdfasdf,
                                     asdfasdfasdf,
                                     asdfasdf)
        someObject.doSomething()
    }
  }
}

Workaround

If I remove the setting newlines.alwaysBeforeTopLevelStatements = true everything works as expected. However, I want to keep the setting for top level statements, and do not have those newlines inserted while doing pattern matches and inside blocks.

@Daxten Daxten referenced this issue May 31, 2017

Merged

Topic/#933 #959

@olafurpg olafurpg closed this in #959 May 31, 2017

olafurpg added a commit that referenced this issue May 31, 2017

Topic/#933 (#959)
* Stop Traversing on Blocks for topLevelTokens

* Stop Traversing on Blocks for topLevelTokens

* Minimize Testcase

* remove ONLY modifier from test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment