Skip to content

Commit 1152c28

Browse files
authored
Update scalafmt-core to 2.5.1 (#116)
1 parent 220b67e commit 1152c28

File tree

7 files changed

+79
-85
lines changed

7 files changed

+79
-85
lines changed

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 2.4.2
1+
version = 2.5.1
22
style = defaultWithAlign
33
maxColumn = 100
44

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
addCommandAlias("ci-test", "scalafmtCheck; scalafmtSbtCheck; test")
1+
addCommandAlias("ci-test", "scalafmtCheckAll; scalafmtSbtCheck; test")
22
addCommandAlias("ci-docs", "github; project-docs/mdoc; headerCreateAll")
33

44
Universal / javaOptions += "-Dscala.classpath.closeZip=true"

project/ProjectPlugin.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ object ProjectPlugin extends AutoPlugin {
7070
"org.typelevel" %% "cats-effect" % V.catsEffect,
7171
"io.circe" %% "circe-core" % V.circe,
7272
"io.circe" %% "circe-generic" % V.circe,
73-
"org.slf4j" % "slf4j-simple" % V.slf4j,
73+
"org.slf4j" % "slf4j-simple" % V.slf4j,
7474
"org.http4s" %% "http4s-dsl" % V.http4s,
7575
"org.http4s" %% "http4s-blaze-server" % V.http4s,
7676
"org.http4s" %% "http4s-circe" % V.http4s,
7777
"io.get-coursier" %% "coursier" % V.coursier,
7878
"io.get-coursier" %% "coursier-cache" % V.coursier,
79-
"com.typesafe" % "config" % V.config,
79+
"com.typesafe" % "config" % V.config,
8080
"com.pauldijou" %% "jwt-core" % V.jwtCore,
8181
"io.get-coursier" %% "coursier-cats-interop" % V.coursier,
8282
"org.scalatest" %% "scalatest" % V.scalatest,
8383
"org.scalatestplus" %% "scalacheck-1-14" % V.scalatestplusScheck,
84-
"joda-time" % "joda-time" % V.jodaTime
84+
"joda-time" % "joda-time" % V.jodaTime
8585
)
8686
)
8787

project/plugins.sbt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.1")
2-
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
3-
addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.5.0")
4-
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
5-
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.3")
6-
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
7-
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.1.5")
8-
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
9-
addSbtPlugin("com.alejandrohdezma" %% "sbt-github" % "0.8.0")
10-
addSbtPlugin("com.alejandrohdezma" % "sbt-github-header" % "0.8.0")
11-
addSbtPlugin("com.alejandrohdezma" % "sbt-github-mdoc" % "0.8.0")
12-
addSbtPlugin("com.alejandrohdezma" % "sbt-mdoc-toc" % "0.2")
1+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.1")
2+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
3+
addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.5.0")
4+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
5+
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.3")
6+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.4")
7+
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.1.5")
8+
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
9+
addSbtPlugin("com.alejandrohdezma" %% "sbt-github" % "0.8.0")
10+
addSbtPlugin("com.alejandrohdezma" % "sbt-github-header" % "0.8.0")
11+
addSbtPlugin("com.alejandrohdezma" % "sbt-github-mdoc" % "0.8.0")
12+
addSbtPlugin("com.alejandrohdezma" % "sbt-mdoc-toc" % "0.2")

server/src/main/scala/org/scalaexercises/evaluator/auth.scala

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ object auth {
3434

3535
val SecretKeyPath = "eval.auth.secretKey"
3636

37-
val secretKey = if (config.hasPath(SecretKeyPath)) {
38-
config.getString(SecretKeyPath)
39-
} else {
40-
throw new IllegalStateException(
41-
"Missing -Deval.auth.secretKey=[YOUR_KEY_HERE] or env var [EVAL_SECRET_KEY] "
42-
)
43-
}
37+
val secretKey =
38+
if (config.hasPath(SecretKeyPath))
39+
config.getString(SecretKeyPath)
40+
else {
41+
throw new IllegalStateException(
42+
"Missing -Deval.auth.secretKey=[YOUR_KEY_HERE] or env var [EVAL_SECRET_KEY] "
43+
)
44+
}
4445

4546
def generateToken(value: String = "{}") =
4647
Jwt.encode(value, secretKey, JwtAlgorithm.HS256)
@@ -69,22 +70,19 @@ object auth {
6970
def apply[F[_]: Sync](service: HttpApp[F]): HttpApp[F] =
7071
HttpRoutes
7172
.of[F] {
72-
case req if req.headers.nonEmpty => {
73+
case req if req.headers.nonEmpty =>
7374
req.headers.get(`X-Scala-Eval-Api-Token`) match {
7475
case Some(header) =>
7576
Jwt.decodeRaw(header.token, secretKey, Seq(JwtAlgorithm.HS256)) match {
76-
case Success(tokenIdentity) => {
77+
case Success(tokenIdentity) =>
7778
logger.info(s"Auth success with identity : $tokenIdentity")
7879
service(req)
79-
}
80-
case Failure(ex) => {
80+
case Failure(ex) =>
8181
logger.warn(s"Auth failed : $ex")
8282
Sync[F].pure(Response(Status.Unauthorized))
83-
}
8483
}
8584
case None => Sync[F].pure(Response(Status.Unauthorized))
8685
}
87-
}
8886
case _ => Sync[F].pure(Response(Status.Unauthorized))
8987
}
9088
.orNotFound

server/src/main/scala/org/scalaexercises/evaluator/evaluation.scala

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import scala.tools.nsc.{Global, Settings}
4040
import scala.util.{Failure, Success, Try}
4141
import scala.util.control.NonFatal
4242

43-
class Evaluator[F[_]: Sync](timeout: FiniteDuration = 20.seconds)(
44-
implicit F: ConcurrentEffect[F],
43+
class Evaluator[F[_]: Sync](timeout: FiniteDuration = 20.seconds)(implicit
44+
F: ConcurrentEffect[F],
4545
T: Timer[F]
4646
) {
4747
type Remote = String
@@ -188,19 +188,17 @@ private class StringCompiler(
188188
}
189189
// the line number is not always available
190190
val lineMessage =
191-
try {
192-
"line " + (pos.line - lineOffset)
193-
} catch {
191+
try "line " + (pos.line - lineOffset)
192+
catch {
194193
case _: Throwable => ""
195194
}
196195
messages += (severityName + lineMessage + ": " + message) ::
197196
(if (pos.isDefined) {
198197
pos.finalPosition.lineContent.stripLineEnd ::
199198
(" " * (pos.column - 1) + "^") ::
200199
Nil
201-
} else {
202-
Nil
203-
})
200+
} else
201+
Nil)
204202
}
205203

206204
override def reset = {
@@ -213,16 +211,13 @@ private class StringCompiler(
213211

214212
def reset() = {
215213
targetDir match {
216-
case None => {
214+
case None =>
217215
output.asInstanceOf[VirtualDirectory].clear()
218-
}
219-
case Some(t) => {
216+
case Some(t) =>
220217
output.foreach { abstractFile =>
221-
if (abstractFile.file == null || abstractFile.file.getName.endsWith(".class")) {
218+
if (abstractFile.file == null || abstractFile.file.getName.endsWith(".class"))
222219
abstractFile.delete()
223-
}
224220
}
225-
}
226221
}
227222
global.cleanup
228223
cache.clear()
@@ -303,9 +298,8 @@ private class StringCompiler(
303298
*/
304299
class Eval(target: Option[File] = None, jars: List[File] = Nil) {
305300
private lazy val compilerPath =
306-
try {
307-
classPathOfClass("scala.tools.nsc.Interpreter")
308-
} catch {
301+
try classPathOfClass("scala.tools.nsc.Interpreter")
302+
catch {
309303
case e: Throwable =>
310304
throw new RuntimeException(
311305
"Unable to load Scala interpreter from classpath (scala-compiler jar is missing?)",
@@ -314,9 +308,8 @@ class Eval(target: Option[File] = None, jars: List[File] = Nil) {
314308
}
315309

316310
private lazy val libPath =
317-
try {
318-
classPathOfClass("scala.AnyVal")
319-
} catch {
311+
try classPathOfClass("scala.AnyVal")
312+
catch {
320313
case e: Throwable =>
321314
throw new RuntimeException(
322315
"Unable to load scala base object from classpath (scala-library jar is missing?)",
@@ -445,31 +438,32 @@ class ${className} extends (() => Any) with java.io.Serializable {
445438
val classPath = getClassPath(this.getClass.getClassLoader)
446439
val currentClassPath = classPath.head
447440

448-
def checkCurrentClassPath: List[String] = currentClassPath match {
449-
case List(jarFile) if jarFile.endsWith(".jar") =>
450-
val relativeRoot = new File(jarFile).getParentFile
451-
val jarResource: Resource[IO, JarFile] =
452-
Resource.make(IO(new JarFile(jarFile)))(jar => IO(jar.close()))
453-
454-
val nestedClassPath: IO[String] =
455-
jarResource
456-
.use(jar => IO(jar.getManifest.getMainAttributes.getValue("Class-Path")))
457-
.handleError {
458-
case scala.util.control.NonFatal(e) =>
459-
throw new CompilerException(List(List(e.getMessage)))
460-
}
461-
462-
nestedClassPath.map {
463-
case ncp if ncp eq null => Nil
464-
case ncp =>
465-
ncp
466-
.split(" ")
467-
.map(f => new File(relativeRoot, f).getAbsolutePath)
468-
.toList
469-
470-
}.unsafeRunSync
471-
case _ => Nil
472-
}
441+
def checkCurrentClassPath: List[String] =
442+
currentClassPath match {
443+
case List(jarFile) if jarFile.endsWith(".jar") =>
444+
val relativeRoot = new File(jarFile).getParentFile
445+
val jarResource: Resource[IO, JarFile] =
446+
Resource.make(IO(new JarFile(jarFile)))(jar => IO(jar.close()))
447+
448+
val nestedClassPath: IO[String] =
449+
jarResource
450+
.use(jar => IO(jar.getManifest.getMainAttributes.getValue("Class-Path")))
451+
.handleError {
452+
case scala.util.control.NonFatal(e) =>
453+
throw new CompilerException(List(List(e.getMessage)))
454+
}
455+
456+
nestedClassPath.map {
457+
case ncp if ncp eq null => Nil
458+
case ncp =>
459+
ncp
460+
.split(" ")
461+
.map(f => new File(relativeRoot, f).getAbsolutePath)
462+
.toList
463+
464+
}.unsafeRunSync
465+
case _ => Nil
466+
}
473467

474468
// if there's just one thing in the classpath, and it's a jar, assume an executable jar.
475469
currentClassPath ::: checkCurrentClassPath ::: classPath.tail.flatten

server/src/test/scala/org/scalaexercises/evaluator/helper.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,25 @@ object helper {
2525

2626
case object Scala213 extends ScalaVersion("2.13.1")
2727

28-
def toScalaVersion(v: String): ScalaVersion = v match {
29-
case version if version.startsWith("2.13") => Scala213
30-
case _ => throw new IllegalArgumentException(s"Unknown Scala Version $v")
31-
}
28+
def toScalaVersion(v: String): ScalaVersion =
29+
v match {
30+
case version if version.startsWith("2.13") => Scala213
31+
case _ => throw new IllegalArgumentException(s"Unknown Scala Version $v")
32+
}
3233

3334
val commonResolvers = List(
3435
"https://oss.sonatype.org/content/repositories/snapshots",
3536
"https://oss.sonatype.org/content/repositories/public",
3637
"http://repo1.maven.org/maven2"
3738
)
3839

39-
def scalaDependencies(scala: ScalaVersion): List[Dependency] = List(
40-
Dependency("org.scala-lang", s"scala-library", s"${scala.version}"),
41-
Dependency("org.scala-lang", s"scala-reflect", s"${scala.version}"),
42-
Dependency("org.scala-lang", s"scala-compiler", s"${scala.version}"),
43-
Dependency("org.scala-lang.modules", s"scala-xml_${scala.version.substring(0, 4)}", "1.2.0")
44-
)
40+
def scalaDependencies(scala: ScalaVersion): List[Dependency] =
41+
List(
42+
Dependency("org.scala-lang", s"scala-library", s"${scala.version}"),
43+
Dependency("org.scala-lang", s"scala-reflect", s"${scala.version}"),
44+
Dependency("org.scala-lang", s"scala-compiler", s"${scala.version}"),
45+
Dependency("org.scala-lang.modules", s"scala-xml_${scala.version.substring(0, 4)}", "1.2.0")
46+
)
4547

4648
def circeLibraryDependencies(scala: ScalaVersion): List[Dependency] = {
4749
val sv = scala.version

0 commit comments

Comments
 (0)