Fix ⚡️
The Fix command is experimental and requires setting the--power option to be used.You can pass it explicitly or set it globally by running:
scala-cli config power true
Thefix command is used to check, lint, rewrite or otherwise rearrange code in a Scala CLI project.
Currently, the following sets of rules are supported:
- built-in rules (enabled automatically and controlled with the
--enable-built-inflag) scalafix, runningScalafix under the hood (enabled automatically and controlled with--enable-scalafixflag).
You can disable unnecessary rule sets when needed.For example, to disable built-in rules, you can run:
scala-cli fix.--power --enable-built-in=false
Built-in rules
Currently, the only built-in rule is extraction ofusing directives into theproject.scala configuration file.This allows to fix warnings tied to havingusing directives present in multiple files and eliminate duplicate directives.Files containing (experimental)using target directives, e.g.//> using target.scala 3.0.0 will not be changed byfix.The original scope (main ortest) of each extracted directive is respected.main scope directives are transformedthem into theirtest.* equivalent when needed.
Exceptions:
- directives won't be extracted for single-file projects;
- directives in test inputs with no test scope equivalents won't be extracted to preserve their initial scope.
scalafix integration
Scala CLI is capable of runningScalafix (a refactoring and linting tool for Scala) on your project.Before using this command you need to provide the configuration at.scalafix.conf.For example:
// .scalafix.conf
rules = [
DisableSyntax
]
Then you can run it:
scala-cli fix.--power
If you’re setting up a continuous integration (CI) server, Scala CLI also has you covered.You can run linter using the--check flag:
scala-cli fix--check.--power
Read more about Scalafix:
Using external rules
Adding anexternal scalafix rule to Scala CLI can be done with thescalafix.dep directive:
//> using scalafix.dep com.github.xuwei-k::scalafix-rules:0.5.1