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
The fix
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-in
flag) scalafix
, running Scalafix under the hood (enabled automatically and controlled with--enable-scalafix
flag).
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 of using
directives into the project.scala
configuration file.
This allows to fix warnings tied to having using
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 by fix
.
The original scope (main
or test
) of each extracted directive is respected. main
scope directives are transformed
them into their test.*
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 running Scalafix (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 an external scalafix rule to Scala CLI can be done with the scalafix.dep
directive:
//> using scalafix.dep com.github.xuwei-k::scalafix-rules:0.5.1