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

Insert newline / align closing paren after method call with single multiline string #3608

Closed
georgms opened this issue Aug 11, 2023 · 2 comments · Fixed by #3613
Closed

Insert newline / align closing paren after method call with single multiline string #3608

georgms opened this issue Aug 11, 2023 · 2 comments · Fixed by #3613

Comments

@georgms
Copy link

georgms commented Aug 11, 2023

Configuration (required)

Please paste the contents of your .scalafmt.conf file here:

version = 3.7.12
runner.dialect = scala212
maxColumn = 120

Command-line parameters (required)

When I run scalafmt via CLI like this: coursier launch scalafmt

Steps

Given code like this:

println("""
  |A very long string
  |with multiple lines
  |""".stripMargin
)

Problem

Scalafmt formats code like this:

println("""
  |A very long string
  |with multiple lines
  |""".stripMargin) // No newline before closing paren, not aligned with beginning of statement

Expectation

I would like the formatted output to look like this:

println("""
  |A very long string
  |with multiple lines
  |""".stripMargin
)

Workaround

Notes

It works fine when the method is called with multiple arguments:

println(
  """
  |A very long string
  |with multiple lines
  |""".stripMargin,
  "ok"
)

I'm assuming that scalafmt (kind of correctly) considers a multiline string to be a single argument so no newline is inserted before the closing paren (same as println("ok")). My rationale is that it would be more consistent if a multiline string actually spanning multiple lines would be considered multiple arguments, in which case scalafmt can be configured to insert a newline before the closing paren.

The behavior for strings using the multiline syntax but actually consisting of a single line is fine:

println("""A pretty short string""".stripMargin)
@kitbellew
Copy link
Collaborator

I'm fairly certain that there's a configuration parameter which deals with dangling closing parentheses. if you have tried it, please amend the issue; if you haven't, would you mind rtfm, please?

@kitbellew
Copy link
Collaborator

I take it back. There's no parameter that helps with this, since there's no newline after the opening paren. the only option is to insert a newline after ( manually and use newlines.source = keep (or a // comment after ().

otherwise, there's a lot of old code which specifically enables the behaviour you're not happy about. we can't just change it, as it's a breaking change, so the only option is to introduce a new parameter.

and this normally requires socializing this with the larger community on the discord channel and getting them to support a new parameter, of which there are already too many, and most users can't power through the configuration doc.

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

Successfully merging a pull request may close this issue.

2 participants