Skip to content

Commit

Permalink
Merge scalafix doc into fix (#3420)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao authored Jan 13, 2025
1 parent da025a0 commit 94a6e37
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 50 deletions.
56 changes: 51 additions & 5 deletions website/docs/commands/fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,56 @@ You can pass it explicitly or set it globally by running:
scala-cli config power true
:::

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

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

The command respects the original scope of each extracted directive and will transform them into their `test.` equivalent if needed.
You can disable unnecessary rule sets when needed.
For example, to disable built-in rules, you can run:
```bash
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.

## `scalafix` integration

Scala CLI is capable of running [Scalafix](https://scalacenter.github.io/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:
``` text title=.scalafix.conf
// .scalafix.conf
rules = [
DisableSyntax
]
```

Then you can run it:
```bash
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:
```bash fail
scala-cli fix --check . --power
```

Read more about Scalafix:
- [Configuration](https://scalacenter.github.io/scalafix/docs/users/configuration.html)
- [Rules](https://scalacenter.github.io/scalafix/docs/rules/overview.html)

### Using external rules

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:
```scala compile power
//> using scalafix.dep com.github.xuwei-k::scalafix-rules:0.5.1
```
45 changes: 0 additions & 45 deletions website/docs/commands/scalafix.md

This file was deleted.

0 comments on commit 94a6e37

Please sign in to comment.