scalacenter / student-projects

The list of the available projects at the Scala Center for bachelor and master students.
8 stars 0 forks source link

Create the syntax rewrite in Scalafix for Scala 3 #14

Closed adpi2 closed 9 months ago

adpi2 commented 1 year ago

Context

Scalafix

Scalafix is the refactoring and linting tool for Scala. Scalafix is a tool and a collection of rule that one can apply in its codebase to refactor some patterns or to get some linting errors. Examples of rules are:

Scalafix is also a library that one can use to define its own rule.

Scala 3 new syntax

In Scala 3, we have a new control structure syntax and the new indentation syntax.

Control structure syntax

https://docs.scala-lang.org/scala3/reference/other-new-features/control-syntax.html

Traditional Scala 2 syntax:

if (cond) {
  branch1
} else  {
  branch2
}

while (cond) {
  loop
}

New Scala 3 syntax:

if cond then
  branch1
else
  branch2

while cond do
  loop

Indentation syntax

https://docs.scala-lang.org/scala3/reference/other-new-features/indentation.html#

Traditional curly-brace syntax:

class A {
  def foo = {
    body
  }
}

New Scala 3 significant indentation syntax:

class A :
  def foo =
    body

Description of the project

The goal of the project is to create Scalafix rules to refactor a codebase to the new control structure syntax and to the significant indentation syntax.

Those rules are already implemented in the Scala 3 compiler itself, however they are not very flexible:

With Scalafix we can have some configuration:

We can try to merge both rules in a single one.

We can integrate the rule in Metals to run the rule in a single file.

Expected outcome

We expect the student to implement the rewrite rules and to define some meaningful configuration on them.

An important requirement are the tests: each rule and configuration should be well-tested using the Scalafix test infrastructure.

Supervisor

Adrien Piquerez(adrien.piquerez@epfl.ch): Tooling Engineer at the Scala Center

adpi2 commented 9 months ago

https://github.com/kotleta2007/scala3-syntax-rewrite Master_Project_Report_TROPIN_Mark_Jan2024.pdf