-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sbt-scalafix doc updates #1572
Merged
Merged
sbt-scalafix doc updates #1572
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,11 @@ pull request is tested on both Linux and Windows. | |
@SCALA211@, @SCALA212@ and @SCALA213@. | ||
|
||
**Scala 3.x**: Scala 3 support is experimental and many built-in rules are not | ||
supported. Make sure you follow the "sbt 1.3x and newer" instructions below. | ||
supported. | ||
|
||
## sbt | ||
|
||
Start by installing the sbt 1.x plugin in `project/plugins.sbt` | ||
Start by installing the sbt 1.3+ plugin in `project/plugins.sbt` | ||
|
||
```scala | ||
// project/plugins.sbt | ||
|
@@ -74,8 +74,9 @@ the Scala compiler option `-Ywarn-unused-import` (or `-Wunused:imports` in | |
|
||
```diff | ||
/* | ||
* build.sbt, for sbt 1.3x and newer | ||
* build.sbt | ||
* SemanticDB is enabled for all sub-projects via ThisBuild scope. | ||
* https://www.scala-sbt.org/1.x/docs/sbt-1.3-Release-Notes.html#SemanticDB+support | ||
*/ | ||
inThisBuild( | ||
List( | ||
|
@@ -92,8 +93,9 @@ the Scala compiler option `-Ywarn-unused-import` (or `-Wunused:imports` in | |
|
||
```diff | ||
/* | ||
* build.sbt, for sbt 1.3x and newer | ||
* build.sbt | ||
* SemanticDB is enabled only for a sub-project. | ||
* https://www.scala-sbt.org/1.x/docs/sbt-1.3-Release-Notes.html#SemanticDB+support | ||
*/ | ||
lazy val myproject = project.settings( | ||
scalaVersion := "@SCALA212@", // @SCALA211@, @SCALA213@, or 3.x | ||
|
@@ -103,18 +105,6 @@ the Scala compiler option `-Ywarn-unused-import` (or `-Wunused:imports` in | |
) | ||
``` | ||
|
||
```diff | ||
// build.sbt, for sbt 1.2.x and older (Scala 2.x only) | ||
lazy val myproject = project.settings( | ||
scalaVersion := "@SCALA212@", // @SCALA211@, or @SCALA213@ | ||
+ addCompilerPlugin(scalafixSemanticdb), // enable SemanticDB | ||
scalacOptions ++= List( | ||
+ "-Yrangepos", // required by SemanticDB compiler plugin | ||
+ "-Ywarn-unused-import" // required by `RemoveUnused` rule | ||
) | ||
) | ||
``` | ||
|
||
For `project/*.scala` files, add | ||
`import scalafix.sbt.ScalafixPlugin.autoImport._` to the top of the file to | ||
resolve `scalafixSemanticdb`. | ||
|
@@ -331,8 +321,7 @@ processed. | |
|
||
### Customize SemanticDB output directory | ||
|
||
When using the `semanticdbEnabled` key with sbt 1.3x and newer, the | ||
`*.semanticdb` files are available in the directory referenced by the | ||
The `*.semanticdb` files are available in the directory referenced by the | ||
`semanticdbTargetRoot` key, which defaults to `target/scala-x/meta`. | ||
|
||
You can override this default to emit `*.semanticdb` files in a custom | ||
|
@@ -382,44 +371,28 @@ session. | |
> scalafix RemoveUnused | ||
``` | ||
|
||
The `scalafixEnable` command automatically runs | ||
`addCompilerPlugin(scalafixSemanticdb)` and `scalacOptions += "-Yrangepos"` for | ||
all eligible projects in the builds. The change in Scala compiler options means | ||
the project needs to be re-built on the next `compile`. | ||
The `scalafixEnable` command automatically enables semanticdb output and adds | ||
`scalacOptions += "-Yrangepos"` for all eligible projects in the builds. The | ||
change in Scala compiler options means the project may need to be re-built on | ||
the next `compile`. | ||
|
||
> The `scalafixEnable` command must be re-executed after every `reload` and when | ||
> sbt shell is exited. | ||
|
||
### Optionally enable SemanticDB | ||
|
||
It's possible to optionally enable the SemanticDB compiler plugin by updating | ||
build.sbt like this: | ||
|
||
```diff | ||
// build.sbt | ||
- addCompilerPlugin(scalafixSemanticdb) | ||
- scalacOptions += "-Yrangepos" | ||
+ def shouldEnableSemanticdb: Boolean = ??? // fill this part | ||
+ libraryDependencies ++= { | ||
+ if (shouldEnableSemanticdb) List(compilerPlugin(scalafixSemanticdb)) | ||
+ else List() | ||
+ } | ||
+ scalacOptions ++= { | ||
+ if (shouldEnableSemanticdb) List("-Yrangepos") | ||
+ else List() | ||
+ } | ||
``` | ||
|
||
### Verify installation | ||
|
||
To verify that the SemanticDB compiler plugin is enabled, check that the | ||
settings `scalacOptions` and `libraryDependencies` contain the values below. | ||
settings `scalacOptions` and `allDependencies` contain the values below. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
```sh | ||
> show scalacOptions | ||
[info] * -Yrangepos | ||
> show libraryDependencies | ||
[info] * org.scalameta:semanticdb-scalac:@SCALA212@:plugin->default(compile) | ||
> show Compile / scalacOptions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
... | ||
[info] * List(..., -Yrangepos, ...) | ||
... | ||
> show allDependencies | ||
... | ||
[info] List(..., org.scalameta:semanticdb-scalac:@SCALA212@:plugin->default(compile), ...) | ||
... | ||
``` | ||
|
||
### Example project | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this as it's now fairly standard since https://www.scala-sbt.org/1.x/docs/sbt-1.3-Release-Notes.html#SemanticDB+support (link added at the top of the page)