Project name | Porting of Scalafix ExplicitResultTypes rule to Scala 3 |
Organization | Scala Center, Scala Center Official Site |
Scala Center idea link | Project proposal link |
Github Issues | ExplicitResultType issue, Scalafix cross compiled to scala-3 |
Project links | Scalafix Github repo, Scalafix website |
Mentors | Meriam Lachkar, Brice Jaglin |
Contributor | Razvan Vacaru |
GSoC Proposal | GSoC Link |
Scalafix is a linting, code completion and rewriting tool for Scala codebases. The Scalafix tool can be used as a CLI from Terminal, as part of your build with the Maven plugin, Mill plugin or the SBT plugin, and finally Scalafix can run as part of your CICD pipelines.
Scalafix uses Scalameta and SemanticDb to parse the target source code into a traversable AST data structure. Scalafix then modifies the AST by applying its rules and then converts it back into Scala source code, with no change in the behaviour of the original source of course.
Scalafix is also an important part of the set of migration tools which will make it easier to migrate Scala code to Scala 3.
The good reasons for porting Scalafix and ExplicitResultTypes to Scala 3 are:
- Linting and re-writing code capabilities will be available for Scala 3 projects
- More readability of Scala3 code
- Better developer experience
- Better maintainability of Scala3 projects
- Scalafix rules written in Scala 3 will be compatible and compilable in Scala 2
- Scalafix helps in migrating code between Scala 2 and Scala 3 versions
Scalafix is currently build in Scala versions 2.11, 2.12 and 2.13. It relies on the Scala 2 compiler for:
- The ExplicitResultTypes Rule, where code is compiled in order to infer the Types of the members
- The Custom / External Rules compilation
Since Scalafix uses the Scala compiler, porting Scalafix or ExplicitResultTypes to Scala 3 also means reimplementing compilation logic in scalafix using the new Scala 3 Dotty compiler
A list of Pull requests, or commits, of the work done presented in chronological order:
- To familiarize with the Scalafix codebase, I picked up a bug related to ExplicitResultTypes:
- Scalafix-core module cross compiled in Scala 3, PR Link
- Ask Mill-Scalafix maintainers to release with Scalafix 0.10.0
- Scalafix-rules module cross compiled in Scala 3
- Update Unit module Scalatest version to 3.2.13
- RuleCompiler using dotty compiler, for Scala 3 compilation
- Scalafix-Reflect + Scalafix-cli + Test modules cross compiled to Scala 3
- Squashed commits: Scalafix-reflect3 cross compiled for Scala 3
- Squashed commits: Scalafix-cli3 cross compiled for Scala 3
- Squashed commits: Scalafix-testkit3 cross compiled for Scala 3
- Unit module test fixes, RuleCompiler fixes, minor refactoring to code or sbt build, see commits
A list of web resources used while working on the project:
The Project is unfortunately not finished, even given a project extension from the regular 12 weeks length. These are the task still to be done:
- Finish the cross compilation of Scalafix to Scala 3
- In particular fixing unit tests
ScalafixArgumentsSuite
andScalafixImplSuite
- In particular fixing unit tests
- Publishing a new Scalafix version for Scala 3, without ExplicitResultTypes
- Implement ExplicitResultTypes using the dotty compiler
Next Steps:
- Make Scalafix-cli_3 fallback on loading 2.13 artifacts for requested community rules
- Advocate for community rules to cross compile to Scala 3 by updating:
- Scalafix Giter8 template
- Scalafix docs on cross publishing rule artifacts not yet available in Scala 3
- Support for running Scalafix-cli_3 in sbt-scalafix plugin
I really want to express my gratitude and thank my mentors Meriam Lachkar and Brice Jaglin for their consistent help during the project, without their support and advice this wouldn't have been possible. I also want to say thank you to Google and everyone involved in the GSoC programme, which is an awesome initiative to promote Open Source.
This project is dear to me personally, for many reasons. First of all, this is a small dream come true, to contribute to such an important open source organization like Scala Center. Only some years ago I was learning Scala from the official EPFL Coursera course, and now I'm helping with the Scala 3 migration via Scalafix. This proves again that with perseverance, consistency and will power we can realize our dreams. Moreover with this project I'm completing my first decade of career, and I think of it as a nice cherry on the cake.
From time to time I have asked for help or advice to the community:
- Scala Center Discord channel - https://discord.com/invite/scala
- Scalameta Discord channel - https://discord.com/invite/RFpSVth
- Scalafix Gitter channel - https://gitter.im/scalacenter/scalafix
- This will soon be archived in favor of the new channel on the Scalameta Discord
(Thanks to everyone in the above chatrooms who helped and replied to my questions)