From ff188f39b553b98df29e105e1ae8a632e613cee5 Mon Sep 17 00:00:00 2001 From: Scala Steward <43047562+scala-steward@users.noreply.github.com> Date: Fri, 26 Jun 2020 09:22:48 +0200 Subject: [PATCH] scalafmt-core 2.6.1 (was 2.4.2) (#158) Co-authored-by: Arnout Engelen --- .scalafmt.conf | 2 +- project/Dependencies.scala | 8 ++-- .../paradox/apidoc/ApidocDirective.scala | 24 +++++----- .../paradox/apidoc/ApidocPlugin.scala | 47 ++++++++++--------- .../paradox/apidoc/ApidocDirectiveSpec.scala | 19 ++++---- 5 files changed, 49 insertions(+), 51 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 33bf044..7bd8495 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 2.4.2 +version = 2.6.1 maxColumn = 120 docstrings = JavaDoc diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 36af776..052bf63 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -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" } diff --git a/src/main/scala/com/lightbend/paradox/apidoc/ApidocDirective.scala b/src/main/scala/com/lightbend/paradox/apidoc/ApidocDirective.scala index 124c416..9a45397 100644 --- a/src/main/scala/com/lightbend/paradox/apidoc/ApidocDirective.scala +++ b/src/main/scala/com/lightbend/paradox/apidoc/ApidocDirective.scala @@ -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 = @@ -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 @@ -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)) @@ -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") @@ -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")) => @@ -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( diff --git a/src/main/scala/com/lightbend/paradox/apidoc/ApidocPlugin.scala b/src/main/scala/com/lightbend/paradox/apidoc/ApidocPlugin.scala index ecb8393..073a565 100644 --- a/src/main/scala/com/lightbend/paradox/apidoc/ApidocPlugin.scala +++ b/src/main/scala/com/lightbend/paradox/apidoc/ApidocPlugin.scala @@ -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 + ) } diff --git a/src/test/scala/com/lightbend/paradox/apidoc/ApidocDirectiveSpec.scala b/src/test/scala/com/lightbend/paradox/apidoc/ApidocDirectiveSpec.scala index ec4c3d5..3bb1fb9 100644 --- a/src/test/scala/com/lightbend/paradox/apidoc/ApidocDirectiveSpec.scala +++ b/src/test/scala/com/lightbend/paradox/apidoc/ApidocDirectiveSpec.scala @@ -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) => @@ -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( """

The |TheClass<File>.method<String> @@ -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") - } } }