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

running format with RedundantBraces rule twice produces different results after upgrade to 3.8.5 (from 3.8.3) #4731

Closed
visma-alexander-maslov opened this issue Jan 20, 2025 · 6 comments · Fixed by #4733

Comments

@visma-alexander-maslov
Copy link

After upgrading to 3.8.5 with RedundandBraces rule enabled and scala3 dialect.

Following code

  "Service" must {
    "have at least one test" in {
      pending
      // Write here your test ....
      // don't forget to remove `pending`
    }
}

is formatted to

"Service" must {
  "have at least one test" in
    pending
    // Write here your test ....
    // don't forget to remove `pending`
}

Which is kind of nice and correct.
But running scalaftm again formats it once more:

"Service" must {
  "have at least one test" in
    pending
  // Write here your test ....
  // don't forget to remove `pending`
}

The indentation for comments is removed.

@kitbellew
Copy link
Collaborator

please provide the information requested in the issue template.

@visma-alexander-maslov
Copy link
Author

Where can I find a template ?
Pressing New Issue provides no template - just empty text field.

Image

@tgodzik
Copy link
Contributor

tgodzik commented Jan 20, 2025

Looks like the old drafter broke, and we need to switch to the same thing as in metals https://github.com/scalameta/metals/tree/main/.github/ISSUE_TEMPLATE

@visma-alexander-maslov
Copy link
Author

At least some issue discovered 😆 .. and fixed 👍
I'll try to go through that.

@kitbellew
Copy link
Collaborator

Looks like the old drafter broke, and we need to switch to the same thing as in metals https://github.com/scalameta/metals/tree/main/.github/ISSUE_TEMPLATE

yep, this was unfortunate. now we have a useless drop-down with a single Bug report template.

@visma-alexander-maslov
Copy link
Author

Requeired: Configuration

version = "3.8.5"
runner.dialect = scala3
rewrite.rules = [  "RedundantBraces" ]

Required: Command-line parameters

scalafmt ./MySpec.scala

Steps

Given code like this:

import org.scalatest.BeforeAndAfterAll
import org.scalatest.wordspec.AnyWordSpec

class MySpec extends AnyWordSpec with BeforeAndAfterAll {

  "Service" must {
    "have at least one test" in {
      pending
      // Write here your test ....
      // don't forget to remove `pending`
    }
  }

  override protected def afterAll(): Unit = {
    println("After all....")
    super.afterAll()
  }

}

run scalafmt ./MySpec.scala 2 times.

Problem

Scalafmt formats code like this:

import org.scalatest.BeforeAndAfterAll
import org.scalatest.wordspec.AnyWordSpec

class MySpec extends AnyWordSpec with BeforeAndAfterAll {

  "Service" must {
    "have at least one test" in
      pending
    // Write here your test ....
    // don't forget to remove `pending`
  }

  override protected def afterAll(): Unit = {
    println("After all....")
    super.afterAll()
  }

}

Expectation

I would like the formatted output to look like this:

import org.scalatest.BeforeAndAfterAll
import org.scalatest.wordspec.AnyWordSpec

class MySpec extends AnyWordSpec with BeforeAndAfterAll {

  "Service" must {
    "have at least one test" in
      pending
      // Write here your test ....
      // don't forget to remove `pending`
  }

  override protected def afterAll(): Unit = {
    println("After all....")
    super.afterAll()
  }

}

Notes

The expected output produces if you run scalafmt ./MySpec.scala once.
Second time it seems to treat comments not belonging the the same indentation block.

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