Skip to content

Commit 4320266

Browse files
authored
Fixing scalafmt configuration (#14)
* Fix sbt build for scalafmt config * Tuning scalafmt config * Reformatting method definition * Update formatter conf for alignment
1 parent 2e20857 commit 4320266

File tree

11 files changed

+80
-47
lines changed

11 files changed

+80
-47
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
# All files
4+
insert_final_newline = true
5+
6+
# 2 spaces indentation
7+
[*.scala, *.sbt]
8+
indent_style = space
9+
indent_size = 2

build.sbt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,25 @@ val commonSettings = Seq(
3737
Set(
3838
"-Ywarn-unused:imports",
3939
"-Xfatal-warnings"
40-
))),
40+
)
41+
)),
4142
scalacOptions in (Test, compile) ~= (_.filterNot(
4243
Set(
4344
"-Ywarn-unused:imports",
4445
"-Xfatal-warnings",
4546
"-Yrangepos"
46-
))),
47+
)
48+
)),
4749
resolvers ++= Seq[Resolver](
4850
Resolver.sonatypeRepo("releases")
4951
)
5052
)
5153

54+
scalafmtOnCompile in ThisBuild := true
5255
scalafmtOnCompile := true
53-
scalafmtConfig := file("project/scalafmt.conf")
56+
scalafmtTestOnCompile in ThisBuild := true
57+
scalafmtTestOnCompile := true
58+
scalafmtConfig in ThisBuild := file("project/scalafmt.conf")
5459

5560
wartremoverErrors ++= Warts.unsafe
5661

@@ -62,7 +67,7 @@ lazy val core = (project in file("core"))
6267
name := "query-core",
6368
libraryDependencies ++= Seq(
6469
Dependencies.acolyte % Test,
65-
Dependencies.anorm % Test,
70+
Dependencies.anorm % Test,
6671
Dependencies.cats,
6772
Dependencies.specs2 % Test
6873
)

core/src/main/scala/core/database/ComposeWithCompletion.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import scala.concurrent.{ExecutionContext, Future}
44
import scala.language.higherKinds
55

66
/**
7-
* Heavily inspired from work done by @cchantep in Acolyte (see acolyte.reactivemongo.ComposeWithCompletion)
8-
*/
7+
* Heavily inspired from work done by @cchantep in Acolyte (see acolyte.reactivemongo.ComposeWithCompletion)
8+
*/
99
trait ComposeWithCompletion[F[_], Out] {
1010
type Outer <: Future[_]
1111

1212
def apply[In](resource: In, f: In => F[Out])(onComplete: In => Unit)(
13-
implicit ec: ExecutionContext): Outer
13+
implicit ec: ExecutionContext
14+
): Outer
1415
}
1516

1617
object ComposeWithCompletion extends LowPriorityCompose {
@@ -21,8 +22,9 @@ object ComposeWithCompletion extends LowPriorityCompose {
2122
new ComposeWithCompletion[Future, A] {
2223
type Outer = Future[A]
2324

24-
def apply[In](resource: In, f: In => Future[A])(onComplete: In => Unit)(
25-
implicit ec: ExecutionContext): Outer =
25+
def apply[In](resource: In, f: In => Future[A])(
26+
onComplete: In => Unit
27+
)(implicit ec: ExecutionContext): Outer =
2628
f(resource).andThen {
2729
case _ => onComplete(resource)
2830
}
@@ -38,8 +40,9 @@ trait LowPriorityCompose { _: ComposeWithCompletion.type =>
3840
new ComposeWithCompletion[F, A] {
3941
type Outer = Future[F[A]]
4042

41-
def apply[In](resource: In, f: In => F[A])(onComplete: In => Unit)(
42-
implicit ec: ExecutionContext): Outer =
43+
def apply[In](resource: In, f: In => F[A])(
44+
onComplete: In => Unit
45+
)(implicit ec: ExecutionContext): Outer =
4346
Future(f(resource)).andThen { case _ => onComplete(resource) }
4447

4548
override val toString = "pureOut"

core/src/main/scala/core/database/QueryRunner.scala

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,22 @@ import scala.concurrent.ExecutionContext
44
import scala.language.higherKinds
55

66
/**
7-
* A class who can run a Query.
8-
*/
7+
* A class who can run a Query.
8+
*/
99
sealed trait QueryRunner[Resource] {
10-
def apply[M[_], T](
11-
query: QueryT[M, Resource, T]
12-
)(
10+
def apply[M[_], T](query: QueryT[M, Resource, T])(
1311
implicit compose: ComposeWithCompletion[M, T]
1412
): compose.Outer
1513
}
1614

1715
object QueryRunner {
18-
private class DefaultRunner[Resource](
19-
wr: WithResource[Resource]
20-
)(
16+
private class DefaultRunner[Resource](wr: WithResource[Resource])(
2117
implicit ec: ExecutionContext
2218
) extends QueryRunner[Resource] {
2319

2420
def apply[M[_], T](
2521
query: QueryT[M, Resource, T]
26-
)(
27-
implicit compose: ComposeWithCompletion[M, T]
28-
): compose.Outer = {
22+
)(implicit compose: ComposeWithCompletion[M, T]): compose.Outer = {
2923
wr { resource =>
3024
compose(resource, query.run)(wr.releaseIfNecessary)
3125
}
@@ -36,8 +30,6 @@ object QueryRunner {
3630
// Default factory
3731
def apply[Resource](
3832
wr: WithResource[Resource]
39-
)(
40-
implicit ec: ExecutionContext
41-
): QueryRunner[Resource] =
33+
)(implicit ec: ExecutionContext): QueryRunner[Resource] =
4234
new DefaultRunner(wr)
4335
}

core/src/main/scala/core/module/sql/package.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import cats.Applicative
99

1010
import com.zengularity.querymonad.core.database.{
1111
Query,
12+
QueryE,
13+
QueryO,
1214
QueryRunner,
1315
QueryT,
14-
QueryO,
15-
QueryE,
1616
WithResource
1717
}
1818

@@ -57,8 +57,9 @@ package object sql {
5757
type SqlQueryRunner = QueryRunner[Connection]
5858

5959
object SqlQueryRunner {
60-
def apply(wc: WithSqlConnection)(
61-
implicit ec: ExecutionContext): SqlQueryRunner =
60+
def apply(
61+
wc: WithSqlConnection
62+
)(implicit ec: ExecutionContext): SqlQueryRunner =
6263
QueryRunner[Connection](wc)
6364
}
6465

core/src/test/scala/module/sql/SqlQueryRunnerSpec.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import org.specs2.mutable.Specification
1111

1212
import com.zengularity.querymonad.core.module.sql.{
1313
SqlQuery,
14-
SqlQueryT,
1514
SqlQueryRunner,
15+
SqlQueryT,
1616
WithSqlConnection
1717
}
1818
import com.zengularity.querymonad.test.core.module.sql.models.{
@@ -51,7 +51,8 @@ class SqlQueryRunnerSpec(implicit ee: ExecutionEnv) extends Specification {
5151
val result = runner(Professor.fetchProfessor(1)).map(_.get)
5252

5353
result aka "professor" must beTypedEqualTo(
54-
Professor(1, "John Doe", 35, 1)).await
54+
Professor(1, "John Doe", 35, 1)
55+
).await
5556
}
5657

5758
"retrieve material with id 1" in {
@@ -61,15 +62,16 @@ class SqlQueryRunnerSpec(implicit ee: ExecutionEnv) extends Specification {
6162
val result = runner(Material.fetchMaterial(1)).map(_.get)
6263

6364
result aka "material" must beTypedEqualTo(
64-
Material(1, "Computer Science", 20, "Beginner")).await
65+
Material(1, "Computer Science", 20, "Beginner")
66+
).await
6567
}
6668

6769
"not retrieve professor with id 2" in {
6870
val withSqlConnection: WithSqlConnection =
6971
SqlConnectionFactory.withSqlConnection(AcolyteQueryResult.Nil)
7072
val runner = SqlQueryRunner(withSqlConnection)
7173
val query = for {
72-
_ <- SqlQuery.ask
74+
_ <- SqlQuery.ask
7375
professor <- Professor.fetchProfessor(2)
7476
} yield professor
7577

@@ -93,12 +95,13 @@ class SqlQueryRunnerSpec(implicit ee: ExecutionEnv) extends Specification {
9395
val runner = SqlQueryRunner(withSqlConnection)
9496
val query = for {
9597
professor <- Professor.fetchProfessor(1).map(_.get)
96-
material <- Material.fetchMaterial(professor.material).map(_.get)
98+
material <- Material.fetchMaterial(professor.material).map(_.get)
9799
} yield (professor, material)
98100

99101
runner(query) aka "professor and material" must beTypedEqualTo(
100102
Tuple2(Professor(1, "John Doe", 35, 1),
101-
Material(1, "Computer Science", 20, "Beginner"))).await
103+
Material(1, "Computer Science", 20, "Beginner"))
104+
).await
102105
}
103106

104107
"not retrieve professor with id 1 and no material" in {
@@ -115,7 +118,8 @@ class SqlQueryRunnerSpec(implicit ee: ExecutionEnv) extends Specification {
115118
val query = for {
116119
professor <- SqlQueryT.fromQuery(Professor.fetchProfessor(1))
117120
material <- SqlQueryT.fromQuery(
118-
Material.fetchMaterial(professor.material))
121+
Material.fetchMaterial(professor.material)
122+
)
119123
} yield (professor, material)
120124

121125
runner(query) aka "professor and material" must beNone.await

core/src/test/scala/module/sql/models/Material.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ case class Material(id: Int, name: String, numberOfHours: Int, level: String)
1111

1212
object Material {
1313
val schema = rowList4(
14-
classOf[Int] -> "id",
14+
classOf[Int] -> "id",
1515
classOf[String] -> "name",
16-
classOf[Int] -> "numberOfHours",
16+
classOf[Int] -> "numberOfHours",
1717
classOf[String] -> "level"
1818
)
1919

core/src/test/scala/module/sql/models/Professor.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ case class Professor(id: Int, name: String, age: Int, material: Int)
1111

1212
object Professor {
1313
val schema = rowList4(
14-
classOf[Int] -> "id",
14+
classOf[Int] -> "id",
1515
classOf[String] -> "name",
16-
classOf[Int] -> "age",
17-
classOf[Int] -> "material"
16+
classOf[Int] -> "age",
17+
classOf[Int] -> "material"
1818
)
1919

2020
val parser = Macro.namedParser[Professor]

core/src/test/scala/module/sql/utils/SqlConnectionFactory.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import com.zengularity.querymonad.core.module.sql.WithSqlConnection
1313
object SqlConnectionFactory {
1414

1515
def withSqlConnection[A <: AcolyteQueryResult](
16-
resultsSet: A): WithSqlConnection =
16+
resultsSet: A
17+
): WithSqlConnection =
1718
new WithSqlConnection {
1819
def apply[B](f: Connection => B): B =
1920
AcolyteDSL.withQueryResult(resultsSet)(f)

examples/sample-app/app/wiring/AppLoader.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import play.api.routing.sird._
1212

1313
import com.zengularity.querymonad.core.module.sql.{
1414
SqlQuery,
15-
SqlQueryT,
16-
SqlQueryRunner
15+
SqlQueryRunner,
16+
SqlQueryT
1717
}
1818
import com.zengularity.querymonad.examples.database.WithPlayTransaction
1919

@@ -45,7 +45,8 @@ class AppComponents(context: Context)
4545
Future {
4646
Thread.sleep(2000) // Simumlates a a very slow query
4747
SQL"select sqrt($num) as result".as(
48-
SqlParser.double("result").single)
48+
SqlParser.double("result").single
49+
)
4950
}
5051
}
5152

@@ -57,8 +58,10 @@ class AppComponents(context: Context)
5758
val query =
5859
for {
5960
number <- SqlQuery.pure(42)
60-
text <- SqlQuery(implicit c =>
61-
SQL"select $cmd as result".as(SqlParser.str("result").single))
61+
text <- SqlQuery(
62+
implicit c =>
63+
SQL"select $cmd as result".as(SqlParser.str("result").single)
64+
)
6265
} yield (text + number)
6366

6467
queryRunner(query).map(r => Ok(r.toString))

0 commit comments

Comments
 (0)