Skip to content

Commit efcf71b

Browse files
authored
Upgrade to latest scalafmt (#305)
1 parent 6c41772 commit efcf71b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1271
-1338
lines changed

.scalafmt.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
version=2.3.2
2-
maxColumn = 110
1+
version=3.9.4
2+
runner.dialect = scala212
3+
maxColumn = 100
34
newlines.penalizeSingleSelectMultiArgList = false
45
align.openParenCallSite = false
56
rewrite.rules = [AvoidInfix, SortImports, RedundantBraces, RedundantParens, PreferCurlyFors]

build.sbt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ lazy val noPublishSettings = Seq(
112112
publishArtifact := false
113113
)
114114

115-
/**
116-
* This returns the previous jar I've released that is compatible
117-
* with the current.
115+
/** This returns the previous jar I've released that is compatible with the current.
118116
*/
119117
val noBinaryCompatCheck = Set[String]("core")
120118

@@ -133,7 +131,9 @@ lazy val rl = Project(id = "scala-rl", base = file("."))
133131
def module(name: String) = {
134132
val id = "scala-rl-%s".format(name)
135133
Project(id = id, base = file(id))
136-
.settings(sharedSettings ++ Seq(Keys.name := id, mimaPreviousArtifacts := previousVersion(name).toSet))
134+
.settings(
135+
sharedSettings ++ Seq(Keys.name := id, mimaPreviousArtifacts := previousVersion(name).toSet)
136+
)
137137
}
138138

139139
lazy val rlCore = module("core").settings(
@@ -192,7 +192,8 @@ implicit val evaluator: Numeric[Real] = new Evaluator(Map.empty)
192192
)
193193
.dependsOn(rlCore, rlPlot, rlWorld)
194194

195-
lazy val docsMappingsAPIDir = settingKey[String]("Name of subdirectory in site target directory for api docs")
195+
lazy val docsMappingsAPIDir =
196+
settingKey[String]("Name of subdirectory in site target directory for api docs")
196197

197198
lazy val docSettings = Seq(
198199
micrositeName := "ScalaRL",
@@ -217,7 +218,10 @@ lazy val docSettings = Seq(
217218
)
218219
),
219220
micrositeEditButton := Some(
220-
MicrositeEditButton("Help us improve this page", "/edit/develop/docs/src/main/tut/{{ page.path }}")
221+
MicrositeEditButton(
222+
"Help us improve this page",
223+
"/edit/develop/docs/src/main/tut/{{ page.path }}"
224+
)
221225
),
222226
micrositeHighlightTheme := "atom-one-light",
223227
micrositePalette := Map(
@@ -239,7 +243,8 @@ lazy val docSettings = Seq(
239243
// Don't kill the cname redirect.
240244
excludeFilter in ghpagesCleanSite :=
241245
new FileFilter {
242-
def accept(f: File) = (ghpagesRepository.value / "CNAME").getCanonicalPath == f.getCanonicalPath
246+
def accept(f: File) =
247+
(ghpagesRepository.value / "CNAME").getCanonicalPath == f.getCanonicalPath
243248
} || "versions.html",
244249
fork in tut := true,
245250
fork in (ScalaUnidoc, unidoc) := true,
@@ -263,5 +268,7 @@ lazy val docs = project
263268
.settings(sharedSettings)
264269
.settings(noPublishSettings)
265270
.settings(docSettings)
266-
.settings((scalacOptions in Tut) ~= (_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-dead-code"))))
271+
.settings(
272+
(scalacOptions in Tut) ~= (_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-dead-code")))
273+
)
267274
.dependsOn(rlCore, rlPlot, rlBook, rlWorld)

project/plugins.sbt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
resolvers ++= Seq(
22
"jgit-repo".at("https://download.eclipse.org/jgit/maven"),
3-
Resolver.url("bintray-sbt-plugin-releases", url("https://dl.bintray.com/content/sbt/sbt-plugin-releases"))(
3+
Resolver.url(
4+
"bintray-sbt-plugin-releases",
5+
url("https://dl.bintray.com/content/sbt/sbt-plugin-releases")
6+
)(
47
Resolver.ivyStylePatterns
58
)
69
)
@@ -11,7 +14,7 @@ addSbtPlugin("com.github.sbt" % "sbt-release" % "1.0.15")
1114
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.2")
1215
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4")
1316
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
14-
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.0")
17+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4")
1518
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
1619
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.3.2")
1720
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1")

scala-rl-book/src/main/scala/com/scalarl/book/Chapter2.scala

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,32 @@ import com.scalarl.policy.bandit.Greedy
1313
import com.scalarl.rainier.Categorical
1414
import com.scalarl.world.Bandit
1515

16-
/**
17-
# Introduction to Chapter 2
18-
19-
This chapter is about Bandits. These are markov processes that know about a
20-
single state, really. The trick here is going to be getting the stuff that
21-
plays these particular states to be more general, and work with the same
22-
machinery that rolls states forward.
23-
24-
25-
* What we REALLY NEED here is both the top and bottom graphs,
26-
* getting it done.
16+
/** # Introduction to Chapter 2
17+
*
18+
* This chapter is about Bandits. These are markov processes that know about a single state,
19+
* really. The trick here is going to be getting the stuff that plays these particular states to be
20+
* more general, and work with the same machinery that rolls states forward.
21+
*
22+
* What we REALLY NEED here is both the top and bottom graphs, getting it done.
2723
*
2824
* The top graph is the average reward across GAMES per step.
2925
*
30-
* So we really want to march them ALL forward and grab the average
31-
* reward...
26+
* So we really want to march them ALL forward and grab the average reward...
3227
*/
3328
object Chapter2 {
3429
import Bandit.Arm
3530
import Episode.Moment
3631

37-
/**
38-
* These are needed to actually call get on anything.
32+
/** These are needed to actually call get on anything.
3933
*/
4034
implicit val rng: RNG = RNG.default
4135
implicit val evaluator: Numeric[Real] = new Evaluator(Map.empty)
4236

4337
// Implementing it the way it does in the book.
4438
def average(s: Iterable[Double]): Double = {
45-
val (sum, n) = s.foldLeft((0.0, 0)) { case ((sum, n), i) => (sum + i, n + 1) }
39+
val (sum, n) = s.foldLeft((0.0, 0)) { case ((sum, n), i) =>
40+
(sum + i, n + 1)
41+
}
4642
sum / n
4743
}
4844

@@ -67,13 +63,14 @@ object Chapter2 {
6763

6864
val elapsed = Stopwatch.start()
6965
val rewardSeq = rewardSeqGen.get
70-
println(s"Time to play $nRuns runs of $timeSteps time steps each: ${elapsed()}")
66+
println(
67+
s"Time to play $nRuns runs of $timeSteps time steps each: ${elapsed()}"
68+
)
7169

7270
rewardSeq
7371
}
7472

75-
/**
76-
* Generates the n-armed testbed.
73+
/** Generates the n-armed testbed.
7774
*/
7875
def nArmedTestbed(
7976
nArms: Int,
@@ -85,8 +82,7 @@ object Chapter2 {
8582
.map(mean => Normal(mean, stdDev).generator)
8683
)
8784

88-
/**
89-
* Generates a non-stationary distribution.
85+
/** Generates a non-stationary distribution.
9086
*/
9187
def nonStationaryTestbed(
9288
nArms: Int,

scala-rl-book/src/main/scala/com/scalarl/book/Chapter3.scala

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/**
2-
This chapter plays a couple of gridworld games. Current goal is to get this
3-
all building, and printing nicely.
4-
5-
This chapter introduces the idea of the Markov Decision Process.
1+
/** This chapter plays a couple of gridworld games. Current goal is to get this all building, and
2+
* printing nicely.
3+
*
4+
* This chapter introduces the idea of the Markov Decision Process.
65
*/
76
package com.scalarl
87
package book
@@ -36,11 +35,9 @@ object Chapter3 {
3635
def notConverging(iterations: Long, allowed: Long): Boolean =
3736
iterations >= allowed
3837

39-
/**
40-
Note... this version, following the python code, checks that the sum of all
41-
differences is less than epsilon. In the next chapter we use the max
42-
function instead here to get this working, to check that the maximum delta
43-
is less than epsilon.
38+
/** Note... this version, following the python code, checks that the sum of all differences is
39+
* less than epsilon. In the next chapter we use the max function instead here to get this
40+
* working, to check that the maximum delta is less than epsilon.
4441
*/
4542
def valueFunctionConverged[Obs, T: ToDouble](
4643
l: StateValueFn[Obs, T],
@@ -55,7 +52,10 @@ object Chapter3 {
5552
notConverging(iterations, allowedIterations) ||
5653
valueFunctionConverged(l, r)
5754

58-
def toTable(conf: GridWorld.Config, f: Position => Double): Iterable[Iterable[Double]] =
55+
def toTable(
56+
conf: GridWorld.Config,
57+
f: Position => Double
58+
): Iterable[Iterable[Double]] =
5959
Grid
6060
.allStates(conf.bounds)
6161
.map(g => f(g.position))
@@ -71,14 +71,16 @@ object Chapter3 {
7171
): Unit = {
7272
val (valueFn, iterations) = pair
7373
println(s"${title}:")
74-
println(Tabulator.format(toTable(conf, p => ToDouble[T].apply(valueFn.stateValue(p)))))
74+
println(
75+
Tabulator.format(
76+
toTable(conf, p => ToDouble[T].apply(valueFn.stateValue(p)))
77+
)
78+
)
7579
println(s"That took $iterations iterations, for the record.")
7680
}
7781

78-
/**
79-
* This is Figure 3.2, with proper stopping conditions and
80-
* everything. Lots of work to go.
81-
* */
82+
/** This is Figure 3.2, with proper stopping conditions and everything. Lots of work to go.
83+
*/
8284
def threeTwo: (StateValueFn[Position, DecayState[Double]], Long) =
8385
Sweep.sweepUntil[Position, Move, Double, DecayState[Double], Cat, Id](
8486
emptyFn,
@@ -90,8 +92,7 @@ object Chapter3 {
9092
valueIteration = false
9193
)
9294

93-
/**
94-
* This is Figure 3.5. This is currently working!
95+
/** This is Figure 3.5. This is currently working!
9596
*/
9697
def threeFive: (StateValueFn[Position, DecayState[Double]], Long) = {
9798
implicit val dm = DecayState.decayStateModule(gamma)
@@ -114,9 +115,7 @@ object Chapter3 {
114115
)
115116
}
116117

117-
/**
118-
* This currently works, and displays rough tables for each of the required
119-
* bits.
118+
/** This currently works, and displays rough tables for each of the required bits.
120119
*/
121120
def main(items: Array[String]): Unit = {
122121
printFigure(gridConf, threeTwo, "Figure 3.2")

0 commit comments

Comments
 (0)