Skip to content

Commit

Permalink
scalafix: support ExplicitResultTypes for scala3 + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dos65 committed Nov 6, 2024
1 parent 512b309 commit 789f70a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ object Scalafix extends ScalaCommand[ScalafixOptions] {
options.scalafixConf.toList.flatMap(scalafixConf => List("--config", scalafixConf)) ++
Seq("--sourceroot", workspace.toString) ++
Seq("--classpath", classPaths.mkString(java.io.File.pathSeparator)) ++
Seq("--scala-version", scalaVersion) ++
(if (options.check) Seq("--test") else Nil) ++
(if (scalacOptions.nonEmpty) scalacOptions.flatMap(Seq("--scalac-options", _))
else Nil) ++
Expand All @@ -130,6 +131,8 @@ object Scalafix extends ScalaCommand[ScalafixOptions] {
options.rules.flatMap(Seq("-r", _))
++ options.scalafixArg

println(s"AAAAAAAAAAAA: ${artifacts.scalafixJars}")

val proc = Runner.runJvm(
buildOptions.javaHome().value.javaCommand,
buildOptions.javaOptions.javaOpts.toSeq.map(_.value.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,25 @@ abstract class ScalafixTestDefinitions extends ScalaCliSuite with TestScalaVersi

test("external rule") {
val original: String =
"""|//> using scalafix.dep "io.github.ghostbuster91.scalafix-unified::unified:0.0.8"
"""|//> using scalafix.dep "com.github.xuwei-k::scalafix-rules:0.5.1"
|
|package foo
|
|object Hello {
| val a = List[Int]()
|object CollectHeadOptionTest {
| def x1: Option[String] = List(1, 2, 3).collect { case n if n % 2 == 0 => n.toString }.headOption
|}
|""".stripMargin
val inputs: TestInputs = TestInputs(
os.rel / confFileName ->
s"""|rules = [
| EmptyCollectionsUnified
| CollectHeadOption
|]
|""".stripMargin,
os.rel / "Hello.scala" -> original
)
val expectedContent: String = noCrLf {
"""|//> using scalafix.dep "io.github.ghostbuster91.scalafix-unified::unified:0.0.8"
"""|//> using scalafix.dep "com.github.xuwei-k::scalafix-rules:0.5.1"
|
|package foo
|
|object Hello {
| val a = List.empty[Int]
|object CollectHeadOptionTest {
| def x1: Option[String] = List(1, 2, 3).collectFirst{ case n if n % 2 == 0 => n.toString }
|}
|""".stripMargin
}
Expand All @@ -267,10 +263,7 @@ abstract class ScalafixTestDefinitions extends ScalaCliSuite with TestScalaVersi
}
}

test {
val name = "explicit-result-types"
if (actualScalaVersion.startsWith("3")) name.ignore else munit.TestOptions(name)
} {
test("explicit-result-types") {
val original: String =
"""|package foo
|
Expand Down
4 changes: 2 additions & 2 deletions website/docs/commands/scalafix.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Read more about Scalafix:

### Using external rules

Adding an [external scalafix rule]() to scala-cli might be done by declaring [`scalafix.dep`](./compile.md#compile-only-dependencies):
Adding an [external scalafix rule](https://scalacenter.github.io/scalafix/docs/rules/external-rules.html) to scala-cli might be done by declaring [`scalafix.dep`](./compile.md#compile-only-dependencies):
```scala title=externalRule.scala
//> using scalafix.dep "com.github.jatcwang::scalafix-named-params:0.2.5"
//> using scalafix.dep "com.github.xuwei-k::scalafix-rules:0.5.1"
```

0 comments on commit 789f70a

Please sign in to comment.