Skip to content

Commit 1427703

Browse files
authored
Merge pull request #119 from xuwei-k/update-scalafmt-version
2 parents 84ec81f + 6ee8152 commit 1427703

25 files changed

+197
-163
lines changed

.scalafmt.conf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
version = 2.3.2
2-
edition = 2019-10
1+
version = 3.9.9
2+
runner.dialect = scala213
33
maxColumn = 100
44
project.git = true
55
lineEndings = preserve
66

77
# https://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style.
88
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala
9-
docstrings = JavaDoc
9+
docstrings.style = Asterisk
10+
docstrings.wrap = false
1011

1112
# This also seems more idiomatic to include whitespace in import x.{ yyy }
1213
spaces.inImportCurlyBraces = true
@@ -17,6 +18,6 @@ align.openParenCallSite = false
1718
align.openParenDefnSite = false
1819

1920
# For better code clarity
20-
danglingParentheses = true
21+
danglingParentheses.preset = true
2122

2223
trailingCommas = preserve

launcher-implementation/src/main/scala/xsbt/boot/Boot.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ object Boot {
7979
catch {
8080
case b: BootException => errorAndExit(b.toString)
8181
case r: xsbti.RetrieveException => errorAndExit(r.getMessage)
82-
case r: xsbti.FullReload => Some(new LauncherArguments(r.arguments.toList, false, false))
83-
case e: Throwable =>
82+
case r: xsbti.FullReload => Some(new LauncherArguments(r.arguments.toList, false, false))
83+
case e: Throwable =>
8484
e.printStackTrace
8585
errorAndExit(Pre.prefixError(e.toString))
8686
}

launcher-implementation/src/main/scala/xsbt/boot/BootConfiguration.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ private[boot] object BootConfiguration {
2525

2626
val SbtOrg = "org.scala-sbt"
2727

28-
/** The Ivy conflict manager to use for updating.*/
28+
/** The Ivy conflict manager to use for updating. */
2929
val ConflictManagerName = "latest-revision"
3030

31-
/** The name of the local Ivy repository, which is used when compiling sbt from source.*/
31+
/** The name of the local Ivy repository, which is used when compiling sbt from source. */
3232
val LocalIvyName = "local"
3333

34-
/** The pattern used for the local Ivy repository, which is used when compiling sbt from source.*/
34+
/** The pattern used for the local Ivy repository, which is used when compiling sbt from source. */
3535
val LocalPattern = "[organisation]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]"
3636

37-
/** The artifact pattern used for the local Ivy repository.*/
37+
/** The artifact pattern used for the local Ivy repository. */
3838
def LocalArtifactPattern = LocalPattern
3939

40-
/** The Ivy pattern used for the local Ivy repository.*/
40+
/** The Ivy pattern used for the local Ivy repository. */
4141
def LocalIvyPattern = LocalPattern
4242

4343
final val FjbgPackage = "ch.epfl.lamp.fjbg."
4444

4545
/** The class name prefix used to hide the Scala classes used by this loader from the application */
4646
final val ScalaPackage = "scala."
4747

48-
/** The class name prefix used to hide the Ivy classes used by this loader from the application*/
48+
/** The class name prefix used to hide the Ivy classes used by this loader from the application */
4949
final val IvyPackage = "org.apache.ivy."
5050

5151
/**
@@ -92,11 +92,11 @@ private[boot] object BootConfiguration {
9292

9393
val ScalaVersionPrefix = "scala-"
9494

95-
/** The name of the directory to retrieve the application and its dependencies to.*/
95+
/** The name of the directory to retrieve the application and its dependencies to. */
9696
def appDirectoryName(appID: xsbti.ApplicationID, sep: String) =
9797
appID.groupID + sep + appID.name + sep + appID.version
9898

99-
/** The name of the directory in the boot directory to put all jars for the given version of scala in.*/
99+
/** The name of the directory in the boot directory to put all jars for the given version of scala in. */
100100
def baseDirectoryName(scalaOrg: String, scalaVersion: Option[String]) = scalaVersion match {
101101
case None => "other"
102102
case Some(sv) => (if (scalaOrg == ScalaOrg) "" else scalaOrg + ".") + ScalaVersionPrefix + sv

launcher-implementation/src/main/scala/xsbt/boot/Configuration.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ object Configuration {
4747
}
4848
def setProperty(head: String): Unit = {
4949
head.split("=", 2) match {
50-
case Array("") => Console.err.println(s"[warn] [launcher] invalid system property '$head'")
51-
case Array(key) => sys.props += key -> ""
50+
case Array("") => Console.err.println(s"[warn] [launcher] invalid system property '$head'")
51+
case Array(key) => sys.props += key -> ""
5252
case Array(key, value) => sys.props += key -> value
5353
case _ => ()
5454
}
@@ -67,10 +67,12 @@ object Configuration {
6767
def configurationFromFile(path: String, baseDirectory: File): URL = {
6868
val pathURI = filePathURI(path)
6969
def resolve(against: URI): Option[URL] = {
70-
val resolved = against.resolve(pathURI) // variant that accepts String doesn't properly escape (#725)
71-
val exists = try {
72-
(new File(resolved)).exists
73-
} catch { case _: IllegalArgumentException => false }
70+
val resolved =
71+
against.resolve(pathURI) // variant that accepts String doesn't properly escape (#725)
72+
val exists =
73+
try {
74+
(new File(resolved)).exists
75+
} catch { case _: IllegalArgumentException => false }
7476
if (exists) Some(resolved.toURL) else None
7577
}
7678
val against = resolveAgainst(baseDirectory)
@@ -110,7 +112,8 @@ object Configuration {
110112
if (m.matches())
111113
subPartsIndices flatMap { is =>
112114
fullMatchOnly(is.map(m.group))
113-
} else
115+
}
116+
else
114117
noMatchParts
115118
}
116119
def noMatchParts: List[String] = DefaultVersionPart :: fallbackParts

launcher-implementation/src/main/scala/xsbt/boot/ConfigurationParser.scala

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ class ConfigurationParser {
136136

137137
def toFiles(paths: List[String]): List[File] = paths.map(toFile)
138138
def toFile(path: String): File =
139-
new File(substituteVariables(path).replace('/', File.separatorChar)) // if the path is relative, it will be resolved by Launch later
139+
new File(
140+
substituteVariables(path).replace('/', File.separatorChar)
141+
) // if the path is relative, it will be resolved by Launch later
140142
def file(map: LabelMap, name: String, default: File): (File, LabelMap) =
141143
(orElse(getOrNone(map, name).map(toFile), default), map - name)
142144
def optfile(map: LabelMap, name: String): (Option[File], LabelMap) =
@@ -213,14 +215,15 @@ class ConfigurationParser {
213215
m.toList.map {
214216
case (key, None) => Predefined(key)
215217
case (key, Some(BootOnly)) => Predefined(key, true)
216-
case (key, Some(value)) =>
218+
case (key, Some(value)) =>
217219
val r = trim(substituteVariables(value).split(",", 8))
218-
val url = try {
219-
new URL(r(0))
220-
} catch {
221-
case e: MalformedURLException =>
222-
Pre.error("invalid URL specified for '" + key + "': " + e.getMessage)
223-
}
220+
val url =
221+
try {
222+
new URL(r(0))
223+
} catch {
224+
case e: MalformedURLException =>
225+
Pre.error("invalid URL specified for '" + key + "': " + e.getMessage)
226+
}
224227
val (optionPart, patterns) = r.tail.partition(OptSet.contains(_))
225228
val options = (
226229
optionPart.contains(BootOnly),
@@ -270,7 +273,7 @@ class ConfigurationParser {
270273
}
271274
def parsePropertyDefinition(name: String)(value: String) = value.split("=", 2) match {
272275
case Array(mode, value) => (mode, parsePropertyValue(name, value)(defineProperty(name)))
273-
case x => Pre.error("invalid property definition '" + x + "' for property '" + name + "'")
276+
case x => Pre.error("invalid property definition '" + x + "' for property '" + name + "'")
274277
}
275278
def defineProperty(
276279
name: String
@@ -280,7 +283,8 @@ class ConfigurationParser {
280283
case "set" => new SetProperty(requiredArg)
281284
case _ => Pre.error("unknown action '" + action + "' for property '" + name + "'")
282285
}
283-
private[this] lazy val propertyPattern = Pattern.compile("""(.+)\((.*)\)(?:\[(.*)\])?""") // examples: prompt(Version)[1.0] or set(1.0)
286+
private[this] lazy val propertyPattern =
287+
Pattern.compile("""(.+)\((.*)\)(?:\[(.*)\])?""") // examples: prompt(Version)[1.0] or set(1.0)
284288
def parsePropertyValue[T](name: String, definition: String)(
285289
f: (String, String, Option[String]) => T
286290
): T = {

launcher-implementation/src/main/scala/xsbt/boot/CoursierUpdate.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CousierUpdate(config: UpdateConfiguration) {
5353
.orElse(sys.env.get("COURSIER_CACHE").map(absoluteFile))
5454
.orElse(sys.props.get("coursier.cache").map(absoluteFile)) match {
5555
case Some(dir) => dir
56-
case _ =>
56+
case _ =>
5757
if (isWindows) windowsCacheDirectory
5858
else CacheDefaults.location
5959
}
@@ -128,7 +128,7 @@ class CousierUpdate(config: UpdateConfiguration) {
128128
case u: UpdateApp =>
129129
val app = u.id
130130
val resolvedName = (app.crossVersioned, scalaVersion) match {
131-
case (xsbti.CrossValue.Full, Some(sv)) => app.getName + "_" + sv
131+
case (xsbti.CrossValue.Full, Some(sv)) => app.getName + "_" + sv
132132
case (xsbti.CrossValue.Binary, Some(sv)) =>
133133
app.getName + "_" + CrossVersionUtil.binaryScalaVersion(sv)
134134
case _ => app.getName
@@ -273,9 +273,9 @@ class CousierUpdate(config: UpdateConfiguration) {
273273
def bootCredentials = {
274274
val optionProps =
275275
Option(System.getProperty("sbt.boot.credentials")) orElse
276-
Option(System.getenv("SBT_CREDENTIALS")) map (
277-
path => Pre.readProperties(new File(substituteTilde(path)))
278-
)
276+
Option(System.getenv("SBT_CREDENTIALS")) map (path =>
277+
Pre.readProperties(new File(substituteTilde(path)))
278+
)
279279
def extractCredentials(
280280
keys: (String, String, String, String)
281281
)(props: Properties): Option[DirectCredentials] = {
@@ -348,7 +348,7 @@ class CousierUpdate(config: UpdateConfiguration) {
348348
MavenRepository(root)
349349
}
350350

351-
/** Uses the pattern defined in BuildConfiguration to download sbt from Google code.*/
351+
/** Uses the pattern defined in BuildConfiguration to download sbt from Google code. */
352352
private def ivyRepository(
353353
id: String,
354354
base: String,

launcher-implementation/src/main/scala/xsbt/boot/Create.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ object Initialize {
2121
spec: List[AppProperty]
2222
): Unit = {
2323
readLine(promptCreate + " (y/N" + (if (enableQuick) "/s" else "") + ") ") match {
24-
case None => declined("")
24+
case None => declined("")
2525
case Some(line) =>
2626
line.toLowerCase(Locale.ENGLISH) match {
2727
case "y" | "yes" => process(file, spec, selectCreate)
2828
case "s" => process(file, spec, selectQuick)
2929
case "n" | "no" | "" => declined("")
30-
case x =>
30+
case x =>
3131
Console.err.println(" '" + x + "' not understood.")
3232
create(file, promptCreate, enableQuick, spec)
3333
}
@@ -43,20 +43,22 @@ object Initialize {
4343
): Unit = {
4444
val properties = readProperties(file)
4545
val uninitialized =
46-
for (property <- appProperties; init <- select(property)
47-
if properties.getProperty(property.name) == null)
46+
for (
47+
property <- appProperties; init <- select(property)
48+
if properties.getProperty(property.name) == null
49+
)
4850
yield initialize(properties, property.name, init)
4951
if (!uninitialized.isEmpty) writeProperties(properties, file, "")
5052
}
5153

5254
@nowarn
5355
def initialize(properties: Properties, name: String, init: PropertyInit): Unit = {
5456
init match {
55-
case set: SetProperty => properties.setProperty(name, set.value)
57+
case set: SetProperty => properties.setProperty(name, set.value)
5658
case prompt: PromptProperty =>
5759
def noValue = declined("no value provided for " + prompt.label)
5860
readLine(prompt.label + prompt.default.toList.map(" [" + _ + "]").mkString + ": ") match {
59-
case None => noValue
61+
case None => noValue
6062
case Some(line) =>
6163
val value =
6264
if (isEmpty(line)) orElse(prompt.default, noValue)

launcher-implementation/src/main/scala/xsbt/boot/Enumeration.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ class Enumeration extends Serializable {
1212
val c = getClass
1313
val correspondingFields = ListMap(c.getDeclaredFields.map(f => (f.getName, f)): _*)
1414
c.getMethods.toList flatMap { method =>
15-
if (method.getParameterTypes.length == 0 && classOf[Value].isAssignableFrom(
16-
method.getReturnType
17-
)) {
18-
for (field <- correspondingFields.get(method.getName)
19-
if field.getType == method.getReturnType) yield method.invoke(this).asInstanceOf[Value]
15+
if (
16+
method.getParameterTypes.length == 0 && classOf[Value].isAssignableFrom(
17+
method.getReturnType
18+
)
19+
) {
20+
for (
21+
field <- correspondingFields.get(method.getName)
22+
if field.getType == method.getReturnType
23+
) yield method.invoke(this).asInstanceOf[Value]
2024
} else
2125
Nil
2226
}

launcher-implementation/src/main/scala/xsbt/boot/FilteredLoader.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ private[boot] final class BootFilteredLoader(parent: ClassLoader) extends ClassL
1414
@throws(classOf[ClassNotFoundException])
1515
override final def loadClass(className: String, resolve: Boolean): Class[_] = {
1616
// note that we allow xsbti.*
17-
if (className.startsWith(ScalaPackage) || className.startsWith(IvyPackage) || className
18-
.startsWith(SbtBootPackage) || className.startsWith(FjbgPackage))
17+
if (
18+
className.startsWith(ScalaPackage) || className.startsWith(IvyPackage) || className
19+
.startsWith(SbtBootPackage) || className.startsWith(FjbgPackage)
20+
)
1921
throw new ClassNotFoundException(className)
2022
else
2123
super.loadClass(className, resolve)

launcher-implementation/src/main/scala/xsbt/boot/Find.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class Find(config: LaunchConfiguration) {
2323
search.tpe match {
2424
case Search.RootFirst => fromRoot.headOption
2525
case Search.Nearest => fromRoot.lastOption
26-
case Search.Only =>
26+
case Search.Only =>
2727
if (hasProject(current))
2828
Some(current)
2929
else
3030
fromRoot match {
3131
case Nil => Some(current)
3232
case head :: Nil => Some(head)
33-
case xs =>
33+
case xs =>
3434
Console.err.println(
3535
"[error] [launcher] search method is 'only' and multiple ancestor directories match:\n\t" + fromRoot
3636
.mkString("\n\t")
@@ -55,7 +55,9 @@ object ResolvePaths {
5555
def apply(baseDirectory: File, f: File): File =
5656
if (f.isAbsolute) f
5757
else {
58-
assert(baseDirectory.isDirectory) // if base directory is not a directory, URI.resolve will not work properly
58+
assert(
59+
baseDirectory.isDirectory
60+
) // if base directory is not a directory, URI.resolve will not work properly
5961
val uri = new URI(null, null, f.getPath, null)
6062
new File(baseDirectory.toURI.resolve(uri))
6163
}

0 commit comments

Comments
 (0)