-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1395 from lihaoyi-databricks/operators
Add flags to support apache/spark style of configuration
- Loading branch information
Showing
6 changed files
with
127 additions
and
14 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
scalafmt-core/shared/src/main/scala/org/scalafmt/config/DanglingParentheses.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.scalafmt.config | ||
|
||
import metaconfig._ | ||
|
||
case class DanglingParentheses( | ||
callSite: Boolean, | ||
defnSite: Boolean | ||
) { | ||
val decoder: ConfDecoder[DanglingParentheses] = | ||
generic.deriveDecoder(this).noTypos | ||
} | ||
object DanglingParentheses { | ||
val default = DanglingParentheses(true, true) | ||
implicit lazy val surface: generic.Surface[DanglingParentheses] = | ||
generic.deriveSurface | ||
|
||
implicit val decoder: ConfDecoder[DanglingParentheses] = | ||
ConfDecoder.instance[DanglingParentheses] { | ||
case Conf.Bool(true) => Configured.Ok(DanglingParentheses(true, true)) | ||
case Conf.Bool(false) => Configured.Ok(DanglingParentheses(false, false)) | ||
case els => default.decoder.read(els) | ||
} | ||
|
||
implicit val encoder: ConfEncoder[DanglingParentheses] = | ||
ConfEncoder.instance[DanglingParentheses] { | ||
case DanglingParentheses(true, true) => Conf.Bool(true) | ||
case DanglingParentheses(true, false) => | ||
Conf.Obj("callSite" -> Conf.Bool(true), "defnSite" -> Conf.Bool(false)) | ||
case DanglingParentheses(false, true) => | ||
Conf.Obj("callSite" -> Conf.Bool(false), "defnSite" -> Conf.Bool(true)) | ||
case DanglingParentheses(false, false) => Conf.Bool(false) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
scalafmt-tests/src/test/resources/test/ContinuationIndentHalfDanglingParens.stat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
maxColumn = 6 | ||
danglingParentheses = {callSite: true, defnSite: false} | ||
|
||
<<< classes and methods | ||
object Foo3 { | ||
def f(a: A, b: B, c: C) = 1 | ||
class F(a: A, b: B, c: C) | ||
|
||
f(a, b, c) | ||
new F(a, b, c) | ||
} | ||
>>> | ||
object Foo3 { | ||
def f( | ||
a: A, | ||
b: B, | ||
c: C) = | ||
1 | ||
class F( | ||
a: A, | ||
b: B, | ||
c: C) | ||
|
||
f( | ||
a, | ||
b, | ||
c | ||
) | ||
new F( | ||
a, | ||
b, | ||
c | ||
) | ||
} |
39 changes: 39 additions & 0 deletions
39
scalafmt-tests/src/test/resources/vertical-multiline/verticalAlignMultilineOperators.stat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
verticalAlignMultilineOperators = true | ||
maxColumn = 10 | ||
|
||
<<< in function call | ||
object Foo1 { | ||
function( | ||
a && | ||
b | ||
) | ||
} | ||
>>> | ||
object Foo1 { | ||
function( | ||
a && | ||
b | ||
) | ||
} | ||
<<< after assignment | ||
object Foo2 { | ||
val x = | ||
a + | ||
b | ||
} | ||
>>> | ||
object Foo2 { | ||
val x = | ||
a + | ||
b | ||
} | ||
<<< in template body | ||
object Foo3 { | ||
a + | ||
b | ||
} | ||
>>> | ||
object Foo3 { | ||
a + | ||
b | ||
} |