scalafmt
parent
8f8af7d55a
commit
540e632404
|
@ -0,0 +1,6 @@
|
|||
version = "2.3.2"
|
||||
align = more
|
||||
maxColumn = 110
|
||||
spaces.inImportCurlyBraces = true
|
||||
rewrite.rules = [SortImports, RedundantParens, SortModifiers]
|
||||
rewrite.redundantBraces.stringInterpolation = true
|
12
build.sbt
12
build.sbt
|
@ -1,5 +1,4 @@
|
|||
import com.typesafe.sbt.packager.Keys.scriptClasspath
|
||||
import com.typesafe.sbt.SbtScalariform.autoImport.scalariformFormat
|
||||
|
||||
import BuildSettings._
|
||||
import Dependencies._
|
||||
|
@ -25,7 +24,10 @@ PlayKeys.playDefaultPort := 9663
|
|||
PlayKeys.externalizeResources := false
|
||||
// shorter prod classpath
|
||||
scriptClasspath := Seq("*")
|
||||
// offline := true
|
||||
// don't make an assets jar
|
||||
resourceDirectory in Assets := (sourceDirectory in Compile).value / "assets"
|
||||
|
||||
// format: off
|
||||
libraryDependencies ++= Seq(
|
||||
macwire.macros, macwire.util, play.json, jodaForms, ws,
|
||||
scalaz, chess, compression, scalalib, hasher,
|
||||
|
@ -35,12 +37,6 @@ libraryDependencies ++= Seq(
|
|||
scrimage, scaffeine, lettuce, epoll
|
||||
) ++ silencer.bundle
|
||||
|
||||
resourceDirectory in Assets := (sourceDirectory in Compile).value / "assets"
|
||||
|
||||
scalariformPreferences := scalariformPrefs(scalariformPreferences.value)
|
||||
excludeFilter in scalariformFormat := "*Routes*"
|
||||
routesGenerator := LilaRoutesGenerator
|
||||
|
||||
lazy val modules = Seq(
|
||||
common, db, rating, user, security, hub, socket,
|
||||
message, notifyModule, i18n, game, bookmark, search,
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import com.typesafe.sbt.SbtScalariform.autoImport.scalariformPreferences
|
||||
import play.sbt.PlayImport._
|
||||
import sbt._, Keys._
|
||||
import scalariform.formatter.preferences._
|
||||
|
||||
object BuildSettings {
|
||||
|
||||
|
@ -19,17 +17,20 @@ object BuildSettings {
|
|||
// disable publishing the main API jar
|
||||
publishArtifact in (Compile, packageDoc) := false,
|
||||
// disable publishing the main sources jar
|
||||
publishArtifact in (Compile, packageSrc) := false,
|
||||
scalariformPreferences := scalariformPrefs(scalariformPreferences.value)
|
||||
publishArtifact in (Compile, packageSrc) := false
|
||||
)
|
||||
|
||||
def scalariformPrefs(prefs: IFormattingPreferences) = prefs
|
||||
.setPreference(DanglingCloseParenthesis, Force)
|
||||
.setPreference(DoubleIndentConstructorArguments, true)
|
||||
|
||||
def defaultLibs: Seq[ModuleID] = Seq(
|
||||
play.api, scalaz, chess, scalalib, jodaTime, ws,
|
||||
macwire.macros, macwire.util, autoconfig, specs2
|
||||
play.api,
|
||||
scalaz,
|
||||
chess,
|
||||
scalalib,
|
||||
jodaTime,
|
||||
ws,
|
||||
macwire.macros,
|
||||
macwire.util,
|
||||
autoconfig,
|
||||
specs2
|
||||
)
|
||||
|
||||
def module(
|
||||
|
@ -40,8 +41,7 @@ object BuildSettings {
|
|||
Project(
|
||||
name,
|
||||
file("modules/" + name)
|
||||
)
|
||||
.dependsOn(deps: _*)
|
||||
).dependsOn(deps: _*)
|
||||
.settings(
|
||||
libraryDependencies ++= defaultLibs ++ libs ++ silencer.bundle,
|
||||
buildSettings,
|
||||
|
@ -59,8 +59,10 @@ object BuildSettings {
|
|||
"-Ywarn-macros:after",
|
||||
"-Ywarn-unused:_",
|
||||
// "-Xfatal-warnings",
|
||||
"-Xmaxerrs", "12",
|
||||
"-Xmaxwarns", "12"
|
||||
"-Xmaxerrs",
|
||||
"12",
|
||||
"-Xmaxwarns",
|
||||
"12"
|
||||
)
|
||||
|
||||
val srcMain = Seq(
|
||||
|
|
|
@ -17,9 +17,11 @@ object MessageCompiler {
|
|||
|
||||
private def doFile(db: String, sourceFile: File, destDir: File, compileTo: File): Seq[File] = {
|
||||
destDir.mkdirs()
|
||||
val registry = ("en-GB" -> sourceFile) :: destDir.list.toList.map { f =>
|
||||
val registry = ("en-GB" -> sourceFile) :: destDir.list.toList
|
||||
.map { f =>
|
||||
f.takeWhile('.' !=) -> (destDir / f)
|
||||
}.sortBy(_._1)
|
||||
}
|
||||
.sortBy(_._1)
|
||||
compileTo.mkdirs()
|
||||
var translatedLocales = Set.empty[String]
|
||||
val res = for {
|
||||
|
@ -33,8 +35,7 @@ object MessageCompiler {
|
|||
printToFile(compileToFile)(render(db, locale, file))
|
||||
}
|
||||
Some(compileToFile)
|
||||
}
|
||||
else None
|
||||
} else None
|
||||
}
|
||||
} yield compilable
|
||||
writeRegistry(db, compileTo, translatedLocales) :: res
|
||||
|
@ -77,10 +78,10 @@ private[i18n] object Registry {
|
|||
}
|
||||
|
||||
private def render(db: String, locale: String, file: File): String = {
|
||||
val xml = try {
|
||||
val xml =
|
||||
try {
|
||||
XML.loadFile(file)
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
case e: Exception => println(file); throw e;
|
||||
}
|
||||
def quote(msg: String) = s"""""\"$msg""\""""
|
||||
|
@ -93,9 +94,12 @@ private[i18n] object Registry {
|
|||
}
|
||||
s"""m.put(${toKey(e)},$translation)"""
|
||||
case e if e.label == "plurals" =>
|
||||
val items: Map[String, String] = e.child.filter(_.label == "item").map { i =>
|
||||
val items: Map[String, String] = e.child
|
||||
.filter(_.label == "item")
|
||||
.map { i =>
|
||||
ucfirst(i.\("@quantity").toString) -> s"""\"\"\"${escape(i.text)}\"\"\""""
|
||||
}.toMap
|
||||
}
|
||||
.toMap
|
||||
s"""m.put(${toKey(e)},new Plurals(${pluralMap(items)}))"""
|
||||
}
|
||||
s"""package lila.i18n
|
||||
|
@ -119,7 +123,6 @@ ${content mkString "\n"}
|
|||
if (items.size > 4) s"""Map(${items.map { case (k, v) => s"$k->$v" } mkString ","})"""
|
||||
else s"""new Map.Map${items.size}(${items.map { case (k, v) => s"$k,$v" } mkString ","})"""
|
||||
|
||||
|
||||
private val badChars = """[<>&"'\r\n]""".r.pattern
|
||||
private def escapeHtmlOption(s: String): Option[String] =
|
||||
if (badChars.matcher(s).find) Some {
|
||||
|
@ -143,6 +146,10 @@ ${content mkString "\n"}
|
|||
|
||||
private def printToFile(f: File)(content: String): Unit = {
|
||||
val p = new java.io.PrintWriter(f, "UTF-8")
|
||||
try { content.foreach(p.print) } finally { p.close() }
|
||||
try {
|
||||
content.foreach(p.print)
|
||||
} finally {
|
||||
p.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,11 @@ object LilaRoutesGenerator extends RoutesGenerator {
|
|||
|
||||
import InjectedRoutesGenerator.Dependency
|
||||
|
||||
def generate(task: RoutesCompilerTask, namespace: Option[String], rules: List[Rule]): Seq[(String, String)] = {
|
||||
def generate(
|
||||
task: RoutesCompilerTask,
|
||||
namespace: Option[String],
|
||||
rules: List[Rule]
|
||||
): Seq[(String, String)] = {
|
||||
val folder = namespace.map(_.replace('.', '/') + "/").getOrElse("") + "/"
|
||||
|
||||
val sourceInfo =
|
||||
|
@ -25,16 +29,20 @@ object LilaRoutesGenerator extends RoutesGenerator {
|
|||
|
||||
val forwardsRoutesFiles = if (task.forwardsRouter) {
|
||||
Seq(folder + ForwardsRoutesFile -> generateRouter(sourceInfo, namespace, task.additionalImports, rules))
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Nil
|
||||
}
|
||||
|
||||
val reverseRoutesFiles = if (task.reverseRouter) {
|
||||
generateReverseRouters(sourceInfo, namespace, task.additionalImports, routes, task.namespaceReverseRouter) ++
|
||||
generateReverseRouters(
|
||||
sourceInfo,
|
||||
namespace,
|
||||
task.additionalImports,
|
||||
routes,
|
||||
task.namespaceReverseRouter
|
||||
) ++
|
||||
generateJavaWrappers(sourceInfo, namespace, rules, task.namespaceReverseRouter)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.0")
|
||||
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")
|
||||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.0")
|
||||
|
|
Loading…
Reference in New Issue