Skip to content

Commit bb0334a

Browse files
committed
scalafmt: apply code formatting
Adjust configuration a little, to be more compatible with existing code.
1 parent 72a5103 commit bb0334a

File tree

163 files changed

+4102
-4316
lines changed

Some content is hidden

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

163 files changed

+4102
-4316
lines changed

.scalafmt.conf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 3.8.2
1+
version = 3.9.4
22

33
style = default
44
maxColumn = 120
@@ -25,7 +25,7 @@ project.excludeFilters = [
2525
storage/src/test/resources
2626
demo/
2727
]
28-
align.preset = more
28+
align.preset = some
2929

3030
rewrite.rules = [Imports]
3131
rewrite.imports.sort = original
@@ -38,8 +38,9 @@ newlines.topLevelStatements = [before, after]
3838
newlines.topLevelStatementsMinBreaks = 2
3939
newlines.implicitParamListModifierForce = [before]
4040

41-
continuationIndent.defnSite = 2
42-
continuationIndent.extendSite = 2
41+
indent.defnSite = 2
42+
indent.extendSite = 2
43+
indent.ctorSite = 4
4344

4445
rewrite.imports.expand = false
4546
rewrite.trailingCommas.style = "never"

api/src/main/scala/com.olegych.scastie.api/ApiModels.scala

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ case class SbtRunnerConnect(hostname: String, port: Int)
99
case object ActorConnected
1010

1111
object SnippetSummary {
12-
implicit val formatSnippetSummary: OFormat[SnippetSummary] =
13-
Json.format[SnippetSummary]
12+
implicit val formatSnippetSummary: OFormat[SnippetSummary] = Json.format[SnippetSummary]
1413
}
1514

1615
case class SnippetSummary(
@@ -20,8 +19,7 @@ case class SnippetSummary(
2019
)
2120

2221
object FormatRequest {
23-
implicit val formatFormatRequest: OFormat[FormatRequest] =
24-
Json.format[FormatRequest]
22+
implicit val formatFormatRequest: OFormat[FormatRequest] = Json.format[FormatRequest]
2523
}
2624

2725
case class FormatRequest(
@@ -31,17 +29,17 @@ case class FormatRequest(
3129
)
3230

3331
object FormatResponse {
32+
3433
implicit object FormatResponseFormat extends Format[FormatResponse] {
34+
3535
def writes(response: FormatResponse): JsValue = {
3636
response.result match {
37-
case Left(error) =>
38-
JsObject(
37+
case Left(error) => JsObject(
3938
Seq(
4039
"Left" -> JsString(error)
4140
)
4241
)
43-
case Right(formatedCode) =>
44-
JsObject(
42+
case Right(formatedCode) => JsObject(
4543
Seq(
4644
"Right" -> JsString(formatedCode)
4745
)
@@ -51,51 +49,55 @@ object FormatResponse {
5149

5250
def reads(json: JsValue): JsResult[FormatResponse] = {
5351
json match {
54-
case JsObject(v) =>
55-
v.toList match {
56-
case List(("Left", JsString(error))) =>
57-
JsSuccess(FormatResponse(Left(error)))
52+
case JsObject(v) => v.toList match {
53+
case List(("Left", JsString(error))) => JsSuccess(FormatResponse(Left(error)))
5854

59-
case List(("Right", JsString(formatedCode))) =>
60-
JsSuccess(FormatResponse(Right(formatedCode)))
55+
case List(("Right", JsString(formatedCode))) => JsSuccess(FormatResponse(Right(formatedCode)))
6156

62-
case _ =>
63-
JsError(Seq())
57+
case _ => JsError(Seq())
6458
}
6559

66-
case _ =>
67-
JsError(Seq())
60+
case _ => JsError(Seq())
6861
}
6962
}
63+
7064
}
71-
}
7265

66+
}
7367

7468
object EitherFormat {
7569
import play.api.libs.functional.syntax._
70+
7671
implicit object JsEither {
7772

78-
implicit def eitherReads[A, B](implicit A: Reads[A], B: Reads[B]): Reads[Either[A, B]] = {
73+
implicit def eitherReads[A, B](
74+
implicit A: Reads[A],
75+
B: Reads[B]
76+
): Reads[Either[A, B]] = {
7977
(JsPath \ "Left" \ "value").read[A].map(Left(_)) or
8078
(JsPath \ "Right" \ "value").read[B].map(Right(_))
8179
}
8280

83-
implicit def eitherWrites[A, B](implicit A: Writes[A], B: Writes[B]): Writes[Either[A, B]] = Writes[Either[A, B]] {
81+
implicit def eitherWrites[A, B](
82+
implicit A: Writes[A],
83+
B: Writes[B]
84+
): Writes[Either[A, B]] = Writes[Either[A, B]] {
8485
case Left(value) => Json.obj("Left" -> Json.toJson(value))
8586
case Right(value) => Json.obj("Right" -> Json.toJson(value))
8687
}
87-
}
88-
}
8988

89+
}
9090

91+
}
9192

9293
case class FormatResponse(
9394
result: Either[String, String]
9495
)
9596

9697
object FetchResult {
9798
implicit val formatFetchResult: OFormat[FetchResult] = Json.format[FetchResult]
98-
def create(inputs: Inputs, progresses: List[SnippetProgress]) = FetchResult(inputs, progresses.sortBy(p => (p.id, p.ts)))
99+
def create(inputs: Inputs, progresses: List[SnippetProgress]) =
100+
FetchResult(inputs, progresses.sortBy(p => (p.id, p.ts)))
99101
}
100102

101103
case class FetchResult private (inputs: Inputs, progresses: List[SnippetProgress])
@@ -110,8 +112,7 @@ case class FetchScalaSource(snippetId: SnippetId)
110112
case class FetchResultScalaSource(content: String)
111113

112114
object ScalaDependency {
113-
implicit val formatScalaDependency: OFormat[ScalaDependency] =
114-
Json.format[ScalaDependency]
115+
implicit val formatScalaDependency: OFormat[ScalaDependency] = Json.format[ScalaDependency]
115116
}
116117

117118
case class ScalaDependency(
@@ -120,9 +121,8 @@ case class ScalaDependency(
120121
target: ScalaTarget,
121122
version: String
122123
) {
123-
def matches(sd: ScalaDependency): Boolean =
124-
sd.groupId == this.groupId &&
125-
sd.artifact == this.artifact
124+
def matches(sd: ScalaDependency): Boolean = sd.groupId == this.groupId &&
125+
sd.artifact == this.artifact
126126

127127
override def toString: String = target.renderSbt(this)
128128
}
@@ -151,7 +151,8 @@ object NoResult {
151151
}
152152

153153
object PresentationCompilerFailure {
154-
implicit val presentationCompilerFailureFormat: OFormat[PresentationCompilerFailure] = Json.format[PresentationCompilerFailure]
154+
implicit val presentationCompilerFailureFormat: OFormat[PresentationCompilerFailure] =
155+
Json.format[PresentationCompilerFailure]
155156
}
156157

157158
object ScastieOffsetParams {
@@ -172,16 +173,15 @@ case class EditRange(startLine: Int, startChar: Int, endLine: Int, endChar: Int)
172173
case class ScalaCompletionList(items: Set[CompletionItemDTO], isIncomplete: Boolean)
173174

174175
case class CompletionItemDTO(
175-
label: String,
176-
detail: String,
177-
tpe: String,
178-
order: Option[Int],
179-
instructions: InsertInstructions,
180-
additionalInsertInstructions: List[AdditionalInsertInstructions],
181-
symbol: Option[String]
176+
label: String,
177+
detail: String,
178+
tpe: String,
179+
order: Option[Int],
180+
instructions: InsertInstructions,
181+
additionalInsertInstructions: List[AdditionalInsertInstructions],
182+
symbol: Option[String]
182183
)
183184

184-
185185
case class HoverDTO(from: Int, to: Int, content: String)
186186

187187
case class CompletionsDTO(items: Set[CompletionItemDTO])
@@ -195,7 +195,8 @@ object InsertInstructions {
195195
}
196196

197197
object AdditionalInsertInstructions {
198-
implicit val additionalInsertInstructionsFormat: OFormat[AdditionalInsertInstructions] = Json.format[AdditionalInsertInstructions]
198+
implicit val additionalInsertInstructionsFormat: OFormat[AdditionalInsertInstructions] =
199+
Json.format[AdditionalInsertInstructions]
199200
}
200201

201202
object ScalaCompletionList {
@@ -219,8 +220,7 @@ object HoverDTO {
219220
}
220221

221222
object Project {
222-
implicit val formatProject: OFormat[Project] =
223-
Json.format[Project]
223+
implicit val formatProject: OFormat[Project] = Json.format[Project]
224224
}
225225

226226
case class Project(

api/src/main/scala/com.olegych.scastie.api/CompilerInfo.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package com.olegych.scastie.api
33
import play.api.libs.json._
44

55
object Severity {
6+
67
implicit object SeverityFormat extends Format[Severity] {
7-
def writes(severity: Severity): JsValue =
8-
severity match {
9-
case Info => JsString("Info")
10-
case Warning => JsString("Warning")
11-
case Error => JsString("Error")
12-
}
8+
9+
def writes(severity: Severity): JsValue = severity match {
10+
case Info => JsString("Info")
11+
case Warning => JsString("Warning")
12+
case Error => JsString("Error")
13+
}
1314

1415
def reads(json: JsValue): JsResult[Severity] = {
1516
json match {
@@ -19,7 +20,9 @@ object Severity {
1920
case _ => JsError(Seq())
2021
}
2122
}
23+
2224
}
25+
2326
}
2427

2528
sealed trait Severity

api/src/main/scala/com.olegych.scastie.api/ConsoleOutput.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ sealed trait ConsoleOutput {
88
}
99

1010
object ConsoleOutput {
11+
1112
case class SbtOutput(output: ProcessOutput) extends ConsoleOutput {
1213
def show: String = s"sbt: ${output.line}"
1314
}
@@ -27,8 +28,7 @@ object ConsoleOutput {
2728

2829
def writes(output: ConsoleOutput): JsValue = {
2930
output match {
30-
case sbtOutput: SbtOutput =>
31-
formatSbtOutput.writes(sbtOutput) ++ JsObject(Seq("tpe" -> JsString("SbtOutput")))
31+
case sbtOutput: SbtOutput => formatSbtOutput.writes(sbtOutput) ++ JsObject(Seq("tpe" -> JsString("SbtOutput")))
3232
case userOutput: UserOutput =>
3333
formatUserOutput.writes(userOutput) ++ JsObject(Seq("tpe" -> JsString("UserOutput")))
3434
case scastieOutput: ScastieOutput =>
@@ -41,18 +41,18 @@ object ConsoleOutput {
4141
case obj: JsObject =>
4242
val vs = obj.value
4343
vs.get("tpe").orElse(vs.get("$type")) match {
44-
case Some(tpe) =>
45-
tpe match {
46-
case JsString("SbtOutput") => formatSbtOutput.reads(json)
47-
case JsString("UserOutput") => formatUserOutput.reads(json)
48-
case JsString("ScastieOutput") =>
49-
formatScastieOutput.reads(json)
50-
case _ => JsError(Seq())
44+
case Some(tpe) => tpe match {
45+
case JsString("SbtOutput") => formatSbtOutput.reads(json)
46+
case JsString("UserOutput") => formatUserOutput.reads(json)
47+
case JsString("ScastieOutput") => formatScastieOutput.reads(json)
48+
case _ => JsError(Seq())
5149
}
5250
case None => JsError(Seq())
5351
}
5452
case _ => JsError(Seq())
5553
}
5654
}
55+
5756
}
57+
5858
}

api/src/main/scala/com.olegych.scastie.api/Inputs.scala

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.olegych.scastie.api
22

3-
import play.api.libs.json._
43
import com.olegych.scastie.buildinfo.BuildInfo
5-
4+
import play.api.libs.json._
65
import System.{lineSeparator => nl}
76

87
sealed trait BaseInputs {
@@ -56,6 +55,7 @@ object Inputs {
5655
f
5756
)
5857
}
58+
5959
}
6060

6161
case class Inputs(
@@ -111,9 +111,11 @@ case class Inputs(
111111

112112
lazy val isDefault: Boolean = copy(code = "").withSavedConfig == Inputs.default.copy(code = "").withSavedConfig
113113

114-
def modifyConfig(inputs: Inputs => Inputs): Inputs = inputs(this).copy(sbtConfigSaved = None, sbtPluginsConfigSaved = None)
114+
def modifyConfig(inputs: Inputs => Inputs): Inputs =
115+
inputs(this).copy(sbtConfigSaved = None, sbtPluginsConfigSaved = None)
115116

116-
def withSavedConfig: Inputs = copy(sbtConfigSaved = Some(sbtConfigGenerated), sbtPluginsConfigSaved = Some(sbtPluginsConfigGenerated))
117+
def withSavedConfig: Inputs =
118+
copy(sbtConfigSaved = Some(sbtConfigGenerated), sbtPluginsConfigSaved = Some(sbtPluginsConfigGenerated))
117119

118120
def clearDependencies: Inputs = {
119121
modifyConfig {
@@ -146,9 +148,8 @@ case class Inputs(
146148
val newScalaDependency = scalaDependency.copy(version = version)
147149
val newLibraries = libraries.filterNot(_.matches(scalaDependency)) + newScalaDependency
148150
val newLibrariesFromList = librariesFromList.collect {
149-
case (l, p) if l.matches(scalaDependency) =>
150-
newScalaDependency -> p
151-
case (l, p) => l -> p
151+
case (l, p) if l.matches(scalaDependency) => newScalaDependency -> p
152+
case (l, p) => l -> p
152153
}
153154
modifyConfig {
154155
_.copy(
@@ -158,8 +159,7 @@ case class Inputs(
158159
}
159160
}
160161

161-
lazy val sbtConfig: String =
162-
mapToConfig(sbtConfigGenerated, sbtConfigExtra)
162+
lazy val sbtConfig: String = mapToConfig(sbtConfigGenerated, sbtConfigExtra)
163163

164164
lazy val sbtConfigGenerated: String = sbtConfigSaved.getOrElse {
165165
val targetConfig = target.sbtConfig
@@ -168,8 +168,7 @@ case class Inputs(
168168
if (target.hasWorksheetMode) target.runtimeDependency
169169
else None
170170

171-
val allLibraries =
172-
optionalTargetDependency.map(libraries + _).getOrElse(libraries)
171+
val allLibraries = optionalTargetDependency.map(libraries + _).getOrElse(libraries)
173172

174173
val librariesConfig =
175174
if (allLibraries.isEmpty) ""
@@ -191,31 +190,28 @@ case class Inputs(
191190
mapToConfig(targetConfig, librariesConfig)
192191
}
193192

194-
lazy val sbtPluginsConfig: String =
195-
mapToConfig(sbtPluginsConfigGenerated, sbtPluginsConfigExtra)
193+
lazy val sbtPluginsConfig: String = mapToConfig(sbtPluginsConfigGenerated, sbtPluginsConfigExtra)
196194

197195
lazy val sbtPluginsConfigGenerated: String = sbtPluginsConfigSaved.getOrElse {
198196
sbtPluginsConfig0(withSbtScastie = true)
199197
}
200198

201-
private def mapToConfig(parts: String*): String =
202-
parts.filter(_.nonEmpty).mkString("\n")
199+
private def mapToConfig(parts: String*): String = parts.filter(_.nonEmpty).mkString("\n")
203200

204201
private def sbtPluginsConfig0(withSbtScastie: Boolean): String = {
205202
val targetConfig = target.sbtPluginsConfig
206203

207204
val sbtScastie =
208-
if (withSbtScastie)
209-
s"""addSbtPlugin("org.scastie" % "sbt-scastie" % "${BuildInfo.versionRuntime}")"""
205+
if (withSbtScastie) s"""addSbtPlugin("org.scastie" % "sbt-scastie" % "${BuildInfo.versionRuntime}")"""
210206
else ""
211207

212208
mapToConfig(targetConfig, sbtScastie)
213209
}
210+
214211
}
215212

216213
object EditInputs {
217-
implicit val formatEditInputs: OFormat[EditInputs] =
218-
Json.format[EditInputs]
214+
implicit val formatEditInputs: OFormat[EditInputs] = Json.format[EditInputs]
219215
}
220216

221217
case class EditInputs(snippetId: SnippetId, inputs: Inputs)

0 commit comments

Comments
 (0)