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

formatter breaks code, making it non-compilable with indent.fewerBraces = beforeSelect and indent.significant = 1 #3590

Closed
unkarjedy opened this issue Jul 19, 2023 · 10 comments · Fixed by #3592

Comments

@unkarjedy
Copy link
Contributor

.scalafmt.conf:

version = 3.7.10

runner.dialect = Scala3
indent.significant = 3
indent.fewerBraces = beforeSelect

before:

class test:
   foo1:
        2 + 2
   .foo0

export Foo.*
object Foo {
  def foo0: Foo.type = ???
  def foo00(): Foo.type = ???
  def foo1(i: Int): Foo.type = ???
}

after:

class test:
   foo1:
        2 + 2
     .foo0

export Foo.*
object Foo {
  def foo0: Foo.type = ???
  def foo00(): Foo.type = ???
  def foo1(i: Int): Foo.type = ???
}
image

That's actual for many other "beforeSelect" tests in OptionalBraces

@unkarjedy
Copy link
Contributor Author

@tgodzik
Copy link
Contributor

tgodzik commented Jul 19, 2023

Thanks for reporting! Which compiler version are you using?

@kitbellew
Copy link
Collaborator

@unkarjedy what's the compiler version? this functionality was added very recently to the compiler, 3.3.1-rc1 or something like that

@unkarjedy
Copy link
Contributor Author

unkarjedy commented Jul 19, 2023

Ah, I was using Scala 3.3.0.
Indeed, it works fine with 3.3.1-RC1

I will leave it here FTR: scala/scala3#17056

@kitbellew
Copy link
Collaborator

Ah, I was using Scala 3.3.0. Indeed, it works fine with 3.3.1-RC1

I will leave it here FTR: lampepfl/dotty#17056

i think i mentioned this on the configuration doc page 🙂 https://scalameta.org/scalafmt/docs/configuration.html#indentfewerbraces

@unkarjedy
Copy link
Contributor Author

Indeed. I was blind to the warning.

@unkarjedy
Copy link
Contributor Author

Though, if you use indent.significant = 1 the issue still exist:

version = 3.7.10
runner.dialect = Scala3
indent.significant = 1
indent.fewerBraces = beforeSelect

before:

class test:
 foo1:
  2 + 2
 .foo0

after:

class test:
 foo1:
    2 + 2
   .foo0
image

@unkarjedy unkarjedy reopened this Jul 19, 2023
@unkarjedy unkarjedy changed the title formatter breaks code, making it non-compilable with indent.fewerBraces = beforeSelect formatter breaks code, making it non-compilable with indent.fewerBraces = beforeSelect and indent.significant = 1 Jul 19, 2023
@kitbellew
Copy link
Collaborator

@unkarjedy what do you think we should do? 🙂 i can add a check for this case and throw an exception. @odersky specifically implemented in the attached dotty issue that the difference must be more than one space, hence indentation of 1 contradicts that rule.

@unkarjedy
Copy link
Contributor Author

unkarjedy commented Jul 19, 2023

I don't have a strong preference here.
One solution could be to not add indent in this case, even when indent.fewerBraces = beforeSelect or always
Another would be throwing an assertion that significant indentation is less then 2

@kitbellew
Copy link
Collaborator

I don't have a strong preference here. One solution could be to not add indent in this case, even when indent.fewerBraces = beforeSelect or always

works for me. will try to add a warning message and reset to never.

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.

3 participants