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

Scalafmt breaks code (tuple, trailing comma, RedundantParens) #3743

Closed
yurique opened this issue Jan 1, 2024 · 0 comments · Fixed by #3750
Closed

Scalafmt breaks code (tuple, trailing comma, RedundantParens) #3743

yurique opened this issue Jan 1, 2024 · 0 comments · Fixed by #3750

Comments

@yurique
Copy link

yurique commented Jan 1, 2024

$ scalafmt --version
scalafmt 3.7.17

Configuration (required)

version=3.7.17
runner.dialect = "scala3"
rewrite.rules = [RedundantParens]

Command-line parameters (required)

scalafmt --stdout scalafmttest.scala

Steps

Given code like this:

def test =
  (
    Option(""),
    ).map(identity)

Problem

Scalafmt formats code like this:

def test =
  Option(""), .map(identity)

Expectation

I would like the formatted output to look like this:

def test =
  Option("").map(identity)

Workaround

¯_(ツ)_/¯ :)

Notes

The trailing comma here is "bad" - I ended up having it by accident (it was a tuple at some point, then I no longer needed a tuple there but didn't clean up the parens and the comma).

In this minified example scalafmt produces broken code, but in my project the file that contained this pattern was larger (though it was simple, no deep nesting etc) – there, scalafmt is exploding with this:

scalafmt: Search state exploded on ',∙.[4915:4926]', line 148

In my case, IDEA is the main driver for scalafmt and in this case the file was just not getting formatted and no messages were shown anywhere – thus I started investigating and ended up with this.

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.

1 participant