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

Update scalafmt default version to 3.8.3 #670

Open
wants to merge 1 commit into
base: idea243.x
Choose a base branch
from

Conversation

987Nabil
Copy link
Contributor

If one activates scalafmt formatting without a config file, currently 1.5.1 is downloaded. That is a very old version and does not support Scala 3. I don't see a reason to not update this.

@vasilmkd
Copy link
Contributor

Hi, thanks for your contribution.
We tried doing this a while ago. Unfortunately, new scalafmt versions (after 3.1.0) require manually specifying a Scala dialect.
https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects

You would essentially have to build some sort of default given the Scala version in the project.
I think it would be fine, as a default (which may not be 100% correct, and power users can still adjust the generated file manually) to do the following mapping:

Scala 2.11 -> scala211
Scala 2.12 -> scala212
Scala 2.13 -> scala213
Scala 3 -> scala3

Would you like to continue with this work? Thanks again.

@987Nabil
Copy link
Contributor Author

I'll take a look

@hmemcpy
Copy link
Contributor

hmemcpy commented Oct 22, 2024

I'll throw another possible wrench into this: there's also -Xsource:3 compatibility.

@vasilmkd
Copy link
Contributor

Which is exactly why we haven't allocated the time to do it yet. 🥶

There are edge cases to work through.

@unkarjedy unkarjedy assigned unkarjedy and vasilmkd and unassigned unkarjedy Oct 25, 2024
@unkarjedy
Copy link
Member

Some useful pointers:
Extension methods to find the Scala version of the current module:

  • org.jetbrains.plugins.scala.project.ModuleExt#scalaMinorVersion
  • org.jetbrains.plugins.scala.project.ModuleExt#languageLevel

Extension methods to detect -xsource

  • org.jetbrains.plugins.scala.project.ModuleExt#isSource3Enabled
  • org.jetbrains.plugins.scala.project.ModuleExt#source3Options
    (not sure how scalafmt handles these, though)

There is currently limited support for multiple scalafmt configuration in the project.
This can be the case when there are multiple Scala versions in the project.
See https://youtrack.jetbrains.com/issue/SCL-16675/Add-an-option-to-use-.scalafmt.conf-from-the-module-in-multi-module-projects

So, the fix would probably work only for the case when there is one Scala version used in the project.
You could take the module representing the root directory, assuming that it has the Scala SDK with the "primary" version.
Though it might be not always true. E.g. the root module might have an empty sources directory, and the main code can be located in subprojects. In this case we might find the "Most frequently used Scala SDK version" among the modules.

@unkarjedy unkarjedy self-assigned this Oct 25, 2024
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.

4 participants