Support shebang in .scala files with the Scala 3 dialect
Configuration (required)
version = 3.5.8
runner.dialect = scala3
Steps
Given code like this:
#!/usr/bin/env scala
@main def run() = println("hello world!")
Problem
Scalafmt formats code like this:
.../main.scala:1: error: [dialect scala3] illegal start of definition identifier
#!/usr/bin/env scala
^
Expectation
The file is legal scala3 (can be run with scala main.scala and compiled with scalac main.scala), and should be formatted while ignoring the first line.
Notes
There seems to be supported for ammonite scripts, or rather anything with a .sc file ending
according to the blog below, there's no good solution: https://www.codementor.io/@martinbrosenberg/shello-world-writing-a-scala-script-z8qg4i7d4
This bug report is about the fact that Scala 3 supports shebang lines in source files (in the sense that they are just ignored by the compiler), but scalafmt does not, thus is unable to format such Scala source files even though they are accepted by the compiler. I updated the title to make that more clear.
The blog is about the issue that not all all tools support shebang lines for Scala 2. This has drastically improved since 2019, with scalafmt being the only holdout of the tools I use.
please include a link to documentation. I'd prefer not to revisit this issue if it turns out that such scripts are handled even more permissively. for instance, the blog seems to suggest that scripts don't require a top level object or class (which is not the same as simply ignoring).