From 338688577b20f4a497ccfe1fc9a2d771473ba8d7 Mon Sep 17 00:00:00 2001 From: Jesse Kinkead Date: Tue, 14 Jun 2016 12:04:48 -0700 Subject: [PATCH] Update default preference to Prevent instead of Preserve. Add back in TODOs (tests still broken). --- README.rst | 2 +- .../preferences/PreferenceDescriptor.scala | 2 +- .../DoubleIndentMethodFormatterTest.scala | 5 +- .../MiscExpressionFormatterTest.scala | 60 ++++++------------- .../formatter/MiscFormatterTest.scala | 3 +- .../ParenAndBracketSpacingTest.scala | 13 ++-- .../formatter/TemplateFormatterTest.scala | 30 ++++------ 7 files changed, 39 insertions(+), 76 deletions(-) diff --git a/README.rst b/README.rst index 9c1c5a46..51b2d499 100644 --- a/README.rst +++ b/README.rst @@ -549,7 +549,7 @@ Otherwise, if ``false``, spaces before arguments will always be removed. danglingCloseParenthesis ~~~~~~~~~~~~~~~~~~~~~~~~ -Default: ``Preserve`` +Default: ``Prevent`` If ``Force``, any closing parentheses will be set to dangle. For example: diff --git a/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala b/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala index 09f83508..d0637141 100755 --- a/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala +++ b/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala @@ -201,7 +201,7 @@ case object PreserveDanglingCloseParenthesis extends BooleanPreferenceDescriptor case object DanglingCloseParenthesis extends IntentPreferenceDescriptor { val key = "danglingCloseParenthesis" val description = "Put a newline before a ')' in an argument expression" - val defaultValue = Preserve + val defaultValue = Prevent } case object SpaceInsideParentheses extends BooleanPreferenceDescriptor { diff --git a/scalariform/src/test/scala/scalariform/formatter/DoubleIndentMethodFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/DoubleIndentMethodFormatterTest.scala index 908f7b49..52b96e48 100644 --- a/scalariform/src/test/scala/scalariform/formatter/DoubleIndentMethodFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/DoubleIndentMethodFormatterTest.scala @@ -55,19 +55,20 @@ class DoubleIndentMethodFormatterTest extends AbstractFormatterTest { """def foo( | a: String)""" + // TODO: Broken until https://github.com/scala-ide/scalariform/issues/187 is fixed. """def foo(a: String, | b: String)""" =/=> """def foo( | a: String, | b: String)""" + // TODO: Broken until https://github.com/scala-ide/scalariform/issues/187 is fixed. """def foo(a: String, | b: String |)""" =/=> """def foo( | a: String, - | b: String - |)""" + | b: String)""" """def foo(a: String, b: String, | c: String)""" ==> diff --git a/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala index 4c7d7add..ba6a683b 100644 --- a/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala @@ -311,8 +311,7 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { |if (b) c |)""" ==> """a( - | if (b) c - |)""" + | if (b) c)""" """a( |if (b) @@ -408,8 +407,7 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { |)""" ==> """( | 42, - | 46 - |)""" // I prefer no initial indent for tuples, although you could argue it should be consistent with ParenExprs + | 46)""" // I prefer no initial indent for tuples, although you could argue it should be consistent with ParenExprs """a(b, |c => { @@ -444,8 +442,7 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { """Book( | name = "Name", | author = "Author", - | rating = 5 - |)""" + | rating = 5)""" """foobar( |(1,2), @@ -686,9 +683,7 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { | label("label"), | popupMenu( | viewer( // TODO - | ) - | ) - |)""" + | )))""" """a(b) |.c(d) @@ -743,8 +738,7 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { | i => List.range(1, i) map (j => (i, j)) |)""" ==> """List.range(1, r) flatMap ( - | i => List.range(1, i) map (j => (i, j)) - |)""" + | i => List.range(1, i) map (j => (i, j)))""" """a map { | b => @@ -799,12 +793,10 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { """a( | b, | c, - | d - |)( + | d)( | e, | f, - | g - |)""" + | g)""" { implicit val formattingPreferences = FormattingPreferences.setPreference(AlignArguments, true) @@ -856,14 +848,11 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { | zzz( | a, | b, - | c - | ) - | ), + | c)), | c(firstGroupOne(x)), | d, | e, - | f - |)""" + | f)""" """o.manyArguments( | abc = 0, @@ -879,8 +868,7 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { | abcTwo, | abcThree = 3, | abcFour = 4, - | abcFive = 3 - |)""" + | abcFive = 3)""" """Nested1(abcccc = 1, | abc2 = 2, @@ -889,8 +877,7 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { """Nested1( | abcccc = 1, | abc2 = 2, - | abcThree = 3 - |)""" + | abcThree = 3)""" """o.grouped( | firstGroupOne = 1, @@ -910,8 +897,7 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { | secondGroup2 = "Two", | | thirdGroupOne = 3, - | thirdGroup2 = Three(3) - |)""" + | thirdGroup2 = Three(3))""" """multiClause( | arg1 = 1, @@ -924,13 +910,10 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { |)""" ==> """multiClause( | arg1 = 1, - | argument2 = 2 - |)( + | argument2 = 2)( | args3 = 3, - | arg4 = 4 - |)( - | arg5 = 5 - |)""" + | arg4 = 4)( + | arg5 = 5)""" """a( |b = c @@ -940,11 +923,9 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { |)( |d)""" ==> """a( - | b = c - |)( + | b = c)( | c, - | d - |)( + | d)( | d)""" """Nested0( @@ -961,14 +942,11 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { | arg1 = Nested1( | abcccc = 1, | abc2 = 2, - | abcThree = 3 - | ), + | abcThree = 3), | NestedTwo( | abcccc = 1, | abc2 = 2, - | abcThree = 3 - | ) - |)""" + | abcThree = 3))""" } override val debug = false } diff --git a/scalariform/src/test/scala/scalariform/formatter/MiscFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/MiscFormatterTest.scala index b5e71cd6..9ad2c4fd 100644 --- a/scalariform/src/test/scala/scalariform/formatter/MiscFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/MiscFormatterTest.scala @@ -10,8 +10,7 @@ class MiscFormatterTest extends AbstractFormatterTest { |)""" ==> """class Foo( | bar: String, - | baz: String - |)""" + | baz: String)""" """class Foo( | bar: String, diff --git a/scalariform/src/test/scala/scalariform/formatter/ParenAndBracketSpacingTest.scala b/scalariform/src/test/scala/scalariform/formatter/ParenAndBracketSpacingTest.scala index c891bb12..7861ff4a 100644 --- a/scalariform/src/test/scala/scalariform/formatter/ParenAndBracketSpacingTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/ParenAndBracketSpacingTest.scala @@ -34,8 +34,7 @@ class ParenAndBracketSpacingTest extends AbstractExpressionFormatterTest { | beta = bar match { | case _ => "bar" | }, - | gamma = false - |)""" + | gamma = false)""" """foo( |alpha = "foo", @@ -47,10 +46,8 @@ class ParenAndBracketSpacingTest extends AbstractExpressionFormatterTest { """foo( | alpha = "foo", | beta = bar( - | a = 1 - | ), - | gamma = false - |)""" + | a = 1), + | gamma = false)""" """foo( |arg = bar( @@ -59,9 +56,7 @@ class ParenAndBracketSpacingTest extends AbstractExpressionFormatterTest { |)""" ==> """foo( | arg = bar( - | baz = "a" - | ).xyz - |)""" + | baz = "a").xyz)""" } { diff --git a/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala index 238a1d19..83197568 100644 --- a/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala @@ -99,8 +99,7 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW | case b => | val c = { d: Int => 1 } | 1.toString - | } - | ) + | }) |}""" """class C1492 { @@ -350,15 +349,13 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW """def A( | a: A ⇒ B = null, | bee: ⇒ B = null, - | c: B ⇒ C = null - |): D""" + | c: B ⇒ C = null): D""" """class a( | b: Int |)""" ==> """class a( - | b: Int - |)""" + | b: Int)""" """class a( | a: String = "", @@ -424,8 +421,7 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW """private def executeWithinClient[T]( | crawlerConfig: String => JsValue = Fancy.function, | f: HttpCrawlerClient => T, - | port: Int = SpecHelper.port - |): T""" + | port: Int = SpecHelper.port): T""" // By name parameters have correct spacing """def a( @@ -434,8 +430,7 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW |): A""" ==> """def a( | p1: => (SomeLongByNameParam => SomeShorterParam) = Null, - | param2: SomeShorterParam = Null - |): A""" + | param2: SomeShorterParam = Null): A""" // Formats parameterized types correctly """def A(complicatedType: Option[B ,C, D[E, F,G]] = None, @@ -443,8 +438,7 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW |): B""" ==> """def A( | complicatedType: Option[B, C, D[E, F, G]] = None, - | simpleType: String = "" - |): B""" + | simpleType: String = ""): B""" // Param gets placed onto a new line due to current limitations of existing IntertokenFormatInstructions """case class Spacing(param: Int = 1, @@ -454,8 +448,7 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW """case class Spacing( | param: Int = 1, | paramTwo: Int = 2, - | paramThree: String = "3" - |)""" + | paramThree: String = "3")""" // Groups and formats consecutive single line parameters (multi line params) """case class Spacing(param: Int = 1, @@ -487,8 +480,7 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW | paramTwo: Int = 2, | | paramFour: Option[String] = Some("One"), - | paramFive: Any = Nothing - |)""" + | paramFive: Any = Nothing)""" // Aligns implicits and curried parameters properly """class SomeClass( @@ -504,10 +496,8 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW """class SomeClass( | parameterOne: Int = 1, | val parameterTwo: Option[String] = None, - | three: String = "three" - |)( - | intermediate: Int - |)( + | three: String = "three")( + | intermediate: Int)( | implicit | val four: Int, | five: String,