Skip to content

Commit

Permalink
force usage of shaded TPrint
Browse files Browse the repository at this point in the history
Injecting instances of pprint.TPrint to customize the docs no longer
has effect as of ffcd8b9, which was a silent breaking change. This
commit exposes the breaking change so that rules built against the
latest scalafix-core either drop usage of TPrint or switch to the
shaded version which is used internally by metaconfig.
  • Loading branch information
bjaglin committed Feb 14, 2022
1 parent 9533c97 commit e65c659
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ lazy val core = project
// metaconfig 0.10.0 shaded pprint but rules built with an old
// scalafix-core must have the original package in the classpath to link
// https://github.com/scalameta/metaconfig/pull/154/files#r794005161
pprint
pprint % Runtime
)
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package scalafix.internal.rule

import java.util.regex.Pattern

import pprint.TPrint
import scalafix.config.CustomMessage

class TPrintImplicits {
implicit val tprintPattern: TPrint[List[CustomMessage[Pattern]]] =
TPrint.literal("List[Regex]")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package scalafix.internal.rule

import java.util.regex.Pattern

import metaconfig.pprint._
import scalafix.config.CustomMessage

class TPrintImplicits {
implicit val tprintPattern: TPrint[List[CustomMessage[Pattern]]] =
new TPrint[List[CustomMessage[Pattern]]] {
def render(implicit tpc: TPrintColors): fansi.Str = fansi.Str("List[Regex]")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import metaconfig.annotation.ExampleValue
import metaconfig.annotation.Hidden
import metaconfig.generic
import metaconfig.generic.Surface
import pprint.TPrint
import scalafix.config.CustomMessage
import scalafix.config.Regex

Expand Down Expand Up @@ -108,8 +107,6 @@ case class DisableSyntaxConfig(
}

object DisableSyntaxConfig {
implicit val tprintPattern: TPrint[List[CustomMessage[Pattern]]] =
TPrint.literal("List[Regex]")
val default: DisableSyntaxConfig = DisableSyntaxConfig()
implicit val surface: Surface[DisableSyntaxConfig] =
generic.deriveSurface[DisableSyntaxConfig]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ final class TestkitPath(
val testPath: RelativePath,
val semanticdbPath: RelativePath
) {
override def toString: String = {
val map = Map(
"input" -> input,
"testPath" -> testPath,
"semanticdbPath" -> semanticdbPath
)
pprint.PPrinter.BlackWhite.tokenize(map).mkString
}
def testName: String = testPath.toURI(isDirectory = false).toString
def toInput: Input =
Input.VirtualFile(testName, FileIO.slurp(input, StandardCharsets.UTF_8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@ final class TestkitProperties(
throw new NoSuchElementException(path.toString())
}
}
override def toString: String = {
val map = Map(
"inputSourceDirectories" -> inputSourceDirectories,
"outputSourceDirectories" -> outputSourceDirectories,
"inputClasspath" -> inputClasspath.syntax,
"sourceroot" -> sourceroot,
"scalaVersion" -> scalaVersion,
"scalacOptions" -> scalacOptions
)
pprint.PPrinter.BlackWhite.tokenize(map).mkString
}
}

object TestkitProperties {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class PrettyTypeFuzzSuite extends BasePrettyTypeSuite {
checkPath(file)
} catch {
case scala.meta.internal.classpath.MissingSymbolException(e) =>
pprint.log(file)
println(file)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MavenFuzzSuite extends AnyFunSuite with DiffAssertions {
finally stream.close()
result += out
} else {
pprint.log(errors)
println(errors)
}
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ class MavenFuzzSuite extends AnyFunSuite with DiffAssertions {
exec("git", "init")
exec("git", "add", ".")
exec("git", "commit", "-m", "first-commit")
pprint.log(paths.length)
println(paths.length)
val args = scalafix
.newArguments()
.withSourceroot(tmp)
Expand All @@ -163,19 +163,19 @@ class MavenFuzzSuite extends AnyFunSuite with DiffAssertions {
.withClasspath(classfiles.asJava)
.withMode(ScalafixMainMode.CHECK)
val exit = args.run()
pprint.log(exit)
println(exit)
// exec("git", "diff")
FileIO.listAllFilesRecursively(AbsolutePath(tmp)).foreach { path =>
if (path.toNIO.getFileName.toString.endsWith(".scala")) {
val text = FileIO.slurp(path, StandardCharsets.UTF_8)
val errors = compileErrors(g, text, path.toString())
if (errors.nonEmpty) {
pprint.log(path)
pprint.log(errors)
println(path)
println(errors)
}
}
}
pprint.log(tmp)
println(tmp)
}
}
check("ExplicitResultTypes")
Expand Down

0 comments on commit e65c659

Please sign in to comment.