From 52087160dadf63c79f05f6f9cc4de1be86f6e793 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 10 Jan 2022 17:40:18 +0100 Subject: [PATCH] Bump pprint, fansi and fs2. Also, refactor them to be detected automatically by steward --- .github/workflows/ci.yml | 1 - build.sbt | 74 +++++++++---------- .../scala/mdoc/internal/cli/Settings.scala | 20 ++++- .../mdoc/internal/markdown/Processor.scala | 5 +- .../mdoc/internal/markdown/Renderer.scala | 5 +- project/plugins.sbt | 4 +- .../mdoc/internal/document/Printing.scala | 2 +- .../scala/tests/cli/ScalacOptionsSuite.scala | 2 +- .../scala/tests/markdown/DefaultSuite.scala | 7 ++ .../scala/tests/markdown/SemanticsSuite.scala | 10 +++ 10 files changed, 77 insertions(+), 53 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index abd58c3bb..8d6ffb157 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,6 @@ jobs: matrix: java: [adopt@1.8, adopt@1.11, 17] command: - - "'++2.11.12 test'" # Test legacy Scala versions, where reporting API changed - "'++2.12.12 test'" - "'++2.12.14 test'" diff --git a/build.sbt b/build.sbt index 7cc79241d..981d7024b 100644 --- a/build.sbt +++ b/build.sbt @@ -1,10 +1,9 @@ import scala.collection.mutable def scala212 = "2.12.15" -def scala211 = "2.11.12" def scala213 = "2.13.7" def scala3 = "3.1.0" -def scala2Versions = List(scala212, scala211, scala213) +def scala2Versions = List(scala212, scala213) def allScalaVersions = scala2Versions :+ scala3 def scalajs = "1.7.1" @@ -13,7 +12,6 @@ def scalajsDom = "2.0.0" def isScala2(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) def isScala212(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exists(_._2 == 12) -def isScala211(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 2) && v.exists(_._2 == 11) def isScala3(v: Option[(Long, Long)]): Boolean = v.exists(_._1 == 3) val isScala212 = Def.setting { @@ -60,7 +58,6 @@ def crossSetting[A]( CrossVersion.partialVersion(scalaVersion) match { case partialVersion if isScala2(partialVersion) => if2 case partialVersion if isScala3(partialVersion) => if3 - case partialVersion if isScala211(partialVersion) => if2 ::: if211 case partialVersion if isScala212(partialVersion) => if2 ::: if212 case _ => Nil } @@ -116,21 +113,10 @@ val V = new { val munit = "0.7.29" val coursier = "1.0.6" val scalacheck = "1.15.4" -} - -lazy val pprintVersion = Def.setting { - if (scalaVersion.value.startsWith("2.11")) "0.5.4" - else "0.6.0" -} - -lazy val fansiVersion = Def.setting { - if (scalaVersion.value.startsWith("2.11")) "0.2.6" - else "0.2.9" -} - -lazy val fs2Version = Def.setting { - if (scalaVersion.value.startsWith("2.11")) "2.1.0" - else "2.5.5" + val pprint = "0.7.1" + val fansi = "0.3.0" + val fs2 = "3.2.4" + val metaconfig = "0.9.16" } lazy val interfaces = project @@ -164,7 +150,7 @@ lazy val runtime = project libraryDependencies ++= crossSetting( scalaVersion.value, if2 = List( - "com.lihaoyi" %% "pprint" % pprintVersion.value, + "com.lihaoyi" %% "pprint" % V.pprint, "org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided, "org.scala-lang" % "scala-compiler" % scalaVersion.value % Provided ), @@ -176,18 +162,33 @@ lazy val runtime = project .dependsOn(interfaces) val excludePprint = ExclusionRule(organization = "com.lihaoyi") +val excludeCollection = + ExclusionRule(organization = "org.scala-lang.modules", name = "scala-collection-compat_2.13") lazy val cli = project .settings( sharedSettings, moduleName := "mdoc-cli", scalaVersion := scala213, - crossScalaVersions := scala2Versions, + crossScalaVersions := allScalaVersions, libraryDependencies ++= List( "io.get-coursier" % "interface" % V.coursier, "com.vladsch.flexmark" % "flexmark-all" % "0.62.2", - "org.scalameta" %% "scalameta" % V.scalameta, - "com.geirsson" %% "metaconfig-typesafe-config" % "0.9.10" + "com.lihaoyi" %% "pprint" % V.pprint, + "com.geirsson" %% "metaconfig-typesafe-config" % V.metaconfig + ), + libraryDependencies ++= crossSetting( + scalaVersion.value, + if2 = List( + ("org.scalameta" %% "scalameta" % V.scalameta) + .excludeAll(excludePprint) + ), + if3 = List( + ("org.scalameta" %% "scalameta" % V.scalameta) + .excludeAll(excludePprint) + .excludeAll(excludeCollection) + .cross(CrossVersion.for3Use2_13) + ) ) ) @@ -218,13 +219,13 @@ lazy val mdoc = project "org.scala-lang" %% "scala3-compiler" % scalaVersion.value, ("org.scalameta" %% "scalameta" % V.scalameta) .excludeAll(excludePprint) + .excludeAll(excludeCollection) .cross(CrossVersion.for3Use2_13) ), if2 = List( "org.scala-lang" % "scala-compiler" % scalaVersion.value, - "org.scalameta" %% "scalameta" % V.scalameta, - "com.geirsson" %% "metaconfig-typesafe-config" % "0.9.10", - "com.lihaoyi" %% "fansi" % fansiVersion.value + ("org.scalameta" %% "scalameta" % V.scalameta) + .excludeAll(excludePprint) ) ), libraryDependencies ++= List( @@ -233,7 +234,10 @@ lazy val mdoc = project // live reload "io.undertow" % "undertow-core" % "2.2.14.Final", "org.jboss.xnio" % "xnio-nio" % "3.8.5.Final", - "org.slf4j" % "slf4j-api" % "1.7.33" + "org.slf4j" % "slf4j-api" % "1.7.33", + "com.geirsson" %% "metaconfig-typesafe-config" % V.metaconfig, + "com.lihaoyi" %% "fansi" % V.fansi, + "com.lihaoyi" %% "pprint" % V.pprint ) ) .dependsOn(runtime, cli) @@ -320,11 +324,11 @@ lazy val unit = project libraryDependencies ++= crossSetting( scalaVersion.value, if3 = List( - ("co.fs2" %% "fs2-core" % fs2Version.value) + ("co.fs2" %% "fs2-core" % V.fs2) .cross(CrossVersion.for3Use2_13) ), if2 = List( - "co.fs2" %% "fs2-core" % fs2Version.value + "co.fs2" %% "fs2-core" % V.fs2 ) ), buildInfoPackage := "tests.cli", @@ -452,11 +456,7 @@ def localCrossPublish(versions: List[String]): Def.Initialize[Task[Unit]] = .reduceLeft(_ dependsOn _) def localCrossPublishProjects(scalaV: String): Def.Initialize[Task[Unit]] = { - val projects = - if (scalaV.startsWith("3")) - List(runtime, mdoc, js).reverse - else - List(runtime, cli, mdoc, js).reverse + val projects = List(runtime, cli, mdoc, js).reverse projects .map(p => localCrossPublishProject(p, scalaV)) .reduceLeft(_ dependsOn _) @@ -465,11 +465,7 @@ def localCrossPublishProjects(scalaV: String): Def.Initialize[Task[Unit]] = { def localCrossPublishProject(ref: Project, scalaV: String): Def.Initialize[Task[Unit]] = Def.task { val versionValue = (ThisBuild / version).value - val projects = - if (scalaV.startsWith("3")) - List(runtime, mdoc, js) - else - List(runtime, cli, mdoc, js) + val projects = List(runtime, cli, mdoc, js) val setttings = (ThisBuild / version := versionValue) :: projects.map(p => p / scalaVersion := scalaV) diff --git a/cli/src/main/scala/mdoc/internal/cli/Settings.scala b/cli/src/main/scala/mdoc/internal/cli/Settings.scala index c35fb494b..e403f77bb 100644 --- a/cli/src/main/scala/mdoc/internal/cli/Settings.scala +++ b/cli/src/main/scala/mdoc/internal/cli/Settings.scala @@ -31,6 +31,7 @@ import mdoc.Reporter import mdoc.internal.markdown.{GitHubIdGenerator, ReplVariablePrinter} import mdoc.internal.cli.CliEnrichments._ import pprint.TPrint +import pprint.TPrintColors class Section(val name: String) extends StaticAnnotation @@ -300,13 +301,24 @@ object Settings { // extends MetaconfigScalametaImplicits with Decoders with Set def write(set: Settings) = ConfEncoder[Settings].write(set) implicit val absolutePathPrint: TPrint[AbsolutePath] = - TPrint.make[AbsolutePath](_ => "") + new TPrint[AbsolutePath] { + def render(implicit tpc: TPrintColors): fansi.Str = fansi.Str("") + } + implicit val pathMatcherPrint: TPrint[PathMatcher] = - TPrint.make[PathMatcher](_ => "") + new TPrint[PathMatcher] { + def render(implicit tpc: TPrintColors): fansi.Str = fansi.Str("") + } + implicit def optionPrint[T](implicit ev: pprint.TPrint[T]): TPrint[Option[T]] = - TPrint.make { implicit cfg => ev.render } + new TPrint[Option[T]] { + def render(implicit tpc: TPrintColors): fansi.Str = ev.render + } + implicit def iterablePrint[C[x] <: Iterable[x], T](implicit ev: pprint.TPrint[T]): TPrint[C[T]] = - TPrint.make { implicit cfg => s"[${ev.render} ...]" } + new TPrint[C[T]] { + def render(implicit tpc: TPrintColors): fansi.Str = s"[${ev.render} ...]" + } implicit val pathMatcherDecoder: ConfDecoder[PathMatcher] = ConfDecoder.stringConfDecoder.map(glob => FileSystems.getDefault.getPathMatcher("glob:" + glob)) diff --git a/mdoc/src/main/scala/mdoc/internal/markdown/Processor.scala b/mdoc/src/main/scala/mdoc/internal/markdown/Processor.scala index 8a006a23c..ab161ca47 100644 --- a/mdoc/src/main/scala/mdoc/internal/markdown/Processor.scala +++ b/mdoc/src/main/scala/mdoc/internal/markdown/Processor.scala @@ -17,9 +17,9 @@ import scala.meta.dialects.{Scala213, Scala3} import scala.util.control.NonFatal import mdoc.internal.cli.Context import mdoc.internal.document.MdocExceptions +import mdoc.internal.document.Printing import mdoc.internal.markdown.Modifier._ import mdoc.internal.pos.PositionSyntax._ -import pprint.TPrintColors import scala.meta.io.RelativePath import coursierapi.error.SimpleResolutionError import coursierapi.error.CoursierError @@ -198,7 +198,6 @@ class Processor(implicit ctx: Context) { ctx.settings.variablePrinter, markdownCompiler ) - implicit val pprintColor = TPrintColors.BlackWhite mod match { case Modifier.Post(modifier, info) => val variables = for { @@ -209,7 +208,7 @@ class Processor(implicit ctx: Context) { } yield { new mdoc.Variable( binder.name, - binder.tpe.render, + Printing.typeString(binder.tpe), binder.value, binder.pos.toMeta(section), j, diff --git a/mdoc/src/main/scala/mdoc/internal/markdown/Renderer.scala b/mdoc/src/main/scala/mdoc/internal/markdown/Renderer.scala index 3f5957ce5..059addc17 100644 --- a/mdoc/src/main/scala/mdoc/internal/markdown/Renderer.scala +++ b/mdoc/src/main/scala/mdoc/internal/markdown/Renderer.scala @@ -10,6 +10,7 @@ import mdoc.document.CrashResult.Crashed import mdoc.document.RangePosition import mdoc.internal.document.FailSection import mdoc.internal.document.MdocExceptions +import mdoc.internal.document.Printing import mdoc.internal.pos.PositionSyntax._ import mdoc.internal.pos.TokenEditDistance import scala.meta._ @@ -157,7 +158,7 @@ object Renderer { } appendFreshMultiline(sb, compiled) case _ => - val obtained = pprint.PPrinter.BlackWhite.apply(binder).toString() + val obtained = Printing.stringValue(binder.value) throw new IllegalArgumentException( s"Expected FailSection. Obtained $obtained" ) @@ -166,7 +167,7 @@ object Renderer { val pos = binder.pos.toMeta(section) val variable = new mdoc.Variable( binder.name, - binder.tpe.render, + Printing.typeString(binder.tpe), binder.value, pos, i, diff --git a/project/plugins.sbt b/project/plugins.sbt index c8bc6f558..e388387ca 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -8,6 +8,6 @@ libraryDependencies ++= List( "org.jsoup" % "jsoup" % "1.12.1", "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value ) -unmanagedSourceDirectories.in(Compile) += - baseDirectory.in(ThisBuild).value.getParentFile / +Compile / unmanagedSourceDirectories += + (ThisBuild / baseDirectory).value.getParentFile / "mdoc-sbt" / "src" / "main" / "scala" diff --git a/runtime/src/main/scala-2/mdoc/internal/document/Printing.scala b/runtime/src/main/scala-2/mdoc/internal/document/Printing.scala index 7097ccfac..e98500264 100644 --- a/runtime/src/main/scala-2/mdoc/internal/document/Printing.scala +++ b/runtime/src/main/scala-2/mdoc/internal/document/Printing.scala @@ -8,7 +8,7 @@ import Compat.TPrint object Printing { def stringValue[T](value: T) = PPrinter.BlackWhite.apply(value) - def typeString[T](tprint: TPrint[T]) = tprint.render(TPrintColors.BlackWhite) + def typeString[T](tprint: TPrint[T]): String = tprint.render(TPrintColors.BlackWhite).render def print[T](value: T, out: StringBuilder, width: Int, height: Int) = { BlackWhite .tokenize(value, width, height) diff --git a/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala b/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala index d37af6a07..1ce5bf5dd 100644 --- a/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala +++ b/tests/unit/src/test/scala/tests/cli/ScalacOptionsSuite.scala @@ -200,7 +200,7 @@ class ScalacOptionsSuite extends BaseCliSuite { |final case class Test(value: Int) | |val test = Test(123) - |// test: Test = Test(123) + |// test: Test = Test(value = 123) | |test.value |// res0: Int = 123 diff --git a/tests/unit/src/test/scala/tests/markdown/DefaultSuite.scala b/tests/unit/src/test/scala/tests/markdown/DefaultSuite.scala index f2c144153..cf877ad91 100644 --- a/tests/unit/src/test/scala/tests/markdown/DefaultSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/DefaultSuite.scala @@ -141,6 +141,13 @@ class DefaultSuite extends BaseMarkdownSuite { """.stripMargin, compat = Map( Compat.Scala213 -> + """|```scala + |case class User(name: String, age: Int) + |User("John", 42) + |// res0: User = User(name = "John", age = 42) + |``` + |""".stripMargin, + Compat.Scala3 -> """|```scala |case class User(name: String, age: Int) |User("John", 42) diff --git a/tests/unit/src/test/scala/tests/markdown/SemanticsSuite.scala b/tests/unit/src/test/scala/tests/markdown/SemanticsSuite.scala index 261dda59f..b9a701ddd 100644 --- a/tests/unit/src/test/scala/tests/markdown/SemanticsSuite.scala +++ b/tests/unit/src/test/scala/tests/markdown/SemanticsSuite.scala @@ -41,6 +41,16 @@ class SemanticsSuite extends BaseMarkdownSuite { |``` """.stripMargin, compat = Map( + Compat.Scala3 -> + """|```scala + |case class User(name: String) + |object User { + | implicit val ordering: Ordering[User] = Ordering.by(_.name) + |} + |List(User("Susan"), User("John")).sorted + |// res0: List[User] = List(User(name = "John"), User(name = "Susan")) + |``` + |""".stripMargin, Compat.Scala213 -> """|```scala |case class User(name: String)