scalafix
scalafix copied to clipboard
New built-in rule to update Scala 3 code to the new syntax
We could create a new rule that groups many small rewrites or lint messages to update the code to the new syntax: Some of those rewrite exist already in Scalafmt, but I think having them here too should be ok
- Rewrite underscores in imports and type arguments
- Rewrite
iftoif then - Drop the case in lambdas when it is not needed anymore
- replace implicit class with extension
- replace package object with top level defs
- replace implicit with using/given
Some of these options are maybe quite difficult to implement, but we can maybe Lint about the possible rewrite instead.
I think we should start with a Source3 rule that turns Scala 2 code into Scala 2 code that compiles under -Xsource:3. It's really what people migrating must do, and it should be possible to automate it fully.
Replacing implicit with using/given is just a nice to have (and will be needed down the line in 3.x) but in most cases would require human interaction to get it right. That would also make testing possible with the testkit: we can define a outputSource3 module using the same version of the compiler used for input but with an extra -Xsource:3, thus verifying that produced code actually compiles.
I wonder if this "migration" rule should be available in scalafix-rules though - could it be implemented/tested in https://github.com/scalacenter/scala3-migrate?
Rewrite underscores in imports and type arguments
https://scalameta.org/scalafmt/docs/configuration.html#scala3-rewrites
Closing, as scalafmt covers a lot of these rewrites, and more (semantic) can be added as community rules