Skip to content

Commit 63b99c6

Browse files
committed
Add formatter
1 parent 8bb3e9c commit 63b99c6

File tree

7 files changed

+69
-39
lines changed

7 files changed

+69
-39
lines changed

.scalafmt.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
maxColumn = 120
2+
docstrings = JavaDoc
3+
assumeStandardLibraryStripMargin = true
4+
rewrite.rules = [RedundantBraces, RedundantParens, SortImports, SortModifiers]
5+
unindentTopLevelOperators = true
6+
align.tokens = [
7+
{code = "%", owner = "Term.ApplyInfix"},
8+
{code = "%%", owner = "Term.ApplyInfix"},
9+
{code = ":=", owner = "Term.ApplyInfix"},
10+
"="
11+
]

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66
include:
77
- stage: test
88
script: sbt test
9+
- script: sbt scalafmtCheck scalafmtSbtCheck
910
- stage: publish
1011
script: sbt ^publish
1112

build.sbt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
scalaVersion := "2.12.7"
22

3-
sbtPlugin := true
3+
sbtPlugin := true
44
crossSbtVersions := List("1.0.0")
5-
organization := "com.lightbend.paradox"
6-
name := "sbt-paradox-apidoc"
5+
organization := "com.lightbend.paradox"
6+
name := "sbt-paradox-apidoc"
77

88
addSbtPlugin(Library.sbtParadox)
99
libraryDependencies ++= Seq(
1010
Library.classgraph,
11-
Library.jtidy % Test,
11+
Library.jtidy % Test,
1212
Library.scalatest % Test
1313
)
1414

1515
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0"))
1616
homepage := Some(url("https://github.com/lightbend/sbt-paradox-apidoc"))
17-
scmInfo := Some(ScmInfo(url("https://github.com/lightbend/sbt-paradox-apidoc"), "git@github.com:lightbend/sbt-paradox-apidoc.git"))
17+
scmInfo := Some(
18+
ScmInfo(url("https://github.com/lightbend/sbt-paradox-apidoc"), "git@github.com:lightbend/sbt-paradox-apidoc.git"))
1819
developers += Developer("contributors",
19-
"Contributors",
20-
"https://gitter.im/lightbend/paradox",
21-
url("https://github.com/lightbend/sbt-paradox-apidoc/graphs/contributors"))
20+
"Contributors",
21+
"https://gitter.im/lightbend/paradox",
22+
url("https://github.com/lightbend/sbt-paradox-apidoc/graphs/contributors"))
2223
organizationName := "Lightbend Inc."
23-
startYear := Some(2018)
24+
startYear := Some(2018)
2425

2526
bintrayOrganization := Some("sbt")
26-
bintrayRepository := "sbt-plugin-releases"
27+
bintrayRepository := "sbt-plugin-releases"
2728

2829
enablePlugins(AutomateHeaderPlugin)
30+
scalafmtOnCompile := true

project/Dependencies.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import sbt._
22

33
object Version {
4-
val classgraph = "4.4.2"
5-
val jtidy = "r938"
6-
val sbtParadox = "0.4.3"
7-
val scalatest = "3.0.5"
4+
val classgraph = "4.4.2"
5+
val jtidy = "r938"
6+
val sbtParadox = "0.4.3"
7+
val scalatest = "3.0.5"
88
}
99

1010
object Library {
11-
val classgraph = "io.github.classgraph" % "classgraph" % Version.classgraph
12-
val jtidy = "net.sf.jtidy" % "jtidy" % Version.jtidy
13-
val sbtParadox = "com.lightbend.paradox" % "sbt-paradox" % Version.sbtParadox
14-
val scalatest = "org.scalatest" %% "scalatest" % Version.scalatest
11+
val classgraph = "io.github.classgraph" % "classgraph" % Version.classgraph
12+
val jtidy = "net.sf.jtidy" % "jtidy" % Version.jtidy
13+
val sbtParadox = "com.lightbend.paradox" % "sbt-paradox" % Version.sbtParadox
14+
val scalatest = "org.scalatest" %% "scalatest" % Version.scalatest
1515
}

project/plugins.sbt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.1.0")
2-
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
3-
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0")
1+
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.1.0")
2+
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4")
3+
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0")
4+
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")

src/main/scala/com/lightbend/paradox/apidoc/ApidocDirective.scala

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import org.pegdown.Printer
2121
import org.pegdown.ast.{DirectiveNode, TextNode, Visitor}
2222

2323
class ApidocDirective(allClasses: IndexedSeq[String]) extends InlineDirective("apidoc") {
24-
def render(node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
24+
def render(node: DirectiveNode, visitor: Visitor, printer: Printer): Unit =
2525
if (node.label.split('[')(0).contains('.')) {
2626
val fqcn = node.label
2727
if (allClasses.contains(fqcn)) {
@@ -31,11 +31,9 @@ class ApidocDirective(allClasses: IndexedSeq[String]) extends InlineDirective("a
3131
} else {
3232
throw new java.lang.IllegalStateException(s"fqcn not found by @apidoc[$fqcn]")
3333
}
34-
}
35-
else {
34+
} else {
3635
renderByClassName(node.label, node, visitor, printer)
3736
}
38-
}
3937

4038
private def baseClassName(label: String) = {
4139
val labelWithoutGenerics = label.split("\\[")(0)
@@ -52,16 +50,27 @@ class ApidocDirective(allClasses: IndexedSeq[String]) extends InlineDirective("a
5250

5351
def syntheticNode(group: String, label: String, fqcn: String, node: DirectiveNode): DirectiveNode = {
5452
val syntheticSource = new DirectiveNode.Source.Direct(fqcn)
55-
val attributes = new org.pegdown.ast.DirectiveAttributes.AttributeMap()
56-
new DirectiveNode(DirectiveNode.Format.Inline, group, null, null, attributes, null,
57-
new DirectiveNode(DirectiveNode.Format.Inline, group + "doc", label, syntheticSource, node.attributes, fqcn,
58-
new TextNode(label)
59-
))
53+
val attributes = new org.pegdown.ast.DirectiveAttributes.AttributeMap()
54+
new DirectiveNode(
55+
DirectiveNode.Format.Inline,
56+
group,
57+
null,
58+
null,
59+
attributes,
60+
null,
61+
new DirectiveNode(DirectiveNode.Format.Inline,
62+
group + "doc",
63+
label,
64+
syntheticSource,
65+
node.attributes,
66+
fqcn,
67+
new TextNode(label))
68+
)
6069
}
6170

6271
def renderByClassName(label: String, node: DirectiveNode, visitor: Visitor, printer: Printer): Unit = {
63-
val query = node.label.replaceAll("\\\\_", "_")
64-
val className = baseClassName(query)
72+
val query = node.label.replaceAll("\\\\_", "_")
73+
val className = baseClassName(query)
6574
val classSuffix = if (query.endsWith("$")) "$" else ""
6675

6776
val matches = allClasses.filter(_.endsWith('.' + className))

src/main/scala/com/lightbend/paradox/apidoc/ApidocPlugin.scala

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,26 @@ object ApidocPlugin extends AutoPlugin {
4040
def apidocParadoxGlobalSettings: Seq[Setting[_]] = Seq(
4141
apidocRootPackage := "scala",
4242
paradoxDirectives ++= Def.taskDyn {
43-
val classpath = (fullClasspath in Compile).value.files.map(_.toURI.toURL).toArray
43+
val classpath = (fullClasspath in Compile).value.files.map(_.toURI.toURL).toArray
4444
val classLoader = new java.net.URLClassLoader(classpath, this.getClass.getClassLoader)
4545
val scanner = new ClassGraph()
4646
.whitelistPackages(apidocRootPackage.value)
4747
.addClassLoader(classLoader)
4848
.scan()
4949
val allClasses = scanner.getAllClasses.getNames.asScala.toVector
50-
Def.task { Seq(
51-
{ _: Writer.Context new ApidocDirective(allClasses) }
52-
)}
50+
Def.task {
51+
Seq(
52+
{ _: Writer.Context
53+
new ApidocDirective(allClasses)
54+
}
55+
)
56+
}
5357
}.value
5458
)
5559

56-
def apidocSettings(config: Configuration): Seq[Setting[_]] = apidocParadoxGlobalSettings ++ inConfig(config)(Seq(
57-
// scoped settings here
58-
))
60+
def apidocSettings(config: Configuration): Seq[Setting[_]] =
61+
apidocParadoxGlobalSettings ++ inConfig(config)(
62+
Seq(
63+
// scoped settings here
64+
))
5965
}

0 commit comments

Comments
 (0)