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

Format scala-3 MacroCompat with scala3 runner #518

Merged
merged 7 commits into from
May 19, 2022
Merged

Conversation

valencik
Copy link
Collaborator

@valencik valencik commented Apr 10, 2022

This was originally in #225 which I am trying to minimize by plucking things out of it.

This PR updates scalafmt to the latest "3.5.4", and formats the scala-3 MacroCompat files which were previously excluded.
Additionally, this formats munit/shared/src/main/scala-2/munit/internal/MacroCompat.scala as the previous regex actually matches on scala-

@valencik valencik self-assigned this Apr 10, 2022
.scalafmt.conf Outdated
Comment on lines 10 to 14
project.excludeFilters = [
".*scala-3*"
"LinesSuite.scala"
".*scala-3.*MacroCompat.scala$"
]
runner.dialect = scala212
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exclude, vs fileOverride?

fileOverride {
  "glob:**/src/{main,test}/scala-3/**" {
    runner.dialect = scala3
  }
}

https://github.com/typelevel/cats/blob/9732f90a4891346fe7979918e606be32b01eef26/.scalafmt.conf#L15

@valencik
Copy link
Collaborator Author

I changed the .scalafmt.conf to use the suggested:

fileOverride {
  "glob:**/src/{main,test}/scala-3/**" {
    runner.dialect = scala3
  }
}

Unfortunately, I ran into a weird issue where scalafmt, with dialect scala3 formats munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala successfully but then fails to be able to format it again (or to check if it is formatted)!

Prior to this PR we have the following line in munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala

implicit def generate[T](value: T): Clue[T] = macro MacroCompatScala2.clueImpl

scalafmt, with dialect scala3 breaks up this line into:

implicit def generate[T](value: T): Clue[T] =
  macro MacroCompatScala2.clueImpl

Which scalafmt then fails to parse:

[error] /home/andrew/grabbed/munit/munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala:26: error: [dialect scala3] illegal start of statement
[error]       macro MacroCompatScala2.clueImpl
[error]       ^: /home/andrew/grabbed/munit/munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala
[error] /home/andrew/grabbed/munit/munit/shared/src/main/scala-3/munit/internal/MacroCompat.scala:26: error: [dialect scala3] illegal start of statement

@armanbilge
Copy link
Contributor

Maybe just disable scalafmt on that line?

@valencik
Copy link
Collaborator Author

Opened an issue upstream for now scalameta/scalameta#2727

.scalafmt.conf Outdated Show resolved Hide resolved
valencik and others added 3 commits May 13, 2022 14:07
@valencik valencik changed the title Only exclude scala-3 MacroCompat from scalafmt Format scala-3 MacroCompat with scala3 runner May 19, 2022
@valencik valencik merged commit 95ee168 into main May 19, 2022
@valencik valencik deleted the scalafmt-scala3 branch May 19, 2022 00:23
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 this pull request may close these issues.

None yet

2 participants