@@ -15,7 +15,7 @@ Note that other setups may work, but could result in unexpected behavior.
15
15
16
16
## sbt
17
17
18
- Start by installing the sbt 1.4+ plugin in ` project/plugins.sbt `
18
+ Start by installing the sbt 1.4+ plugin in ` project/plugins.sbt ` :
19
19
20
20
``` scala
21
21
// project/plugins.sbt
@@ -24,15 +24,15 @@ addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "@VERSION@")
24
24
25
25
> Scalafix is no longer published for Scala 2.11. You can run the final version
26
26
> of Scalafix supporting 2.11, but all features documented below might not be
27
- > supported.
27
+ > supported:
28
28
> ``` scala
29
29
> // project/plugins.sbt
30
30
> addSbtPlugin(" ch.epfl.scala" % " sbt-scalafix" % " 0.10.4" ) // final Scala 2.11 version
31
31
> ```
32
32
33
33
> sbt- scalafix is no longer published for sbt 0.13 .x. You should be able to run
34
34
> the latest version of Scalafix with the final sbt- scalafix version published
35
- > for sbt 0.13 .x, but all features documented below might not be supported.
35
+ > for sbt 0.13 .x, but all features documented below might not be supported :
36
36
>
37
37
> ```scala
38
38
> // project/plugins.sbt
@@ -42,7 +42,7 @@ addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "@VERSION@")
42
42
43
43
[! [Maven Central ](https:// maven- badges.herokuapp.com/ maven- central/ ch.epfl.scala/ sbt- scalafix/ badge.svg)](https:// maven- badges.herokuapp.com/ maven- central/ ch.epfl.scala/ sbt- scalafix)
44
44
45
- From the sbt shell, let' s run the rule `ProcedureSyntax`
45
+ From the sbt shell, let' s run the rule `ProcedureSyntax` :
46
46
47
47
```
48
48
> myproject / scalafix ProcedureSyntax
@@ -52,14 +52,14 @@ It's normal that the first invocation of `scalafix` takes a while to download
52
52
Scalafix artifacts from Maven Central.
53
53
54
54
If all went well and your project uses the deprecated "procedure syntax", you
55
- should have a diff in your sources like this
55
+ should have a diff in your sources like this:
56
56
57
57
```diff
58
58
- def myProcedure {
59
59
+ def myProcedure: Unit = {
60
60
```
61
61
62
- Next, if we run another rule like ` RemoveUnused ` then we get an error
62
+ Next, if we run another rule like ` RemoveUnused ` then we get an error:
63
63
64
64
```
65
65
> myproject / scalafix RemoveUnused
@@ -71,11 +71,10 @@ problem, update your build to add -Ywarn-unused-import (with 2.12) ...
71
71
```
72
72
73
73
The first error message means the
74
- [ SemanticDB] ( https://scalameta.org/docs/semanticdb/guide.html ) compiler plugin
75
- is not enabled for this project. The second error says ` RemoveUnused ` requires
76
-
77
- the Scala compiler option ` -Ywarn-unused-import ` (or ` -Wunused:imports ` in
78
- 2.13.x or 3.x). To fix both problems, add the following settings to ` build.sbt `
74
+ [ SemanticDB] ( https://scalameta.org/docs/semanticdb/guide.html ) compiler output
75
+ is not enabled for this project. The second error says that ` RemoveUnused `
76
+ requires the Scala compiler option ` -Ywarn-unused-import ` (or ` -Wunused:imports `
77
+ in 2.13.x or 3.x). To fix both problems, add the following settings to ` build.sbt ` :
79
78
80
79
``` diff
81
80
/*
@@ -124,15 +123,15 @@ For `project/*.scala` files, add
124
123
` import scalafix.sbt.ScalafixPlugin.autoImport._ ` to the top of the file to
125
124
resolve ` scalafixSemanticdb ` .
126
125
127
- We run ` RemoveUnused ` again and the error is now gone
126
+ We run ` RemoveUnused ` again and the error is now gone:
128
127
129
128
```
130
129
> myproject / scalafix RemoveUnused
131
130
[info] Compiling 15 Scala sources to ...
132
131
[info] Running scalafix on 15 Scala sources
133
132
```
134
133
135
- If your project has unused imports, you should see a diff like this
134
+ If your project has unused imports, you should see a diff like this:
136
135
137
136
``` diff
138
137
- import scala.util.{ Success, Failure }
@@ -184,7 +183,7 @@ The task `myproject / scalafix` runs for **main sources** in the project
184
183
By default, the `scalafix` command is enabled for the `Compile` and `Test`
185
184
configurations, and `scalafixAll` will run on both of them. To enable
186
185
Scalafix for other configuration like `IntegrationTest`, add the following
187
- to your project settings
186
+ to your project settings:
188
187
189
188
```diff
190
189
lazy val myproject = project
@@ -219,7 +218,7 @@ fetch Scalafix artifacts from Maven Central. These artifacts are by default
219
218
cached [ inside the home directory] ( https://get-coursier.io/docs/cache.html#default-location ) .
220
219
To avoid redundant downloads on every pull request, it's recommended to configure
221
220
your CI enviroment to cache this directory. The location can be customized with
222
- the environment variable ` COURSIER_CACHE `
221
+ the environment variable ` COURSIER_CACHE ` :
223
222
224
223
``` sh
225
224
export COURSIER_CACHE=$HOME /.custom-cache
@@ -240,7 +239,7 @@ feature with care as it has several shortcomings, for example:
240
239
before a call to ` scalafix[All] --check ` , causing this one to run on dirty
241
240
sources and thus pass while it should not. Make sure that ` scalafixOnCompile `
242
241
is disabled on CI or, if that is impossible, that ` scalafix[All] --check `
243
- is the first task executed, without any other concurrently .
242
+ is the first task executed, without any other at the same time .
244
243
1 . Some rules such as ` RemoveUnused ` can be counter-productive if applied too
245
244
often/early, as the work-in-progress code that was just added might disappear
246
245
after a simple ` test ` .
@@ -251,13 +250,9 @@ feature with care as it has several shortcomings, for example:
251
250
stale information and fail the invocation, which needs to be re-run manually.
252
251
This is [ not specific to ` scalafixOnCompile ` ] ( https://github.com/scalacenter/scalafix/issues/1204 ) ,
253
252
but the problem becomes much more visible with it.
254
- 1 . To keep the overhead minimal, ` scalafixCaching ` is automatically enabled when
255
- ` scalafixOnCompile ` is, which can cause unexpected behaviors if you run into
256
- false positive cache hits. ` scalafixCaching ` can explicitly be set to
257
- ` false ` in that case.
258
253
1 . Non-idempotent rewrite rules might get you in an infinite loop where sources
259
- never converge - not specific to ` scalafixOnCompile ` either , but rather
260
- confusing when triggered automatically.
254
+ never converge - not specific to ` scalafixOnCompile ` , but rather confusing
255
+ when triggered automatically.
261
256
1 . Bugs in rule implementations can prevent you from getting a successful
262
257
` compile ` , blocking testing or publishing for example
263
258
@@ -295,13 +290,13 @@ If all went well, you should see a diff adding the comment
295
290
By default, the SemanticDB compiler plugin will process all files in a project.
296
291
297
292
Use ` -P:semanticdb:exclude:<regex> ` to exclude files from the SemanticDB
298
- compiler plugin.
293
+ compiler plugin:
299
294
300
295
``` scala
301
296
scalacOptions += " -P:semanticdb:exclude:Macros.scala"
302
297
```
303
298
304
- Separate multiple patterns with pipe ` | ` to exclude multiple files.
299
+ Separate multiple patterns with pipe ` | ` to exclude multiple files:
305
300
306
301
``` scala
307
302
scalacOptions += " -P:semanticdb:exclude:Macros.scala|Schema.scala"
@@ -322,7 +317,7 @@ Scala 2.x, the `scalafix` task also respects
322
317
[ ` -P:semanticdb:exclude ` ] ( #exclude-files-from-semanticdb-scala-2x-only ) .
323
318
324
319
Use ` Compile / scalafix / unmanagedSources ` to optionally exclude files from
325
- the ` scalafix ` task.
320
+ the ` scalafix ` task:
326
321
327
322
``` scala
328
323
Compile / scalafix / unmanagedSources :=
@@ -339,15 +334,15 @@ The `*.semanticdb` files are available in the directory referenced by the
339
334
` semanticdbTargetRoot ` key, which defaults to ` target/scala-x/meta ` .
340
335
341
336
You can override this default to emit ` *.semanticdb ` files in a custom
342
- location. For example :
337
+ location:
343
338
344
339
``` scala
345
340
semanticdbTargetRoot := target.value / " semanticdb"
346
341
```
347
342
348
343
Alternatively, you can set the ` semanticdbIncludeInJar ` key to request
349
344
the compiler to emit these files into the ` classDirectory ` so that they
350
- are available in packaged JARs.
345
+ are available in packaged JARs:
351
346
352
347
``` scala
353
348
semanticdbIncludeInJar := true
@@ -356,7 +351,7 @@ semanticdbIncludeInJar := true
356
351
### Disable Scalafix for specific project
357
352
358
353
Use ` .disablePlugins(ScalafixPlugin) ` to disable Scalafix for a particular
359
- project.
354
+ project:
360
355
361
356
``` diff
362
357
lazy val myproject = project
@@ -365,7 +360,7 @@ project.
365
360
```
366
361
367
362
When using Scala.js or Scala Native, use ` .jsConfigure ` or ` .nativeConfigure ` to
368
- disable Scalafix for only the Scala.js or Scala Native project. For example :
363
+ disable Scalafix for only the Scala.js or Scala Native project:
369
364
370
365
``` diff
371
366
lazy val myproject = crossProject(JVMPlatform, JSPlatform)
@@ -377,7 +372,7 @@ disable Scalafix for only the Scala.js or Scala Native project. For example:
377
372
378
373
Instead of permanently enabling SemanticDB in build.sbt, use the
379
374
` scalafixEnable ` command to enable SemanticDB the current active sbt shell
380
- session.
375
+ session:
381
376
382
377
```
383
378
> scalafixEnable
@@ -411,25 +406,35 @@ git diff // should produce a diff
411
406
First, install the [ Coursier] ( https://get-coursier.io/docs/cli-installation )
412
407
command-line interface.
413
408
414
- Then, download the Scalafix runner built with the latest version of Scala
415
- (@SCALA3NEXT @)
409
+ Then, install or launch a Scalafix runner built with the latest version of Scala
410
+ (@SCALA3NEXT @):
416
411
417
412
``` sh
418
413
cs install scalafix
419
- ./scalafix --version # Should say @VERSION@
414
+ scalafix --version # Should say @VERSION@
415
+
416
+ cs install scalafix:0.14.0
417
+ scalafix --version # Should say 0.14.0
418
+
419
+ cs launch scalafix:0.13.0 -- --version # Should say 0.13.0
420
420
```
421
421
422
422
> If you plan to use advanced semantic rules like ` ExplicitResultTypes ` , you
423
423
> must use the version of Scalafix built with a Scala version matching your
424
- > target source files.
424
+ > target source files (major.minor) .
425
425
>
426
426
> If your target files are not built with the latest minor version of Scala,
427
- > use one of the following commands to create a custom runner
427
+ > use one of the following commands to create a custom runner:
428
428
>
429
429
> ``` sh
430
430
> cs bootstrap ch.epfl.scala:scalafix-cli_@SCALA212@:@VERSION@ --main scalafix.cli.Cli -o scalafix_2.12
431
431
> cs bootstrap ch.epfl.scala:scalafix-cli_@SCALA213@:@VERSION@ --main scalafix.cli.Cli -o scalafix_2.13
432
- > cs bootstrap ch.epfl.scala:scalafix-cli_@SCALA3LTS@:@VERSION@ --main scalafix.cli.Cli -o scalafix_3-lts
432
+ > cs bootstrap ch.epfl.scala:scalafix-cli_@SCALA3LTS@:@VERSION@ --main scalafix.cli.Cli -o scalafix_3.3-lts
433
+ > ` ` `
434
+ >
435
+ > Alternatively, you can run a one-shot command:
436
+ > ` ` ` sh
437
+ > cs launch --scala X.Y scalafix -- --version
433
438
> ` ` `
434
439
435
440
# ## Help
@@ -453,7 +458,7 @@ Scalafix is supported in other build tools via externally maintained plugins:
453
458
Our CI publishes a snapshot release to Sonatype on every merge into main. Each
454
459
snapshot release has a unique version number, jars don't get overwritten.
455
460
456
- If using the sbt plugin
461
+ If using the sbt plugin:
457
462
458
463
``` diff
459
464
// project/plugins.sbt
@@ -462,7 +467,7 @@ If using the sbt plugin
462
467
+ dependencyOverrides += "ch.epfl.scala" % "scalafix-interfaces" % "@NIGHTLY_VERSION@"
463
468
```
464
469
465
- If using the command-line interface
470
+ If using the command-line interface:
466
471
467
472
``` sh
468
473
cs launch ch.epfl.scala:scalafix-cli_@SCALA213@:@NIGHTLY_VERSION@ -r sonatype:snapshots --main scalafix.cli.Cli -- --help
0 commit comments