Skip to content

Commit 4b1d7f3

Browse files
committed
Apply scalafmt
1 parent 4fcdd19 commit 4b1d7f3

File tree

4 files changed

+156
-67
lines changed

4 files changed

+156
-67
lines changed

cli/src/org/scalajs/cli/Scalajsld.scala

Lines changed: 92 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
** |/____/ **
77
\* */
88

9-
109
package org.scalajs.cli
1110

1211
import org.scalajs.ir.ScalaJSVersions
@@ -52,7 +51,10 @@ object Scalajsld {
5251
logLevel: Level = Level.Info
5352
)
5453

55-
private def moduleInitializer(s: String, hasArgs: Boolean): ModuleInitializer = {
54+
private def moduleInitializer(
55+
s: String,
56+
hasArgs: Boolean
57+
): ModuleInitializer = {
5658
val lastDot = s.lastIndexOf('.')
5759
if (lastDot < 0)
5860
throw new IllegalArgumentException(s"$s is not a valid main method")
@@ -67,21 +69,35 @@ object Scalajsld {
6769
private implicit object ModuleKindRead extends scopt.Read[ModuleKind] {
6870
val arity = 1
6971
val reads = { (s: String) =>
70-
ModuleKind.All.find(_.toString() == s).getOrElse(
71-
throw new IllegalArgumentException(s"$s is not a valid module kind"))
72+
ModuleKind.All
73+
.find(_.toString() == s)
74+
.getOrElse(
75+
throw new IllegalArgumentException(s"$s is not a valid module kind")
76+
)
7277
}
7378
}
7479

7580
private object ModuleSplitStyleRead {
76-
val All = List(ModuleSplitStyle.FewestModules.toString, ModuleSplitStyle.SmallestModules.toString, "SmallModulesFor")
81+
val All = List(
82+
ModuleSplitStyle.FewestModules.toString,
83+
ModuleSplitStyle.SmallestModules.toString,
84+
"SmallModulesFor"
85+
)
7786

78-
def moduleSplitStyleRead(splitStyle: String, modulePackages: Seq[String]): ModuleSplitStyle =
87+
def moduleSplitStyleRead(
88+
splitStyle: String,
89+
modulePackages: Seq[String]
90+
): ModuleSplitStyle =
7991
try {
80-
(new ModuleSplitStyleParser).parse(splitStyle, modulePackages.toArray).underlying
81-
}
82-
catch {
92+
(new ModuleSplitStyleParser)
93+
.parse(splitStyle, modulePackages.toArray)
94+
.underlying
95+
} catch {
8396
case e: NoClassDefFoundError =>
84-
throw new IllegalArgumentException(s"$splitStyle is not a valid module split style", e.getCause)
97+
throw new IllegalArgumentException(
98+
s"$splitStyle is not a valid module split style",
99+
e.getCause
100+
)
85101
}
86102
}
87103

@@ -128,14 +144,22 @@ object Scalajsld {
128144
.text("Don't optimize code")
129145
opt[String]("moduleSplitStyle")
130146
.action { (x, c) => c.copy(moduleSplitStyle = x) }
131-
.text("Module splitting style " + ModuleSplitStyleRead.All.mkString("(", ", ", ")"))
147+
.text(
148+
"Module splitting style " + ModuleSplitStyleRead.All
149+
.mkString("(", ", ", ")")
150+
)
132151
opt[Seq[String]]("smallModuleForPackages")
133152
.valueName("<package1>,<package2>...")
134153
.action((x, c) => c.copy(smallModuleForPackages = x))
135-
.text("Create as many small modules as possible for the classes in the passed packages and their subpackages.")
154+
.text(
155+
"Create as many small modules as possible for the classes in the passed packages and their subpackages."
156+
)
136157
opt[String]("jsFilePattern")
137-
.action { (x, c) => c.copy(outputPatterns = OutputPatterns.fromJSFile(x)) }
138-
.text("Pattern for JS file names (default: `%s.js`). " +
158+
.action { (x, c) =>
159+
c.copy(outputPatterns = OutputPatterns.fromJSFile(x))
160+
}
161+
.text(
162+
"Pattern for JS file names (default: `%s.js`). " +
139163
"Expects a printf-style pattern with a single placeholder for the module ID. " +
140164
"A typical use case is changing the file extension, e.g. `%.mjs` for Node.js modules."
141165
)
@@ -154,15 +178,21 @@ object Scalajsld {
154178
.action { (_, c) => c.copy(sourceMap = true) }
155179
.text("Produce a source map for the produced code")
156180
opt[Unit]("compliantAsInstanceOfs")
157-
.action { (_, c) => c.copy(semantics =
158-
c.semantics.withAsInstanceOfs(Compliant))
181+
.action { (_, c) =>
182+
c.copy(semantics = c.semantics.withAsInstanceOfs(Compliant))
159183
}
160184
.text("Use compliant asInstanceOfs")
161185
opt[Unit]("es2015")
162-
.action { (_, c) => c.copy(esFeatures = c.esFeatures.withESVersion(ESVersion.ES2015)) }
186+
.action { (_, c) =>
187+
c.copy(esFeatures = c.esFeatures.withESVersion(ESVersion.ES2015))
188+
}
163189
.text("Use ECMAScript 2015")
164190
opt[String]("esVersion")
165-
.action { (esV, c) => c.copy(esFeatures = c.esFeatures.withESVersion(EsVersionParser.parse(esV))) }
191+
.action { (esV, c) =>
192+
c.copy(esFeatures =
193+
c.esFeatures.withESVersion(EsVersionParser.parse(esV))
194+
)
195+
}
166196
.text("EsVersion " + EsVersionParser.All.mkString("(", ", ", ")"))
167197
opt[ModuleKind]('k', "moduleKind")
168198
.action { (kind, c) => c.copy(moduleKind = kind) }
@@ -173,19 +203,25 @@ object Scalajsld {
173203
opt[File]('r', "relativizeSourceMap")
174204
.valueName("<path>")
175205
.action { (x, c) => c.copy(relativizeSourceMap = Some(x.toURI)) }
176-
.text("Relativize source map with respect to given path (meaningful with -s)")
206+
.text(
207+
"Relativize source map with respect to given path (meaningful with -s)"
208+
)
177209
opt[Unit]("noStdlib")
178210
.action { (_, c) => c.copy(stdLib = Nil) }
179211
.text("Don't automatically include Scala.js standard library")
180212
opt[String]("stdlib")
181213
.valueName("<scala.js stdlib jar>")
182214
.hidden()
183-
.action { (x, c) => c.copy(stdLib = x.split(File.pathSeparator).map(new File(_)).toSeq) }
184-
.text("Location of Scala.js standard libarary. This is set by the " +
215+
.action { (x, c) =>
216+
c.copy(stdLib = x.split(File.pathSeparator).map(new File(_)).toSeq)
217+
}
218+
.text(
219+
"Location of Scala.js standard libarary. This is set by the " +
185220
"runner script and automatically prepended to the classpath. " +
186-
"Use -n to not include it.")
221+
"Use -n to not include it."
222+
)
187223
opt[String]("jsHeader")
188-
.action { (jsHeader, c) => c.copy(jsHeader = jsHeader)}
224+
.action { (jsHeader, c) => c.copy(jsHeader = jsHeader) }
189225
.text("A header that will be added at the top of generated .js files")
190226
opt[Unit]('d', "debug")
191227
.action { (_, c) => c.copy(logLevel = Level.Debug) }
@@ -205,8 +241,10 @@ object Scalajsld {
205241
.text("prints this usage text")
206242
checkConfig { c =>
207243
if (c.output.isDefined) {
208-
reportWarning("using a single file as output (--output) is deprecated since Scala.js 1.3.0." +
209-
" Use --outputDir instead.")
244+
reportWarning(
245+
"using a single file as output (--output) is deprecated since Scala.js 1.3.0." +
246+
" Use --outputDir instead."
247+
)
210248
}
211249

212250
if (c.outputDir.isDefined == c.output.isDefined)
@@ -225,7 +263,10 @@ object Scalajsld {
225263
val semantics =
226264
if (options.fullOpt) options.semantics.optimized
227265
else options.semantics
228-
val moduleSplitStyle = ModuleSplitStyleRead.moduleSplitStyleRead(options.moduleSplitStyle, options.smallModuleForPackages)
266+
val moduleSplitStyle = ModuleSplitStyleRead.moduleSplitStyleRead(
267+
options.moduleSplitStyle,
268+
options.smallModuleForPackages
269+
)
229270

230271
val config = StandardConfig()
231272
.withSemantics(semantics)
@@ -253,10 +294,24 @@ object Scalajsld {
253294
.flatMap { irFiles =>
254295
(options.output, options.outputDir) match {
255296
case (Some(jsFile), None) =>
256-
(DeprecatedLinkerAPI: DeprecatedLinkerAPI).link(linker, irFiles.toList, moduleInitializers, jsFile, logger)
297+
(DeprecatedLinkerAPI: DeprecatedLinkerAPI).link(
298+
linker,
299+
irFiles.toList,
300+
moduleInitializers,
301+
jsFile,
302+
logger
303+
)
257304
case (None, Some(outputDir)) =>
258-
linker.link(irFiles, moduleInitializers, PathOutputDirectory(outputDir.toPath()), logger)
259-
case _ => throw new AssertionError("Either output or outputDir have to be defined.")
305+
linker.link(
306+
irFiles,
307+
moduleInitializers,
308+
PathOutputDirectory(outputDir.toPath()),
309+
logger
310+
)
311+
case _ =>
312+
throw new AssertionError(
313+
"Either output or outputDir have to be defined."
314+
)
260315
}
261316
}
262317
Await.result(result, Duration.Inf)
@@ -265,22 +320,26 @@ object Scalajsld {
265320

266321
// Covers deprecated api with not deprecated method. Suppresses warning.
267322
private abstract class DeprecatedLinkerAPI {
268-
def link(linker: Linker,
323+
def link(
324+
linker: Linker,
269325
irFiles: Seq[IRFile],
270326
moduleInitializers: Seq[ModuleInitializer],
271327
linkerOutputFile: File,
272-
logger: Logger): Future[Unit]
328+
logger: Logger
329+
): Future[Unit]
273330
}
274331

275332
private object DeprecatedLinkerAPI extends DeprecatedLinkerAPI {
276333
def apply(): DeprecatedLinkerAPI = this
277334

278335
@deprecated("Deprecate to silence warnings", "never/always")
279-
def link(linker: Linker,
336+
def link(
337+
linker: Linker,
280338
irFiles: Seq[IRFile],
281339
moduleInitializers: Seq[ModuleInitializer],
282340
linkerOutputFile: File,
283-
logger: Logger): Future[Unit] = {
341+
logger: Logger
342+
): Future[Unit] = {
284343
val js = linkerOutputFile.toPath()
285344
val sm = js.resolveSibling(js.getFileName().toString() + ".map")
286345

cli/src/org/scalajs/cli/Scalajsp.scala

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
** |/____/ **
77
\* */
88

9-
109
package org.scalajs.cli
1110

1211
import org.scalajs.ir.ScalaJSVersions
@@ -49,7 +48,9 @@ object Scalajsp {
4948
.action { (x, c) => c.copy(jar = Some(x)) }
5049
.text("Read *.sjsir file(s) from the given JAR.")
5150
opt[Unit]('s', "supported")
52-
.action { (_,_) => printSupported(); exit(0) }
51+
.action { (_, _) =>
52+
printSupported(); exit(0)
53+
}
5354
.text("Show supported Scala.js IR versions")
5455
version("version")
5556
.abbr("v")
@@ -65,11 +66,13 @@ object Scalajsp {
6566
options <- parser.parse(args, Options())
6667
fileName <- options.fileNames
6768
} {
68-
val vfile = options.jar.map { jar =>
69-
readFromJar(jar, fileName)
70-
}.getOrElse {
71-
readFromFile(fileName)
72-
}
69+
val vfile = options.jar
70+
.map { jar =>
71+
readFromJar(jar, fileName)
72+
}
73+
.getOrElse {
74+
readFromFile(fileName)
75+
}
7376

7477
displayFileContent(Await.result(vfile, Duration.Inf), options)
7578
}
@@ -116,19 +119,25 @@ object Scalajsp {
116119
*/
117120

118121
def findRequestedClass(sjsirFiles: Seq[IRFile]): Future[IRFile] = {
119-
Future.traverse(sjsirFiles) { irFile =>
120-
val ir = IRFileImpl.fromIRFile(irFile)
121-
ir.entryPointsInfo.map { i =>
122-
if (i.className.nameString == name) Success(Some(ir))
123-
else Success(None)
124-
}.recover { case t => Failure(t) }
125-
}.map { irs =>
126-
irs.collectFirst {
127-
case Success(Some(f)) => f
128-
}.getOrElse {
129-
fail(s"No such class in jar: $name")
122+
Future
123+
.traverse(sjsirFiles) { irFile =>
124+
val ir = IRFileImpl.fromIRFile(irFile)
125+
ir.entryPointsInfo
126+
.map { i =>
127+
if (i.className.nameString == name) Success(Some(ir))
128+
else Success(None)
129+
}
130+
.recover { case t => Failure(t) }
131+
}
132+
.map { irs =>
133+
irs
134+
.collectFirst { case Success(Some(f)) =>
135+
f
136+
}
137+
.getOrElse {
138+
fail(s"No such class in jar: $name")
139+
}
130140
}
131-
}
132141
}
133142

134143
val cache = StandardImpl.irFileCache().newCache

cli/src/org/scalajs/cli/internal/EsVersionParser.scala

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,29 @@ import java.util.Locale
77
object EsVersionParser {
88
def parse(esVersion: String): ESVersion =
99
esVersion.trim.toLowerCase(Locale.ROOT) match {
10-
case "es5_1" => ESVersion.ES5_1
11-
case "es2015" => ESVersion.ES2015
12-
case "es2016" => ESVersion.ES2016
13-
case "es2017" => ESVersion.ES2017
14-
case "es2018" => ESVersion.ES2018
15-
case "es2019" => ESVersion.ES2019
16-
case "es2020" => ESVersion.ES2020
17-
case "es2021" => ESVersion.ES2021
18-
case unknown => throw new IllegalArgumentException(s"Warning: unrecognized argument: $unknown for --esVersion parameter")
19-
}
10+
case "es5_1" => ESVersion.ES5_1
11+
case "es2015" => ESVersion.ES2015
12+
case "es2016" => ESVersion.ES2016
13+
case "es2017" => ESVersion.ES2017
14+
case "es2018" => ESVersion.ES2018
15+
case "es2019" => ESVersion.ES2019
16+
case "es2020" => ESVersion.ES2020
17+
case "es2021" => ESVersion.ES2021
18+
case unknown =>
19+
throw new IllegalArgumentException(
20+
s"Warning: unrecognized argument: $unknown for --esVersion parameter"
21+
)
22+
}
2023

2124
val All: List[ESVersion] =
22-
List(ESVersion.ES5_1, ESVersion.ES2015, ESVersion.ES2016, ESVersion.ES2017, ESVersion.ES2018, ESVersion.ES2019, ESVersion.ES2020, ESVersion.ES2021)
25+
List(
26+
ESVersion.ES5_1,
27+
ESVersion.ES2015,
28+
ESVersion.ES2016,
29+
ESVersion.ES2017,
30+
ESVersion.ES2018,
31+
ESVersion.ES2019,
32+
ESVersion.ES2020,
33+
ESVersion.ES2021
34+
)
2335
}

cli/src/org/scalajs/cli/internal/ModuleSplitStyleParser.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@ import org.scalajs.linker.interface.{ModuleSplitStyle => ActualModuleSplitStyle}
44

55
// class rather than object, as that's easier to substitute from native-image
66
class ModuleSplitStyleParser {
7-
def parse(splitStyle: String, modulePackages: Array[String]): ModuleSplitStyle =
7+
def parse(
8+
splitStyle: String,
9+
modulePackages: Array[String]
10+
): ModuleSplitStyle =
811
if (splitStyle == ActualModuleSplitStyle.FewestModules.toString)
912
ModuleSplitStyle(ActualModuleSplitStyle.FewestModules)
1013
else if (splitStyle == ActualModuleSplitStyle.SmallestModules.toString)
1114
ModuleSplitStyle(ActualModuleSplitStyle.SmallestModules)
1215
else if (splitStyle == ActualModuleSplitStyle.SmallModulesFor.toString) {
1316
if (modulePackages.isEmpty)
14-
throw new IllegalArgumentException(s"SmallModuleFor style must have at least one package. To define it pass `--smallModuleForPackages` parameter.")
15-
ModuleSplitStyle(ActualModuleSplitStyle.SmallModulesFor(modulePackages.toList))
17+
throw new IllegalArgumentException(
18+
s"SmallModuleFor style must have at least one package. To define it pass `--smallModuleForPackages` parameter."
19+
)
20+
ModuleSplitStyle(
21+
ActualModuleSplitStyle.SmallModulesFor(modulePackages.toList)
22+
)
1623
} else
17-
throw new IllegalArgumentException(s"$splitStyle is not a valid module split style")
24+
throw new IllegalArgumentException(
25+
s"$splitStyle is not a valid module split style"
26+
)
1827
}

0 commit comments

Comments
 (0)