Skip to content

Commit

Permalink
Merge pull request #2023 from tgodzik/add-inferred-type
Browse files Browse the repository at this point in the history
feature: ExplicitResultTypes for Scala 3
  • Loading branch information
bjaglin authored Sep 27, 2024
2 parents 590db62 + fe41df2 commit aadace9
Show file tree
Hide file tree
Showing 72 changed files with 932 additions and 240 deletions.
20 changes: 0 additions & 20 deletions .scalafix-scala3.conf

This file was deleted.

File renamed without changes.
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ lazy val rules = projectMatrix
semanticdbScalacCore,
collectionCompat
)
else Nil
else
Seq(
"org.scala-lang" %% "scala3-presentation-compiler" % scalaVersion.value,
coursierInterfaces
)
},
// companion of `.dependsOn(core)`
// issue reported in https://github.com/sbt/sbt/issues/7405
Expand Down
10 changes: 6 additions & 4 deletions docs/rules/ExplicitResultTypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ id: ExplicitResultTypes
title: ExplicitResultTypes
---

This rewrite inserts type annotations for inferred public members. Only compatible with
scala 2.12 & 2.13.
This rewrite inserts type annotations for inferred public members.

Example:

Expand Down Expand Up @@ -35,6 +34,9 @@ This rule has several known limitations, which are most likely fixable with some
effort. At the time of this writing, there are no short-term plans to address
these issues however.

Scala 3 support is recent and therefore not widely tested. Expect annotations
to be be less precise than the ones added to sources compiled with Scala 2.x.

### Imports ordering

The rewrite inserts imports at the bottom of the global import list. Users are
Expand All @@ -43,8 +45,8 @@ expected to organize the imports according to the conventions of their codebase.
For example, the rewrite may produce the following diff.

```diff
import java.io.File
import scala.collection.mutable
import java.io.File
import scala.collection.mutable
+ import java.util.UUID
```

Expand Down
20 changes: 5 additions & 15 deletions project/ScalafixBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
val xsource3 = TargetAxis(sv, xsource3 = true)

(prevVersions :+ xsource3).map((sv, _))
} :+ (scala3Next, TargetAxis(scala213))
} ++ Seq(
(scala3Next, TargetAxis(scala213)),
(scala3Next, TargetAxis(scala3LTS))
)

lazy val publishLocalTransitive =
taskKey[Unit]("Run publishLocal on this project and its dependencies")
Expand Down Expand Up @@ -280,13 +283,6 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
Compile / console / scalacOptions :=
compilerOptions.value :+ "-Yrepl-class-based",
Compile / doc / scalacOptions ++= scaladocOptions,
Compile / unmanagedResourceDirectories ++= {
val resourceParentDir = (Compile / resourceDirectory).value.getParentFile
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((major, _)) => Seq(resourceParentDir / s"resources-${major}")
case _ => Seq()
}
},
// Don't package sources & docs when publishing locally as it adds a significant
// overhead when testing because of publishLocalTransitive. Tweaking publishArtifact
// would more readable, but it would also affect remote (sonatype) publishing.
Expand Down Expand Up @@ -316,13 +312,7 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
if (scalaVersion.value.startsWith("3")) Set.empty
else Set.empty
},
mimaBinaryIssueFilters ++= Mima.ignoredABIProblems,
scalafixConfig := {
if (scalaBinaryVersion.value.startsWith("2"))
Some(file(".scalafix-scala2.conf"))
else
Some(file(".scalafix-scala3.conf"))
}
mimaBinaryIssueFilters ++= Mima.ignoredABIProblems
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ package scalafix.internal.util
import org.typelevel.paiges.Doc

object DocConstants {
val `|` = Doc.char('|')
val `&` = Doc.char('&')
val `.` = Doc.char('.')
val `#` = Doc.char('#')
val `(` = Doc.char('(')
val `)` = Doc.char(')')
val `[` = Doc.char('[')
val `]` = Doc.char(']')
val `{` = Doc.char('{')
val `}` = Doc.char('}')
val `=>` = Doc.text("=>")
val `=>>` = Doc.text("=>>")
val `()` = Doc.text("()")
val `*` = Doc.char('*')
val `|`: Doc = Doc.char('|')
val `&`: Doc = Doc.char('&')
val `.`: Doc = Doc.char('.')
val `#`: Doc = Doc.char('#')
val `(`: Doc = Doc.char('(')
val `)`: Doc = Doc.char(')')
val `[`: Doc = Doc.char('[')
val `]`: Doc = Doc.char(']')
val `{`: Doc = Doc.char('{')
val `}`: Doc = Doc.char('}')
val `=>`: Doc = Doc.text("=>")
val `=>>`: Doc = Doc.text("=>>")
val `()`: Doc = Doc.text("()")
val `*`: Doc = Doc.char('*')
val L: Doc = Doc.char('L')
val f: Doc = Doc.char('f')
val `:` = Doc.char(':')
val `@` = Doc.char('@')
val `:`: Doc = Doc.char(':')
val `@`: Doc = Doc.char('@')
val `val`: Doc = Doc.text("val")
val `var`: Doc = Doc.text("var")
val `def`: Doc = Doc.text("def")
Expand Down
4 changes: 2 additions & 2 deletions scalafix-core/src/main/scala/scalafix/v0/Symbol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ object Symbol {
// https://github.com/scalameta/scalameta/pull/1241.
def apply(s: String): Symbol = {
object naiveParser {
val EOL = System.lineSeparator()
val EOL: String = System.lineSeparator()
var i = 0
def fail(message: String = "invalid symbol format") = {
def fail(message: String = "invalid symbol format"): Nothing = {
val caret = " " * (i - 1) + "^"
throw new IllegalArgumentException(s"$message$EOL$s$EOL$caret")
}
Expand Down

This file was deleted.

Loading

0 comments on commit aadace9

Please sign in to comment.