Skip to content

Commit 94a6e37

Browse files
authored
Merge scalafix doc into fix (#3420)
1 parent da025a0 commit 94a6e37

File tree

2 files changed

+51
-50
lines changed

2 files changed

+51
-50
lines changed

website/docs/commands/fix.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,56 @@ You can pass it explicitly or set it globally by running:
1010
scala-cli config power true
1111
:::
1212

13-
The `fix` command scans your project for `using` directives and extracts them into the `project.scala` file placed in the project root directory.
14-
This allows to fix warnings tied to having `using` directives present in multiple files.
15-
Additionally, `fix` will format the result file, thus allowing to quickly spot configuration options that may be duplicated.
13+
The `fix` command is used to check, lint, rewrite or otherwise rearrange code in a Scala CLI project.
1614

17-
Files containing `using target` directives, e.g. `//> using target.scala 3.0.0` will not be changed by `fix`.
15+
Currently, the following sets of rules are supported:
16+
- built-in rules (enabled automatically and controlled with the `--enable-built-in` flag)
17+
- `scalafix`, running [Scalafix](https://scalacenter.github.io/scalafix/) under the hood (enabled automatically and controlled with `--enable-scalafix` flag).
1818

19-
The command respects the original scope of each extracted directive and will transform them into their `test.` equivalent if needed.
19+
You can disable unnecessary rule sets when needed.
20+
For example, to disable built-in rules, you can run:
21+
```bash
22+
scala-cli fix . --power --enable-built-in=false
23+
```
24+
25+
## Built-in rules
26+
27+
Currently, the only built-in rule is extraction of `using` directives into the `project.scala` configuration file.
28+
This allows to fix warnings tied to having `using` directives present in multiple files and eliminate duplicate directives.
29+
Files containing (experimental) `using target` directives, e.g. `//> using target.scala 3.0.0` will not be changed by `fix`.
30+
The original scope (`main` or `test`) of each extracted directive is respected. `main` scope directives are transformed
31+
them into their `test.*` equivalent when needed.
32+
33+
## `scalafix` integration
34+
35+
Scala CLI is capable of running [Scalafix](https://scalacenter.github.io/scalafix/) (a refactoring and linting tool for Scala) on your project.
36+
Before using this command you need to provide the configuration at `.scalafix.conf`.
37+
For example:
38+
``` text title=.scalafix.conf
39+
// .scalafix.conf
40+
rules = [
41+
DisableSyntax
42+
]
43+
```
44+
45+
Then you can run it:
46+
```bash
47+
scala-cli fix . --power
48+
```
49+
50+
If you’re setting up a continuous integration (CI) server, Scala CLI also has you covered.
51+
You can run linter using the `--check` flag:
52+
```bash fail
53+
scala-cli fix --check . --power
54+
```
55+
56+
Read more about Scalafix:
57+
- [Configuration](https://scalacenter.github.io/scalafix/docs/users/configuration.html)
58+
- [Rules](https://scalacenter.github.io/scalafix/docs/rules/overview.html)
59+
60+
### Using external rules
61+
62+
Adding an [external scalafix rule](https://scalacenter.github.io/scalafix/docs/rules/external-rules.html) to Scala CLI can be done with the [`scalafix.dep`](./compile.md#compile-only-dependencies) directive:
63+
```scala compile power
64+
//> using scalafix.dep com.github.xuwei-k::scalafix-rules:0.5.1
65+
```

website/docs/commands/scalafix.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)