Skip to content

Commit

Permalink
scalafmt-core 2.6.1 (was 2.4.2) (#158)
Browse files Browse the repository at this point in the history
Co-authored-by: Arnout Engelen <[email protected]>
  • Loading branch information
scala-steward and raboof authored Jun 26, 2020
1 parent 339d6fb commit ff188f3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 2.4.2
version = 2.6.1

maxColumn = 120
docstrings = JavaDoc
Expand Down
8 changes: 4 additions & 4 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sbt._

object Library {
val classgraph = "io.github.classgraph" % "classgraph" % "4.8.87"
val sbtParadox = "com.lightbend.paradox" % "sbt-paradox" % "0.8.0"
val scalatest = "org.scalatest" %% "scalatest" % "3.2.0"
val paradoxTestkit = "com.lightbend.paradox" %% "testkit" % "0.8.0"
val classgraph = "io.github.classgraph" % "classgraph" % "4.8.87"
val sbtParadox = "com.lightbend.paradox" % "sbt-paradox" % "0.8.0"
val scalatest = "org.scalatest" %% "scalatest" % "3.2.0"
val paradoxTestkit = "com.lightbend.paradox" %% "testkit" % "0.8.0"
}
24 changes: 11 additions & 13 deletions src/main/scala/com/lightbend/paradox/apidoc/ApidocDirective.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ class ApidocDirective(scanner: ScanResult, allClassesAndObjects: IndexedSeq[Stri
}

private def errorForStaticForwardersOnly(query: Query, node: DirectiveNode, classname: String) =
if (!query.linkToObject && containsOnlyStaticForwarders(classname) &&
allClassesAndObjects.contains(classname + "$")) {
if (
!query.linkToObject && containsOnlyStaticForwarders(classname) &&
allClassesAndObjects.contains(classname + "$")
)
ctx.error(
s"Class `$classname` matches @apidoc[$query], but is empty, did you intend to link to the object?",
node
)
}

private case class Query(label: Option[String], pattern: String, generics: String, linkToObject: Boolean) {
def scalaLabel(matched: String): String =
Expand Down Expand Up @@ -112,9 +113,9 @@ class ApidocDirective(scanner: ScanResult, allClassesAndObjects: IndexedSeq[Stri
}
if (query.pattern.contains('.')) {
val classNameWithDollarForInnerClasses = query.pattern.replaceAll("(\\b[A-Z].+)\\.", "$1\\$")
if (allClasses.contains(classNameWithDollarForInnerClasses)) {
if (allClasses.contains(classNameWithDollarForInnerClasses))
renderMatches(query, Seq(query.pattern), node, visitor, printer)
} else {
else
allClasses.filter(_.endsWith(classNameWithDollarForInnerClasses)) match {
case Seq() =>
// No matches? then try globbing
Expand All @@ -128,7 +129,6 @@ class ApidocDirective(scanner: ScanResult, allClassesAndObjects: IndexedSeq[Stri
case results =>
renderMatches(query, results, node, visitor, printer)
}
}
} else { // only a classname
val className = '.' + query.pattern
val classMatches = allClasses.filter(_.endsWith(className))
Expand Down Expand Up @@ -172,9 +172,8 @@ class ApidocDirective(scanner: ScanResult, allClassesAndObjects: IndexedSeq[Stri
): DirectiveNode = {
val attributes = new org.pegdown.ast.DirectiveAttributes.AttributeMap()
val theUrl = fqcn + anchor
try {
ParadoxUrl(theUrl)
} catch {
try ParadoxUrl(theUrl)
catch {
case ParadoxUrl.Error(reason) =>
val suggestedUrl = theUrl
.replace("<", "%3C")
Expand Down Expand Up @@ -231,9 +230,9 @@ class ApidocDirective(scanner: ScanResult, allClassesAndObjects: IndexedSeq[Stri
errorForStaticForwardersOnly(query, node, query.scalaFqcn(pkg))
scaladocNode("scala", query.scalaLabel(pkg), query.scalaFqcn(pkg) + scalaClassSuffix, sAnchor, node)
.accept(visitor)
if (hasJavadocUrl(pkg)) {
if (hasJavadocUrl(pkg))
javadocNode(query.javaLabel(pkg), query.javaFqcn(pkg), jAnchor, node).accept(visitor)
} else
else
scaladocNode("java", query.javaLabel(pkg), query.scalaFqcn(pkg) + scalaClassSuffix, jAnchor, node)
.accept(visitor)
case 2 if matches.forall(_.contains("adsl")) =>
Expand All @@ -243,13 +242,12 @@ class ApidocDirective(scanner: ScanResult, allClassesAndObjects: IndexedSeq[Stri
scaladocNode("scala", query.scalaLabel(pkg), query.scalaFqcn(pkg) + scalaClassSuffix, sAnchor, node)
.accept(visitor)
}
if (!pkg.contains("scaladsl")) {
if (!pkg.contains("scaladsl"))
if (hasJavadocUrl(pkg))
javadocNode(query.javaLabel(pkg), query.javaFqcn(pkg), jAnchor, node).accept(visitor)
else
scaladocNode("java", query.javaLabel(pkg), query.scalaFqcn(pkg) + scalaClassSuffix, jAnchor, node)
.accept(visitor)
}
}
case n =>
ctx.error(
Expand Down
47 changes: 24 additions & 23 deletions src/main/scala/com/lightbend/paradox/apidoc/ApidocPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,29 @@ object ApidocPlugin extends AutoPlugin {

override def projectSettings: Seq[Setting[_]] = apidocParadoxZeroSettings

def apidocParadoxZeroSettings: Seq[Setting[_]] = Seq(
apidocRootPackage := "scala",
apidocClasses := Def.taskDyn {
val classpathProjects = apidocProjects.?.value
.map(inProjects)
.getOrElse {
inAggregates(LocalRootProject, includeRoot = true)
def apidocParadoxZeroSettings: Seq[Setting[_]] =
Seq(
apidocRootPackage := "scala",
apidocClasses := Def.taskDyn {
val classpathProjects = apidocProjects.?.value
.map(inProjects)
.getOrElse {
inAggregates(LocalRootProject, includeRoot = true)
}
val filter = ScopeFilter(classpathProjects, inConfigurations(Compile))
fullClasspath.all(filter).map(_.flatMap(_.files).map(_.toURI.toURL))
}.value,
paradoxDirectives ++= Def.taskDyn {
val classLoader = new java.net.URLClassLoader(apidocClasses.value.toArray, this.getClass.getClassLoader)
val scanner = new ClassGraph()
.whitelistPackages(apidocRootPackage.value)
.addClassLoader(classLoader)
.enableMethodInfo()
.scan()
val allClasses = scanner.getAllClasses.getNames.asScala.toVector
Def.task {
Seq((ctx: Writer.Context) => new ApidocDirective(scanner, allClasses, ctx))
}
val filter = ScopeFilter(classpathProjects, inConfigurations(Compile))
fullClasspath.all(filter).map(_.flatMap(_.files).map(_.toURI.toURL))
}.value,
paradoxDirectives ++= Def.taskDyn {
val classLoader = new java.net.URLClassLoader(apidocClasses.value.toArray, this.getClass.getClassLoader)
val scanner = new ClassGraph()
.whitelistPackages(apidocRootPackage.value)
.addClassLoader(classLoader)
.enableMethodInfo()
.scan()
val allClasses = scanner.getAllClasses.getNames.asScala.toVector
Def.task {
Seq((ctx: Writer.Context) => new ApidocDirective(scanner, allClasses, ctx))
}
}.value
)
}.value
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ApidocDirectiveSpec extends MarkdownTestkit with Matchers with AnyFlatSpec
)

override val markdownWriter = new Writer(
linkRenderer = Writer.defaultLinks,
linkRenderer = Writer.defaultLinks,
verbatimSerializers = Writer.defaultVerbatims,
serializerPlugins = Writer.defaultPlugins(
Writer.defaultDirectives ++ Seq((ctx: Writer.Context) =>
Expand Down Expand Up @@ -311,7 +311,9 @@ class ApidocDirectiveSpec extends MarkdownTestkit with Matchers with AnyFlatSpec
}

it should "use anchors" in {
markdown("""The @apidoc[TheClass[File].method[String]](Flow) { scala="#method():Unit" java="#method()" } thingie""") shouldEqual
markdown(
"""The @apidoc[TheClass[File].method[String]](Flow) { scala="#method():Unit" java="#method()" } thingie"""
) shouldEqual
html(
"""<p>The <span class="group-java">
|<a href="https://doc.akka.io/japi/akka/2.5/?akka/stream/javadsl/Flow.html#method()" title="akka.stream.javadsl.Flow"><code>TheClass&lt;File&gt;.method&lt;String&gt;</code></a></span><span class="group-scala">
Expand All @@ -333,16 +335,13 @@ class ApidocDirectiveSpec extends MarkdownTestkit with Matchers with AnyFlatSpec
}

it should "catch exception on malformed URIs and make suggestions" in {
try {

markdown(
"""The @apidoc[label](Flow) { scala="#method[ T <: Q[T] ](Flow => Unit):Unit" java="#method()" } thingie"""
)
} catch {
case t @ ParadoxException(error) => {
try markdown(
"""The @apidoc[label](Flow) { scala="#method[ T <: Q[T] ](Flow => Unit):Unit" java="#method()" } thingie"""
)
catch {
case t @ ParadoxException(error) =>
error.msg should include("template resulted in an invalid URL")
error.msg should include("method%5B T %3C: Q%5BT] ](Flow =%3E Unit):Unit")
}
}
}

Expand Down

0 comments on commit ff188f3

Please sign in to comment.