Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 42c8a1f

Browse files
authored
Reformat with the latest scalafmt. (#85)
1 parent b930271 commit 42c8a1f

Some content is hidden

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

51 files changed

+567
-651
lines changed

.scalafmt.conf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
version = "2.6.4"
32
align = some
43
align {
@@ -17,10 +16,9 @@ align {
1716
assumeStandardLibraryStripMargin = true
1817
continuationIndent.defnSite = 2
1918
continuationIndent.callSite = 2
20-
danglingParentheses = true
2119
docstrings = JavaDoc
22-
indentOperator = spray
2320
maxColumn = 110
21+
newlines.implicitParamListModifierPrefer = before
2422
project {
2523
git = true
2624
excludeFilters = ["target"]

src/main/scala/org/scalastyle/Checker.scala

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ case class Lines(lines: Array[Line], lastChar: Char) {
4343

4444
lines.foreach { l =>
4545
i = i + 1
46-
if (position >= l.start && position < l.end) {
46+
if (position >= l.start && position < l.end)
4747
return Some((l, i))
48-
}
4948
}
5049

5150
None
@@ -78,7 +77,7 @@ class ScalastyleChecker[T <: FileSpec](classLoader: Option[ClassLoader] = None)
7877
StartWork() :: files
7978
.flatMap(file =>
8079
StartFile(file) :: checkerUtils.verifyFile(configuration, checks, file) :::
81-
List(EndFile(file))
80+
List(EndFile(file))
8281
)
8382
.toList ::: List(EndWork())
8483
}
@@ -131,17 +130,17 @@ class CheckerUtils(classLoader: Option[ClassLoader] = None) {
131130
file: T,
132131
source: String
133132
): List[Message[T]] = {
134-
if (source.isEmpty) {
133+
if (source.isEmpty)
135134
Nil
136-
} else {
135+
else {
137136
val lines = Checker.parseLines(source)
138137
val scalariformAst = parseScalariform(source)
139138

140-
val commentFilters = if (configuration.commentFilter) {
141-
CommentFilter.findCommentFilters(scalariformAst.comments, lines)
142-
} else {
143-
Nil
144-
}
139+
val commentFilters =
140+
if (configuration.commentFilter)
141+
CommentFilter.findCommentFilters(scalariformAst.comments, lines)
142+
else
143+
Nil
145144

146145
classes
147146
.flatMap(cc => newInstance(cc.className, cc.level, cc.parameters, cc.customMessage, cc.customId))
@@ -188,13 +187,12 @@ class CheckerUtils(classLoader: Option[ClassLoader] = None) {
188187
def readFile(file: String, encoding: Option[String])(implicit codec: Codec): String = {
189188
@tailrec
190189
def readFileWithEncoding(file: String, encodings: List[String]): Option[String] = {
191-
if (encodings.isEmpty) {
190+
if (encodings.isEmpty)
192191
None
193-
} else {
192+
else {
194193
val encoding = encodings.head
195-
try {
196-
Some(Source.fromFile(file)(encoding).mkString)
197-
} catch {
194+
try Some(Source.fromFile(file)(encoding).mkString)
195+
catch {
198196
case _: MalformedInputException =>
199197
// printxxln("caught MalFormedInputException with " + (if (encoding.isDefined) encoding.get else "default (" + codec.charSet + ")") + " encoding")
200198
readFileWithEncoding(file, encodings.tail)

src/main/scala/org/scalastyle/CommentFilter.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,21 @@ object CommentFilter {
6767

6868
it.foreach { ci =>
6969
(inMap.getOrElse(ci.id, false), ci.off) match {
70-
case (true, false) => { // off then on, add a new CommentFilter
70+
case (true, false) => // off then on, add a new CommentFilter
7171
list += CommentFilter(ci.id, start.getOrElse(ci.id, None), lines.toLineColumn(ci.position))
7272
inMap.put(ci.id, false)
7373
start.remove(ci.id)
74-
}
7574
case (true, true) => // off then off, do nothing
7675
case (false, false) => // on then on, do nothing
77-
case (false, true) => { // on then off, reset start
76+
case (false, true) => // on then off, reset start
7877
start.put(ci.id, lines.toLineColumn(ci.position))
7978
inMap.put(ci.id, true)
80-
}
8179
}
8280
}
8381

8482
inMap.foreach { e =>
85-
if (e._2) {
83+
if (e._2)
8684
list += CommentFilter(e._1, start.getOrElse(e._1, None), None)
87-
}
8885
}
8986

9087
list.toList
@@ -100,9 +97,9 @@ object CommentFilter {
10097
private def idMatches(key: String)(cf: CommentFilter) = cf.id.isEmpty || cf.id.get == key
10198

10299
private def filterApplies[T <: FileSpec](se: StyleError[_])(cf: CommentFilter): Boolean = {
103-
if (se.lineNumber.isEmpty) {
100+
if (se.lineNumber.isEmpty)
104101
true
105-
} else {
102+
else {
106103
val m = se.lineNumber.get
107104
(cf.start, cf.end) match {
108105
case (Some(s), Some(e)) => m >= s.line && m < e.line

src/main/scala/org/scalastyle/Directory.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ object Directory {
4646
}
4747

4848
private[this] def createFileExclusionFilter(excludedFiles: Seq[String]): Option[FileFilter] = {
49-
if (excludedFiles.isEmpty) {
49+
if (excludedFiles.isEmpty)
5050
None
51-
} else {
51+
else {
5252
val exclusionPatterns = excludedFiles.map(_.r)
5353
Some(new FileFilter {
5454
def accept(file: File): Boolean = {
@@ -68,17 +68,16 @@ object Directory {
6868
def getFilesHelper(currentFiles: Iterable[File], acc: Set[File]): Set[File] = {
6969
currentFiles.headOption match {
7070
case Some(f) =>
71-
if (excludeFilter.exists(_.accept(f))) {
71+
if (excludeFilter.exists(_.accept(f)))
7272
getFilesHelper(currentFiles.tail, acc)
73-
} else if (f.isDirectory) {
73+
else if (f.isDirectory) {
7474
val newCurrentFiles = currentFiles.tail ++ f.listFiles
7575
getFilesHelper(newCurrentFiles, acc)
7676
} else if (scalaFileFilter.accept(f) && !acc(f)) {
7777
val newAcc = acc + f
7878
getFilesHelper(currentFiles.tail, newAcc)
79-
} else {
79+
} else
8080
getFilesHelper(currentFiles.tail, acc)
81-
}
8281
case None => acc
8382
}
8483
}

src/main/scala/org/scalastyle/Main.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ object Main {
8585
}
8686
}
8787

88-
if (config.config.isEmpty || config.directories.isEmpty) {
88+
if (config.config.isEmpty || config.directories.isEmpty)
8989
config = config.copy(error = true)
90-
}
9190

9291
config
9392
}
@@ -100,9 +99,8 @@ object Main {
10099
if (config.error) {
101100
usage(BuildInfo.version)
102101
1
103-
} else {
104-
if (execute(config)) 1 else 0
105-
}
102+
} else if (execute(config)) 1
103+
else 0
106104
}
107105

108106
System.exit(exitVal)
@@ -122,10 +120,9 @@ object Main {
122120
val config = ConfigFactory.load(cl.getOrElse(this.getClass.getClassLoader))
123121
val outputResult = new TextOutput(config, mc.verbose, mc.quiet).output(messages)
124122
mc.xmlFile match {
125-
case Some(x) => {
123+
case Some(x) =>
126124
val encoding = mc.xmlEncoding.getOrElse(codec.charSet).toString
127125
XmlOutput.save(config, x, encoding, messages)
128-
}
129126
case None =>
130127
}
131128

src/main/scala/org/scalastyle/Message.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ case class StyleError[+T <: FileSpec](
7272
) extends Message[T] {
7373
override def toString(): String =
7474
"StyleError key=" + key + " args=" + args + " lineNumber=" + lineNumber +
75-
" column=" + column + " customMessage=" + customMessage
75+
" column=" + column + " customMessage=" + customMessage
7676
}
7777
case class StyleException[+T <: FileSpec](
7878
fileSpec: T,

src/main/scala/org/scalastyle/Output.scala

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,20 @@ trait Output[T <: FileSpec] {
5050
OutputResult(files, errors, warnings, infos)
5151
}
5252

53-
def eachMessage(m: Message[T]): Unit = m match {
54-
case StartWork() =>
55-
case EndWork() =>
56-
case StartFile(file) => files += 1
57-
case EndFile(file) =>
58-
case StyleError(file, clazz, key, level, args, line, column, customMessage) =>
59-
level match {
60-
case WarningLevel => warnings += 1
61-
case InfoLevel => infos += 1
62-
case _ => errors += 1
63-
}
64-
case StyleException(file, clazz, message, stacktrace, line, column) => errors += 1
65-
}
53+
def eachMessage(m: Message[T]): Unit =
54+
m match {
55+
case StartWork() =>
56+
case EndWork() =>
57+
case StartFile(file) => files += 1
58+
case EndFile(file) =>
59+
case StyleError(file, clazz, key, level, args, line, column, customMessage) =>
60+
level match {
61+
case WarningLevel => warnings += 1
62+
case InfoLevel => infos += 1
63+
case _ => errors += 1
64+
}
65+
case StyleException(file, clazz, message, stacktrace, line, column) => errors += 1
66+
}
6667

6768
def message(m: Message[T]): Unit
6869
}
@@ -74,29 +75,30 @@ class TextOutput[T <: FileSpec](config: Config, verbose: Boolean = false, quiet:
7475
private val messageHelper = new MessageHelper(config)
7576

7677
// scalastyle:off regex multiple.string.literals
77-
override def message(m: Message[T]): Unit = m match {
78-
case StartWork() => if (verbose) println("Starting scalastyle")
79-
case EndWork() =>
80-
case StartFile(file) => if (verbose) println("start file " + file)
81-
case EndFile(file) => if (verbose) println("end file " + file)
82-
case StyleError(file, clazz, key, level, args, line, column, customMessage) =>
83-
if (!quiet || verbose) {
84-
println(
85-
messageHelper.text(level.name) + print("file", file.name) +
86-
print("message", Output.findMessage(messageHelper, key, args, customMessage)) +
87-
print("line", line) + print("column", column)
88-
)
89-
}
90-
case StyleException(file, clazz, message, stacktrace, line, column) =>
91-
if (!quiet || verbose) {
92-
println(
93-
"error" + print("file", file.name) + print("message", message) + print("line", line) + print(
94-
"column",
95-
column
78+
override def message(m: Message[T]): Unit =
79+
m match {
80+
case StartWork() => if (verbose) println("Starting scalastyle")
81+
case EndWork() =>
82+
case StartFile(file) => if (verbose) println("start file " + file)
83+
case EndFile(file) => if (verbose) println("end file " + file)
84+
case StyleError(file, clazz, key, level, args, line, column, customMessage) =>
85+
if (!quiet || verbose) {
86+
println(
87+
messageHelper.text(level.name) + print("file", file.name) +
88+
print("message", Output.findMessage(messageHelper, key, args, customMessage)) +
89+
print("line", line) + print("column", column)
9690
)
97-
)
98-
}
99-
}
91+
}
92+
case StyleException(file, clazz, message, stacktrace, line, column) =>
93+
if (!quiet || verbose) {
94+
println(
95+
"error" + print("file", file.name) + print("message", message) + print("line", line) + print(
96+
"column",
97+
column
98+
)
99+
)
100+
}
101+
}
100102

101103
// scalastyle:on regex
102104

@@ -137,18 +139,14 @@ object XmlOutput {
137139
private def printToFile(f: java.io.File, encoding: String)(op: java.io.PrintWriter => Unit): Unit = {
138140
val parent = f.getParentFile
139141
// sometimes f.getParentFile returns null - don't know why, but protect anyway
140-
if (parent != null && !parent.exists() && !parent.mkdirs()) { // scalastyle:ignore null
142+
if (parent != null && !parent.exists() && !parent.mkdirs()) // scalastyle:ignore null
141143
throw new IllegalStateException("Couldn't create dir: " + parent)
142-
}
143144

144145
val p = new java.io.PrintWriter(f, encoding)
145-
try {
146-
op(p)
147-
} catch {
146+
try op(p)
147+
catch {
148148
case e: Throwable => throw e
149-
} finally {
150-
p.close()
151-
}
149+
} finally p.close()
152150
}
153151

154152
case class Alert(
@@ -188,15 +186,17 @@ object XmlOutput {
188186
<file name={filename}>
189187
{
190188
alerts.map {
191-
case Alert(fn, severity, message, source, line, column) => {
189+
case Alert(fn, severity, message, source, line, column) =>
192190
val s = source.collect {
193191
case x: Class[_] => x.getName
194192
}
195-
<error severity={severity} message={message}/> % attr("source", s) % attr("line", line) % attr(
193+
<error severity={severity} message={message}/> % attr("source", s) % attr(
194+
"line",
195+
line
196+
) % attr(
196197
"column",
197198
column
198199
)
199-
}
200200
}
201201
}
202202
</file>
@@ -205,8 +205,9 @@ object XmlOutput {
205205
</checkstyle>
206206
}
207207

208-
private[this] def attr(name: String, value: Option[Any]): xml.MetaData = value match {
209-
case Some(x) => xml.Attribute("", name, x.toString, xml.Null)
210-
case None => xml.Null
211-
}
208+
private[this] def attr(name: String, value: Option[Any]): xml.MetaData =
209+
value match {
210+
case Some(x) => xml.Attribute("", name, x.toString, xml.Null)
211+
case None => xml.Null
212+
}
212213
}

0 commit comments

Comments
 (0)