scala-ide / scalariform

Scala source code formatter
http://scala-ide.github.com/scalariform/
MIT License
527 stars 148 forks source link

Incorrect indentation produced #221

Closed thesamet closed 8 years ago

thesamet commented 8 years ago

Running the CLI with -alignParameters +doubleIndentClassDeclaration -preserveDanglingCloseParenthesis

-  case class MyClass(a: String,
-                                 b: String,
-                                 c: Option[String]) extends Foo {
+  case class MyClass(
+    a: String,
+      b: String,
+      c: Option[String]
+) extends Foo {

The problem is that the "a: String" line gets two spaces and not 4, as it should due to the +doubleIndentClassDeclaration.

Update: this happens when the above case class is nested with a class. Here is a failing unit test:

  {
    implicit val formattingPreferences =
        FormattingPreferences.setPreference(AlignParameters, false)
        .setPreference(DoubleIndentClassDeclaration, true)

    """object Foo {
      |  case class Bar(alpha: String,
      |                 beta: String,
      |                 gamma: String) extends Baz {
      |  }
      |}""" ==>
    """object Foo {
      |  case class PersonSignUpRequest(
      |      alpha: String,
      |      beta: String,
      |      gamma: String) extends Baz {
      |  }
      |}"""
  }
jkinkead commented 8 years ago

Thanks for the bug report!

This is fixed on master (duplicate of #187 ).