Skip to content

Commit 31aa306

Browse files
authored
Update scalafmt-core to 2.7.0
1 parent 6c50c2e commit 31aa306

File tree

7 files changed

+87
-113
lines changed

7 files changed

+87
-113
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.6.4
1+
version=2.7.0
22
style = defaultWithAlign
33
maxColumn = 100
44

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ lazy val `sbt-exercise` = (project in file("sbt-exercise"))
7474
buildInfoPackage := "org.scalaexercises.plugin.sbtexercise",
7575
buildInfoKeys := Seq(
7676
version,
77-
BuildInfoKey.map(compilerClasspath) {
78-
case (_, classFiles) ("compilerClasspath", classFiles.map(_.data))
77+
BuildInfoKey.map(compilerClasspath) { case (_, classFiles)
78+
("compilerClasspath", classFiles.map(_.data))
7979
}
8080
)
8181
)

compiler/src/main/scala/org/scalaexercises/exercises/compiler/SourceTextExtraction.scala

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ class SourceTextExtraction {
6161
absolutePath.split(base).lift(1).getOrElse("")
6262

6363
def extractAll(sources: List[String], paths: List[String], baseDir: String): Extracted = {
64-
new global.Run() compileSources (paths zip sources).map({
65-
case (path, code) => new BatchSourceFile(path, code)
64+
new global.Run() compileSources (paths zip sources).map({ case (path, code) =>
65+
new BatchSourceFile(path, code)
6666
})
6767
val run = global.currentRun
68-
val symbolPaths = Map(run.symSource.toList: _*).map({
69-
case (symbol, file) => (symbol.toString, relativePath(file.path, baseDir))
68+
val symbolPaths = Map(run.symSource.toList: _*).map({ case (symbol, file) =>
69+
(symbol.toString, relativePath(file.path, baseDir))
7070
})
7171
val compilationUnits = run.units.toList // `units` is only only iterable once!
7272
val extractions = compilationUnits.map(_.body).map(boundExtractRaw)
@@ -84,27 +84,25 @@ class SourceTextExtraction {
8484
p flatMap (_.split('.').toList)
8585

8686
val (commentss, methodss) = extractions.map { extraction =>
87-
val comments = extraction.comments.map(expandPath).map {
88-
case (k, v) =>
89-
splitPackage(k) -> new ExtractedComment(v._2.raw, commentFactory.parse(v._2))
87+
val comments = extraction.comments.map(expandPath).map { case (k, v) =>
88+
splitPackage(k) -> new ExtractedComment(v._2.raw, commentFactory.parse(v._2))
9089
}
9190

9291
val rawImports = extraction.imports
9392
val paths = rawImports.map(expandPath)
9493

9594
val imports = paths.groupBy(_._1).view.mapValues(_.map(_._2)).toMap
9695

97-
val methods = extraction.methods.map(expandPath).map {
98-
case (k, v) =>
99-
lazy val methodImports = k
100-
.scanLeft(Nil: List[String])((a, c) => c :: a)
101-
.map(_.reverse)
102-
.flatMap(imports.get)
103-
.flatten
104-
.collect {
105-
case (order, imp) if order < v._1 => showCode(imp)
106-
}
107-
splitPackage(k) -> new ExtractedMethod(boundReadCode(v._2), methodImports)
96+
val methods = extraction.methods.map(expandPath).map { case (k, v) =>
97+
lazy val methodImports = k
98+
.scanLeft(Nil: List[String])((a, c) => c :: a)
99+
.map(_.reverse)
100+
.flatMap(imports.get)
101+
.flatten
102+
.collect {
103+
case (order, imp) if order < v._1 => showCode(imp)
104+
}
105+
splitPackage(k) -> new ExtractedMethod(boundReadCode(v._2), methodImports)
108106
}
109107
(comments, methods)
110108
}.unzip
@@ -159,8 +157,8 @@ object SourceTextExtraction {
159157
case DocDef(comment, moduleDef @ ModuleDef(_, _, impl)) =>
160158
val nextPath = moduleDef.name :: path
161159
traversal(
162-
impl.body.zipWithIndex.map {
163-
case (body, index) => (nextPath, index, body)
160+
impl.body.zipWithIndex.map { case (body, index) =>
161+
(nextPath, index, body)
164162
} ::: rs,
165163
visitDocComment(nextPath.reverse, comment, acc)
166164
)
@@ -169,8 +167,8 @@ object SourceTextExtraction {
169167
case DocDef(comment, classDef @ ClassDef(_, _, Nil, impl)) =>
170168
val nextPath = classDef.name :: path
171169
traversal(
172-
impl.body.zipWithIndex.map {
173-
case (body, index) => (nextPath, index, body)
170+
impl.body.zipWithIndex.map { case (body, index) =>
171+
(nextPath, index, body)
174172
} ::: rs,
175173
visitDocComment(nextPath.reverse, comment, acc)
176174
)
@@ -190,8 +188,8 @@ object SourceTextExtraction {
190188
case moduleDef @ ModuleDef(_, _, impl) =>
191189
val nextPath = moduleDef.name :: path
192190
traversal(
193-
impl.body.zipWithIndex.map {
194-
case (body, index) => (nextPath, index, body)
191+
impl.body.zipWithIndex.map { case (body, index) =>
192+
(nextPath, index, body)
195193
} ::: rs,
196194
acc
197195
)
@@ -200,8 +198,8 @@ object SourceTextExtraction {
200198
case classDef @ ClassDef(_, _, Nil, impl) =>
201199
val nextPath = classDef.name :: path
202200
traversal(
203-
impl.body.zipWithIndex.map {
204-
case (body, index) => (nextPath, index, body)
201+
impl.body.zipWithIndex.map { case (body, index) =>
202+
(nextPath, index, body)
205203
} ::: rs,
206204
acc
207205
)
@@ -211,8 +209,8 @@ object SourceTextExtraction {
211209
if (ref.name == termNames.EMPTY_PACKAGE_NAME) path
212210
else TermName(ref.toString) :: path
213211
traversal(
214-
topstats.zipWithIndex.map {
215-
case (body, index) => (nextPath, index, body)
212+
topstats.zipWithIndex.map { case (body, index) =>
213+
(nextPath, index, body)
216214
} ::: rs,
217215
acc
218216
)

compiler/src/test/scala/org/scalaexercises/exercises/compiler/CommentParsingRenderingSpec.scala

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -151,31 +151,25 @@ class CommentParsingRenderingSpec extends AnyFunSpec with Matchers with Inside {
151151
it("properly handles names") {
152152

153153
comments.withoutNames.foreach { comment =>
154-
inside(CommentParsing.parse[Mode.Name[Id]](comment)) {
155-
case Left(_) =>
154+
inside(CommentParsing.parse[Mode.Name[Id]](comment)) { case Left(_) =>
156155
}
157-
inside(CommentParsing.parse[Mode.Name[Option]](comment)) {
158-
case Right(parsed) =>
159-
parsed.name shouldEqual None
156+
inside(CommentParsing.parse[Mode.Name[Option]](comment)) { case Right(parsed) =>
157+
parsed.name shouldEqual None
160158
}
161-
inside(CommentParsing.parse[Mode.Name[Empty]](comment)) {
162-
case Right(parsed) =>
163-
parsed.name shouldEqual Empty
159+
inside(CommentParsing.parse[Mode.Name[Empty]](comment)) { case Right(parsed) =>
160+
parsed.name shouldEqual Empty
164161
}
165162

166163
}
167164

168165
comments.withNames.foreach { comment =>
169-
inside(CommentParsing.parse[Mode.Name[Id]](comment)) {
170-
case Right(parsed) =>
171-
parsed.name shouldEqual comments.name
166+
inside(CommentParsing.parse[Mode.Name[Id]](comment)) { case Right(parsed) =>
167+
parsed.name shouldEqual comments.name
172168
}
173-
inside(CommentParsing.parse[Mode.Name[Option]](comment)) {
174-
case Right(parsed) =>
175-
parsed.name shouldEqual Some(comments.name)
169+
inside(CommentParsing.parse[Mode.Name[Option]](comment)) { case Right(parsed) =>
170+
parsed.name shouldEqual Some(comments.name)
176171
}
177-
inside(CommentParsing.parse[Mode.Name[Empty]](comment)) {
178-
case Left(_) =>
172+
inside(CommentParsing.parse[Mode.Name[Empty]](comment)) { case Left(_) =>
179173
}
180174

181175
}
@@ -201,30 +195,24 @@ class CommentParsingRenderingSpec extends AnyFunSpec with Matchers with Inside {
201195
it("properly handles descriptions") {
202196

203197
comments.withoutDescriptions.foreach { comment =>
204-
inside(CommentParsing.parse[Mode.Description[Id]](comment)) {
205-
case Left(_) =>
198+
inside(CommentParsing.parse[Mode.Description[Id]](comment)) { case Left(_) =>
206199
}
207-
inside(CommentParsing.parse[Mode.Description[Option]](comment)) {
208-
case Right(parsed) =>
209-
parsed.description shouldEqual None
200+
inside(CommentParsing.parse[Mode.Description[Option]](comment)) { case Right(parsed) =>
201+
parsed.description shouldEqual None
210202
}
211-
inside(CommentParsing.parse[Mode.Description[Empty]](comment)) {
212-
case Right(parsed) =>
213-
parsed.description shouldEqual Empty
203+
inside(CommentParsing.parse[Mode.Description[Empty]](comment)) { case Right(parsed) =>
204+
parsed.description shouldEqual Empty
214205
}
215206

216207
}
217208

218209
comments.withDescriptions.foreach { comment =>
219-
inside(CommentParsing.parse[Mode.Description[Id]](comment)) {
220-
case Right(parsed) =>
210+
inside(CommentParsing.parse[Mode.Description[Id]](comment)) { case Right(parsed) =>
221211
}
222-
inside(CommentParsing.parse[Mode.Description[Option]](comment)) {
223-
case Right(parsed) =>
224-
parsed.description shouldBe defined
212+
inside(CommentParsing.parse[Mode.Description[Option]](comment)) { case Right(parsed) =>
213+
parsed.description shouldBe defined
225214
}
226-
inside(CommentParsing.parse[Mode.Description[Empty]](comment)) {
227-
case Left(_) =>
215+
inside(CommentParsing.parse[Mode.Description[Empty]](comment)) { case Left(_) =>
228216
}
229217
}
230218

@@ -233,30 +221,24 @@ class CommentParsingRenderingSpec extends AnyFunSpec with Matchers with Inside {
233221
it("properly handles explanations") {
234222

235223
comments.withoutExplanations.foreach { comment =>
236-
inside(CommentParsing.parse[Mode.Explanation[Id]](comment)) {
237-
case Left(_) =>
224+
inside(CommentParsing.parse[Mode.Explanation[Id]](comment)) { case Left(_) =>
238225
}
239-
inside(CommentParsing.parse[Mode.Explanation[Option]](comment)) {
240-
case Right(parsed) =>
241-
parsed.explanation shouldEqual None
226+
inside(CommentParsing.parse[Mode.Explanation[Option]](comment)) { case Right(parsed) =>
227+
parsed.explanation shouldEqual None
242228
}
243-
inside(CommentParsing.parse[Mode.Explanation[Empty]](comment)) {
244-
case Right(parsed) =>
245-
parsed.explanation shouldEqual Empty
229+
inside(CommentParsing.parse[Mode.Explanation[Empty]](comment)) { case Right(parsed) =>
230+
parsed.explanation shouldEqual Empty
246231
}
247232

248233
}
249234

250235
comments.withExplanations.foreach { comment =>
251-
inside(CommentParsing.parse[Mode.Explanation[Id]](comment)) {
252-
case Right(parsed) =>
236+
inside(CommentParsing.parse[Mode.Explanation[Id]](comment)) { case Right(parsed) =>
253237
}
254-
inside(CommentParsing.parse[Mode.Explanation[Option]](comment)) {
255-
case Right(parsed) =>
256-
parsed.explanation shouldBe defined
238+
inside(CommentParsing.parse[Mode.Explanation[Option]](comment)) { case Right(parsed) =>
239+
parsed.explanation shouldBe defined
257240
}
258-
inside(CommentParsing.parse[Mode.Explanation[Empty]](comment)) {
259-
case Left(_) =>
241+
inside(CommentParsing.parse[Mode.Explanation[Empty]](comment)) { case Left(_) =>
260242
}
261243
}
262244

compiler/src/test/scala/org/scalaexercises/exercises/compiler/CommentRenderingRegressions.scala

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,16 @@ class CommentRenderingRegressions extends AnyFunSpec with Matchers with Inside {
4848
* }}}
4949
*/""")
5050

51-
inside(Comments.parseAndRender[Mode.Exercise](comment)) {
52-
case Right(parsed) =>
53-
// remove XML and check that there is code content
54-
val description = parsed.description
55-
.map(_.replaceAll("\\<.*?\\>", ""))
56-
.getOrElse("")
57-
58-
assert(
59-
description.trim.length > 50,
60-
"Issue #309: code segment was not properly rendered"
61-
)
51+
inside(Comments.parseAndRender[Mode.Exercise](comment)) { case Right(parsed) =>
52+
// remove XML and check that there is code content
53+
val description = parsed.description
54+
.map(_.replaceAll("\\<.*?\\>", ""))
55+
.getOrElse("")
56+
57+
assert(
58+
description.trim.length > 50,
59+
"Issue #309: code segment was not properly rendered"
60+
)
6261
}
6362

6463
}
@@ -74,20 +73,19 @@ class CommentRenderingRegressions extends AnyFunSpec with Matchers with Inside {
7473
* }}}
7574
*/""")
7675

77-
inside(Comments.parseAndRender[Mode.Exercise](comment)) {
78-
case Right(parsed) =>
79-
val description = parsed.description
80-
.map(_.replaceAll("\\<.*?\\>", ""))
81-
.getOrElse("")
76+
inside(Comments.parseAndRender[Mode.Exercise](comment)) { case Right(parsed) =>
77+
val description = parsed.description
78+
.map(_.replaceAll("\\<.*?\\>", ""))
79+
.getOrElse("")
8280

83-
assert(
84-
description.trim ==
85-
"""abstract class Soldier(val firstName: String, val lastName: String) {}
81+
assert(
82+
description.trim ==
83+
"""abstract class Soldier(val firstName: String, val lastName: String) {}
8684
|
8785
|// if you uncomment this line, it will fail compilation
8886
|//val soldier = new Soldier""".stripMargin,
89-
"Issue scala-exercises/exercises-stdlib#50: comment rendering problem"
90-
)
87+
"Issue scala-exercises/exercises-stdlib#50: comment rendering problem"
88+
)
9189
}
9290
}
9391
}

compiler/src/test/scala/org/scalaexercises/exercises/compiler/SourceTextExtractionSpec.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ class SourceTextExtractionSpec extends AnyFunSpec with Matchers with Inside {
8484
it("should find all doc comments on classes and objects") {
8585
val comments = res.comments
8686
comments shouldNot be(empty)
87-
comments foreach {
88-
case (k, _) =>
89-
multiLevelPackage.split('.') foreach (k should contain(_))
87+
comments foreach { case (k, _) =>
88+
multiLevelPackage.split('.') foreach (k should contain(_))
9089
}
9190
comments map { case (k, v) => k.mkString(".") -> v.raw } should equal(
9291
Map(
@@ -133,15 +132,13 @@ class SourceTextExtractionSpec extends AnyFunSpec with Matchers with Inside {
133132
val res = new SourceTextExtraction().extractAll(source1 :: source2 :: Nil, paths, "/")
134133

135134
// Should capture exactly 1 import for Object1.method
136-
inside(res.methods.get("Object1" :: "method" :: Nil)) {
137-
case Some(method) =>
138-
method.imports shouldEqual List("import a._", "import b._")
135+
inside(res.methods.get("Object1" :: "method" :: Nil)) { case Some(method) =>
136+
method.imports shouldEqual List("import a._", "import b._")
139137
}
140138

141139
// Should capture exactly 2 imports for Object2.method
142-
inside(res.methods.get("Object2" :: "method" :: Nil)) {
143-
case Some(method) =>
144-
method.imports shouldEqual List("import c._", "import d._", "import obj2._")
140+
inside(res.methods.get("Object2" :: "method" :: Nil)) { case Some(method) =>
141+
method.imports shouldEqual List("import c._", "import d._", "import obj2._")
145142
}
146143

147144
}

sbt-exercise/src/main/scala/org/scalaexercises/exercises/sbtexercise/ExerciseCompilerPlugin.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,11 @@ object ExerciseCompilerPlugin extends AutoPlugin {
267267
val generated = generateExercises.value
268268

269269
val dir = (sourceManaged in Compile).value
270-
generated.map {
271-
case (n, code) =>
272-
val file = dir / (n.replace(".", "/") + ".scala")
273-
IO.write(file, code)
274-
log.info(s"Generated library at $file")
275-
file
270+
generated.map { case (n, code) =>
271+
val file = dir / (n.replace(".", "/") + ".scala")
272+
IO.write(file, code)
273+
log.info(s"Generated library at $file")
274+
file
276275
}
277276
}
278277

0 commit comments

Comments
 (0)