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

Interpolated string might be splitted #2501

Closed
dos65 opened this issue May 7, 2021 · 7 comments
Closed

Interpolated string might be splitted #2501

dos65 opened this issue May 7, 2021 · 7 comments

Comments

@dos65
Copy link
Member

dos65 commented May 7, 2021

Version: 2.7.5 / 3.0.0-RC1

Existing code:

object x {
  s"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa${f(token.pos)} ${g(foo.x)}"
}

After fmt:

object x {
  s"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa${f(
    token.pos
  )} ${g(foo.x)}"
}

Expectation

No splits

Notes:

It seems that splits produced only if it has at least two arguments and f(>>token.pos<<) column position is greater than maxColumn

@kitbellew
Copy link
Collaborator

@dos65 why is your expectation that a line exceeding maxColumn would not be split?

p.s. https://scalameta.org/scalafmt/docs/configuration.html#newlinesavoidforsimpleoverflow

@dos65 dos65 changed the title Inportlated string might be splitted Interpolated string might be splitted May 7, 2021
@dos65
Copy link
Member Author

dos65 commented May 7, 2021

@kitbellew because it's close to literals in their nature.

Also, I think it might confuse people. I was surprised that this compiles 😄
I didn't know that it's acceptable to have \n inside arguments in a non-multiline interpolated string.

@kitbellew
Copy link
Collaborator

@kitbellew because it's close to literals in their nature.

Also, I think it might confuse people. I was surprised that this compiles 😄
I didn't know that it's acceptable to have \n inside arguments in a non-multiline interpolated string.

i don't think we should change the default behaviour, but do check out that parameter, it will probably do what you want. if it does, we should probably close this issue.

@kitbellew
Copy link
Collaborator

@dos65 вадим, я пока закрою, но если параметр newlines.avoidForSimpleOverflow = [tooLong] не поможет, то ты мне скажи, пожалуйста.

@dos65
Copy link
Member Author

dos65 commented Jan 26, 2022

@kitbellew

Я тут случайно проверил - newlines.avoidForSimpleOverflow = [tooLong] не помогает.
Пример из scalameta:

// до
q"""
    ${instrument(requirement)} match {
       case (true, _) => ()
       case (false, $failures) => $InvariantFailedRaiseMethod(${showCode(requirement)}, $failures, $allDebuggees)
     }
"""

// после
q"""
  ${instrument(requirement)} match {
    case (true, _) => ()
    case (false, $failures) => $InvariantFailedRaiseMethod(${showCode(
 requirement
 )}, $failures, $allDebuggees)
   }
"""

Как-то не красиво выходит.
Может все таки сделать чтобы по дефолту игнорировало интерполированные строки?

@kitbellew
Copy link
Collaborator

забавно... по дефолту нет, но #3080 было вчера.

@dos65
Copy link
Member Author

dos65 commented Jan 26, 2022

но #3080 было вчера

шик, тогда все ок!

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

No branches or pull requests

2 participants