scalaintellij-ideascalafmt

Intellij has a problem with scalafmt and scala 3


My .scalafmt.conf file content is:

version = 3.5.4

IntelliJ downloaded scalafmt for this version:

Scalafmt was downloaded

But when I want to format a file, I get a really confusing error:

Failed to load scalafmt config

IntelliJ version:

IntelliJ IDEA 2022.1.1 (Community Edition)
Build #IC-221.5591.52, built on May 10, 2022

How to solve this problem?


Solution

  • You should explicitly specify runner.dialect. In the case of Scala 3, add runner.dialect = scala3.

    Example final content of .scalafmt.conf:

    version = 3.9.2
    runner.dialect = scala3
    rewrite.scala3.convertToNewSyntax = true
    rewrite.scala3.removeOptionalBraces = true
    

    See https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects

    As for non-descriptive error message see https://youtrack.jetbrains.com/issue/SCL-20123