Skip to content

Commit

Permalink
Update scalafmt-core to 2.5.1 (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenFradet committed May 4, 2020
1 parent b68d9ba commit 4ba2591
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 247 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.5.1
style = defaultWithAlign
maxColumn = 100

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inThisBuild(
)
)

addCommandAlias("ci-test", "scalafmtCheck; scalafmtSbtCheck; docs/tut; compile; test; scripted")
addCommandAlias("ci-test", "scalafmtCheckAll; scalafmtSbtCheck; docs/tut; compile; test; scripted")
addCommandAlias("ci-docs", "project-docs/mdoc; headerCreateAll")
addCommandAlias("ci-microsite", "docs/publishMicrosite")

Expand Down
24 changes: 12 additions & 12 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import sbt.Resolver.sonatypeRepo

resolvers ++= Seq(sonatypeRepo("snapshots"), sonatypeRepo("releases"))

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.3")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.4.0")
addSbtPlugin("com.alejandrohdezma" %% "sbt-github" % "0.6.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-header" % "0.6.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-mdoc" % "0.6.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-mdoc-toc" % "0.2")
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.13")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.1.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.3")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.4.0")
addSbtPlugin("com.alejandrohdezma" %% "sbt-github" % "0.6.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-header" % "0.6.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-mdoc" % "0.6.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-mdoc-toc" % "0.2")
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.13")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.1.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.0")

unmanagedSourceDirectories in Compile ++= Seq(
baseDirectory.in(ThisBuild).value.getParentFile / "src" / "main" / "scala"
Expand Down
40 changes: 17 additions & 23 deletions src/main/scala/microsites/MicrositeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
val pluginName = "microsites.MicrositesPlugin"
val sbtMicrositesProjects = pluginProjects(pluginName)
sbtMicrositesProjects match {
case Some(projects) => {
case Some(projects) =>
List(
"sbt",
s"""clean; project ${projects(0)}; set micrositeBaseUrl := "$newBaseUrl"; makeMicrosite"""
Expand All @@ -276,7 +276,6 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
StandardCopyOption.REPLACE_EXISTING
)
()
}
case None => System.err.println(s"$pluginName not found in version $version")
}
}
Expand Down Expand Up @@ -412,21 +411,18 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
val re = tutNameFilter.value.pattern.toString
_root_.tut.TutPlugin.tutOne(streams.value, r, in, out, cp, opts, pOpts, re).map(_._1)
},
makeTut := {
Def.sequential(tut, micrositeTutExtraMdFiles)
}.value,
makeMdoc := {
Def.sequential(mdoc.toTask(""), micrositeMakeExtraMdFiles)
}.value,
makeTut :=
Def.sequential(tut, micrositeTutExtraMdFiles).value,
makeMdoc :=
Def.sequential(mdoc.toTask(""), micrositeMakeExtraMdFiles).value,
makeDocs := Def.taskDyn {
micrositeCompilingDocsTool.value match {
case WithTut => Def.sequential(makeTut)
case WithMdoc => Def.sequential(makeMdoc)
}
}.value,
makeMicrosite := {
Def.sequential(microsite, makeDocs, makeSite)
}.value,
makeMicrosite :=
Def.sequential(microsite, makeDocs, makeSite).value,
makeVersionsJson := {
"which git".! match {
case 0 => ()
Expand Down Expand Up @@ -481,12 +477,12 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
)
}
},
makeVersionedMicrosite := {
Def.sequential(microsite, makeVersionsJson, makeDocs, makeSite)
}.value,
makeMultiversionMicrosite := {
Def.sequential(createMicrositeVersions, clean, makeVersionedMicrosite, moveMicrositeVersions)
}.value,
makeVersionedMicrosite :=
Def.sequential(microsite, makeVersionsJson, makeDocs, makeSite).value,
makeMultiversionMicrosite :=
Def
.sequential(createMicrositeVersions, clean, makeVersionedMicrosite, moveMicrositeVersions)
.value,
ghpagesPrivateMappings := {
sbt.Path.allSubpaths((target in makeSite).value).toList
},
Expand Down Expand Up @@ -552,12 +548,10 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
)
}
}.value,
publishMicrosite := {
Def.sequential(clean, makeMicrosite, pushMicrosite)
}.value,
publishMultiversionMicrosite := {
Def.sequential(clean, makeMultiversionMicrosite, pushMicrosite)
}.value
publishMicrosite :=
Def.sequential(clean, makeMicrosite, pushMicrosite).value,
publishMultiversionMicrosite :=
Def.sequential(clean, makeMultiversionMicrosite, pushMicrosite).value
)

val pushMicrositeCommand: Command = Command(pushMicrositeCommandKey)(_ => OptNotSpace) {
Expand Down
18 changes: 10 additions & 8 deletions src/main/scala/microsites/github/GitHubOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ class GitHubOps[F[_]: ConcurrentEffect: Timer](
filePath: String,
array: Array[Byte]
): OptionT[F, TreeData] =
if (blobConfig.acceptedExtensions.exists(s => file.getName.toLowerCase.endsWith(s)) &&
array.length < blobConfig.maximumSize) {
if (
blobConfig.acceptedExtensions.exists(s => file.getName.toLowerCase.endsWith(s)) &&
array.length < blobConfig.maximumSize
)
OptionT(createTreeDataBlob(filePath, array).map(Option(_)))
} else {
else
OptionT(createTreeDataSha(filePath, array).map(Option(_)))
}

def processFile(file: File): F[TreeData] =
(for {
Expand Down Expand Up @@ -167,10 +168,11 @@ class GitHubOps[F[_]: ConcurrentEffect: Timer](
)
} yield res

def parentCommitSha: F[String] = commitSha match {
case Some(sha) => Sync[F].pure(sha)
case None => fetchHeadCommit(branch).map(_.`object`.sha)
}
def parentCommitSha: F[String] =
commitSha match {
case Some(sha) => Sync[F].pure(sha)
case None => fetchHeadCommit(branch).map(_.`object`.sha)
}

for {
parentCommit <- parentCommitSha
Expand Down
13 changes: 7 additions & 6 deletions src/main/scala/microsites/ioops/ioops.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ package object ioops {

final class FilteredEitherOps[T](either: Either[Throwable, T]) {

def withFilter(f: T => Boolean): Either[Throwable, T] = either match {
case Right(r) if !f(r) =>
new IllegalStateException("Filter condition has not been satisfied").asLeft[T]
case _ =>
either
}
def withFilter(f: T => Boolean): Either[Throwable, T] =
either match {
case Right(r) if !f(r) =>
new IllegalStateException("Filter condition has not been satisfied").asLeft[T]
case _ =>
either
}
}

final class FileNameOps(filename: String) {
Expand Down
34 changes: 22 additions & 12 deletions src/main/scala/microsites/layouts/Layout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ abstract class Layout(config: MicrositeSettings) {
else None

val twitter: Option[TypedTag[String]] =
if (config.identity.twitter.nonEmpty) {
if (config.identity.twitter.nonEmpty)
Some(meta(name := "twitter:site", content := config.identity.twitter))
} else None
else None

val twitterCreator: Option[TypedTag[String]] =
if (config.identity.twitterCreator.nonEmpty) {
if (config.identity.twitterCreator.nonEmpty)
Some(meta(name := "twitter:creator", content := config.identity.twitterCreator))
} else None
else None

def metas: List[TypedTag[String]] = {
val pageTitle = s"${config.identity.name}{% if page.title %}: {{page.title}}{% endif %}"
Expand Down Expand Up @@ -125,11 +125,10 @@ abstract class Layout(config: MicrositeSettings) {
}

def favicons: List[TypedTag[String]] =
(if (config.visualSettings.favicons.nonEmpty) {
(if (config.visualSettings.favicons.nonEmpty)
config.visualSettings.favicons
} else {
micrositeHelper.faviconDescriptions
}).map { icon =>
else
micrositeHelper.faviconDescriptions).map { icon =>
link(
rel := "icon",
`type` := "image/png",
Expand All @@ -141,7 +140,10 @@ abstract class Layout(config: MicrositeSettings) {
def styles: List[TypedTag[String]] = {

val customCssList =
fr.fetchFilesRecursively(List(config.fileLocations.micrositeCssDirectory), validFile("css")) match {
fr.fetchFilesRecursively(
List(config.fileLocations.micrositeCssDirectory),
validFile("css")
) match {
case Right(cssList) =>
cssList.map(css =>
link(rel := "stylesheet", href := s"{{site.baseurl}}/css/${css.getName}")
Expand All @@ -150,7 +152,10 @@ abstract class Layout(config: MicrositeSettings) {
}

val customScssList =
fr.fetchFilesRecursively(List(config.fileLocations.micrositeCssDirectory), validFile("scss")) match {
fr.fetchFilesRecursively(
List(config.fileLocations.micrositeCssDirectory),
validFile("scss")
) match {
case Right(scssList) =>
scssList.map { scss =>
val fileNameWithOutExt = scss.getName.replaceFirst("[.][^.]+$", "")
Expand Down Expand Up @@ -205,7 +210,10 @@ abstract class Layout(config: MicrositeSettings) {
def scripts: List[TypedTag[String]] = {

val customJsList =
fr.fetchFilesRecursively(List(config.fileLocations.micrositeJsDirectory), validFile("js")) match {
fr.fetchFilesRecursively(
List(config.fileLocations.micrositeJsDirectory),
validFile("js")
) match {
case Right(jsList) =>
jsList.map(js => script(src := s"{{site.url}}{{site.baseurl}}/js/${js.getName}"))
case _ => Nil
Expand Down Expand Up @@ -273,7 +281,9 @@ abstract class Layout(config: MicrositeSettings) {
"""console.info('\x57\x65\x62\x73\x69\x74\x65\x20\x62\x75\x69\x6c\x74\x20\x77\x69\x74\x68\x3a\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x5f\x5f\x20\x20\x20\x20\x5f\x5f\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x5f\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x5f\x20\x5f\x5f\x0a\x20\x20\x20\x5f\x5f\x5f\x5f\x5f\x2f\x20\x2f\x5f\x20\x20\x2f\x20\x2f\x5f\x20\x20\x20\x20\x20\x20\x5f\x5f\x5f\x5f\x20\x5f\x5f\x5f\x20\x20\x28\x5f\x29\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x5f\x20\x20\x5f\x5f\x5f\x5f\x5f\x28\x5f\x29\x20\x2f\x5f\x5f\x5f\x5f\x20\x20\x5f\x5f\x5f\x5f\x5f\x0a\x20\x20\x2f\x20\x5f\x5f\x5f\x2f\x20\x5f\x5f\x20\x5c\x2f\x20\x5f\x5f\x2f\x5f\x5f\x5f\x5f\x5f\x2f\x20\x5f\x5f\x20\x60\x5f\x5f\x20\x5c\x2f\x20\x2f\x20\x5f\x5f\x5f\x2f\x20\x5f\x5f\x5f\x2f\x20\x5f\x5f\x20\x5c\x2f\x20\x5f\x5f\x5f\x2f\x20\x2f\x20\x5f\x5f\x2f\x20\x5f\x20\x5c\x2f\x20\x5f\x5f\x5f\x2f\x0a\x20\x28\x5f\x5f\x20\x20\x29\x20\x2f\x5f\x2f\x20\x2f\x20\x2f\x5f\x2f\x5f\x5f\x5f\x5f\x5f\x2f\x20\x2f\x20\x2f\x20\x2f\x20\x2f\x20\x2f\x20\x2f\x20\x2f\x5f\x5f\x2f\x20\x2f\x20\x20\x2f\x20\x2f\x5f\x2f\x20\x28\x5f\x5f\x20\x20\x29\x20\x2f\x20\x2f\x5f\x2f\x20\x20\x5f\x5f\x28\x5f\x5f\x20\x20\x29\x0a\x2f\x5f\x5f\x5f\x5f\x2f\x5f\x2e\x5f\x5f\x5f\x2f\x5c\x5f\x5f\x2f\x20\x20\x20\x20\x20\x2f\x5f\x2f\x20\x2f\x5f\x2f\x20\x2f\x5f\x2f\x5f\x2f\x5c\x5f\x5f\x5f\x2f\x5f\x2f\x20\x20\x20\x5c\x5f\x5f\x5f\x5f\x2f\x5f\x5f\x5f\x5f\x2f\x5f\x2f\x5c\x5f\x5f\x2f\x5c\x5f\x5f\x5f\x2f\x5f\x5f\x5f\x5f\x2f\x0a\x0a\x68\x74\x74\x70\x73\x3a\x2f\x2f\x34\x37\x64\x65\x67\x2e\x67\x69\x74\x68\x75\x62\x2e\x69\x6f\x2f\x73\x62\x74\x2d\x6d\x69\x63\x72\x6f\x73\x69\x74\x65\x73')"""
)

auxScripts ++ languageScripts ++ List(highlightingScript) ++ customJsList ++ customCDNList ++ (message :: gitSidecar)
auxScripts ++ languageScripts ++ List(
highlightingScript
) ++ customJsList ++ customCDNList ++ (message :: gitSidecar)
}

def versionScript: TypedTag[String] =
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/microsites/util/MicrositeHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class MicrositeHelper(config: MicrositeSettings) {
s"""---
|layout: ${targetFileConfig.layout}
|${targetFileConfig.metaProperties map {
case (key, value) => "%s: %s" format (key, value)
} mkString ("", "\n", "")}
case (key, value) => "%s: %s" format (key, value)
} mkString ("", "\n", "")}
|---
|${Source.fromFile(sourceFile.getAbsolutePath).mkString}
|""".stripMargin
Expand All @@ -151,9 +151,9 @@ class MicrositeHelper(config: MicrositeSettings) {
yaml.yamlInline.parseYaml.asYamlObject.fields
else Map.empty[YamlValue, YamlValue]
val fileYaml = yaml.yamlPath.fold(Map.empty[YamlValue, YamlValue])(f =>
if (f.exists()) {
if (f.exists())
Source.fromFile(f.getAbsolutePath).mkString.parseYaml.asYamlObject.fields
} else Map.empty[YamlValue, YamlValue]
else Map.empty[YamlValue, YamlValue]
)

writeContentToFile(
Expand Down
42 changes: 22 additions & 20 deletions src/main/scala/microsites/util/YamlFormats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@ import net.jcazevedo.moultingyaml._
object YamlFormats extends DefaultYamlProtocol {

implicit object AnyYamlFormat extends YamlFormat[Any] {
def write(x: Any): YamlValue = x match {
case n: Int => YamlNumber(n)
case n: Long => YamlNumber(n)
case n: Double => YamlNumber(n)
case s: String => YamlString(s)
case b: Boolean => YamlBoolean(b)
case x: Seq[_] => seqFormat[Any].write(x)
case m: Map[String, _] => mapFormat[String, Any].write(m)
case t =>
serializationError("Serialization Error - Non expected type " + t.getClass.getName)
}
def write(x: Any): YamlValue =
x match {
case n: Int => YamlNumber(n)
case n: Long => YamlNumber(n)
case n: Double => YamlNumber(n)
case s: String => YamlString(s)
case b: Boolean => YamlBoolean(b)
case x: Seq[_] => seqFormat[Any].write(x)
case m: Map[String, _] => mapFormat[String, Any].write(m)
case t =>
serializationError("Serialization Error - Non expected type " + t.getClass.getName)
}

def read(value: YamlValue): Any = value match {
case YamlNumber(n) => n.intValue()
case YamlString(s) => s
case YamlBoolean(b) => b
case _: YamlArray => listFormat[Any].read(value)
case _: YamlObject => mapFormat[String, Any].read(value)
case x =>
deserializationError("Deserialization Error - it failed the deserialization of " + x)
}
def read(value: YamlValue): Any =
value match {
case YamlNumber(n) => n.intValue()
case YamlString(s) => s
case YamlBoolean(b) => b
case _: YamlArray => listFormat[Any].read(value)
case _: YamlObject => mapFormat[String, Any].read(value)
case x =>
deserializationError("Deserialization Error - it failed the deserialization of " + x)
}
}
}
7 changes: 4 additions & 3 deletions src/test/scala/microsites/LayoutTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import org.scalatest.matchers.should.Matchers

class LayoutTest extends AnyFunSuite with Checkers with Matchers with Arbitraries {

def buildParentLayout(implicit settings: MicrositeSettings) = new Layout(settings) {
override def render: TypedTag[String] = html
}
def buildParentLayout(implicit settings: MicrositeSettings) =
new Layout(settings) {
override def render: TypedTag[String] = html
}

test("meta TypeTag list shouldn't be empty") {

Expand Down
Loading

0 comments on commit 4ba2591

Please sign in to comment.