Skip to content
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

Conflict between new line before / after implicit and verticalMultilineAtDefinitionSite? #1362

Closed
alexarchambault opened this issue Feb 5, 2019 · 3 comments · Fixed by #1749

Comments

@alexarchambault
Copy link
Contributor

alexarchambault commented Feb 5, 2019

  • Version: 2.0.0-RC4
  • Integration: CLI
  • Configuration:
maxColumn = 80
continuationIndent.callSite = 2
continuationIndent.defnSite = 2
align.openParenCallSite = false
align.openParenDefnSite = false
danglingParentheses = true

verticalMultiline.newlineBeforeImplicitKW = false
verticalMultiline.newlineAfterImplicitKW = true
newlines.afterImplicitKWInVerticalMultiline = true

verticalMultilineAtDefinitionSite = true

Steps

Given code like this:

case class Foo(
  a: Int,
  b: Boolean,
  c: String,
  d: String,
  e: String,
  f: String,
  g: String
) {
  def run[F[_]](
    fetch: ResolutionProcess.Fetch[F],
    maxIterations: Int = ResolutionProcess.defaultMaxIterations
  )(implicit
    F: Monad[F]
  ): F[Resolution] =
    ???
}

Problem

Scalafmt formats code like this:

case class Foo(
  a: Int,
  b: Boolean,
  c: String,
  d: String,
  e: String,
  f: String,
  g: String) {
  def run[F[_]](
    fetch: ResolutionProcess.Fetch[F],
    maxIterations: Int = ResolutionProcess.defaultMaxIterations
  )(implicit
    F: Monad[F]
  ): F[Resolution] =
    ???
}

Expectation

I would like

  f: String,
  g: String
) {

to be left as-is, rather than changed to

  f: String,
  g: String) {

Workaround

Setting

verticalMultilineAtDefinitionSite = false

fixes that, but in turn, changes

  )(implicit

to

  )(
    implicit

(which I would like to avoid too).

@olafurpg
Copy link
Member

olafurpg commented Feb 6, 2019

Thanks for reporting! The two features were contributed separately so it could be that they don't play nicely together.

@kitbellew
Copy link
Collaborator

@alexarchambault you have reported two issues:

  • dangling parens in case of vertical multiline
  • split before implicit outside of vertical multiline

the first issue should be solved by setting verticalMultiline.excludeDanglingParens = [] (which, for some reason, include class and trait by default). the vertical multiline logic doesn't use the danglingParentheses setting (which also only applies to methods).

the second issue remains, and i will send in a patch to address it.

kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 10, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 10, 2020
If optin.configStyleArguments and/or newlines.danglingParentheses have
been explicitly specified, incorporate them into the vertical multiline
logic.

Fixes scalameta#1362.
Fixes scalameta#1539.
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 28, 2020
This will format "implicit" on the same line as the opening paren, if
possible. It will also break after the "implicit" unless all parameters
fit on one line.

Fixes scalameta#1362.
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 28, 2020
This will format "implicit" on the same line as the opening paren, if
possible. It will also break after the "implicit" unless all parameters
fit on one line.

Fixes scalameta#1362.
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 28, 2020
This will format "implicit" on the same line as the opening paren, if
possible. It will also break after the "implicit" unless all parameters
fit on one line.

Fixes scalameta#1362.
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Feb 29, 2020
This will format "implicit" on the same line as the opening paren, if
possible. It will also break after the "implicit" unless all parameters
fit on one line.

Fixes scalameta#1362.
kitbellew added a commit that referenced this issue Mar 2, 2020
This will format "implicit" on the same line as the opening paren, if
possible. It will also break after the "implicit" unless all parameters
fit on one line.

Fixes #1362.
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 2, 2020
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 2, 2020
If newlines.danglingParentheses is true, the current vertical multiline
logic will apply. However, if the flag is false (the default), it will
supersede the current logic and no dangling will occur.

Fixes scalameta#1362.
kitbellew added a commit that referenced this issue Mar 2, 2020
kitbellew added a commit that referenced this issue Mar 2, 2020
If newlines.danglingParentheses is true, the current vertical multiline
logic will apply. However, if the flag is false (the default), it will
supersede the current logic and no dangling will occur.

Fixes #1362.
@alexarchambault
Copy link
Contributor Author

Thanks a lot for having fixed that, @kitbellew!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants