Skip to content

Commit

Permalink
Update scalafmt-core to 2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
scala-steward authored and marcospereira committed Mar 3, 2020
1 parent 0feb367 commit 712dd9a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ rewrite.rules = [ AvoidInfix, ExpandImportSelectors, RedundantParens, SortModifi
rewrite.sortModifiers.order = [ "private", "protected", "final", "sealed", "abstract", "implicit", "override", "lazy" ]
spaces.inImportCurlyBraces = true # more idiomatic to include whitepsace in import x.{ yyy }
trailingCommas = preserve
version = 2.4.1
version = 2.4.2
4 changes: 1 addition & 3 deletions api/shared/src/main/scala/play/twirl/api/Content.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ abstract class BufferedContent[A <: BufferedContent[A]](
with Content { this: A =>
protected def buildString(builder: StringBuilder): Unit = {
if (!elements.isEmpty) {
elements.foreach { e =>
e.buildString(builder)
}
elements.foreach { e => e.buildString(builder) }
} else {
builder.append(text)
}
Expand Down
4 changes: 1 addition & 3 deletions api/shared/src/main/scala/play/twirl/api/Formats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ class Html private[api] (elements: immutable.Seq[Html], text: String, escape: Bo
*/
protected override def buildString(builder: StringBuilder): Unit = {
if (elements.nonEmpty) {
elements.foreach { e =>
e.buildString(builder)
}
elements.foreach { e => e.buildString(builder) }
} else if (escape) {
// Using our own algorithm here because commons lang escaping wasn't designed for protecting against XSS, and there
// don't seem to be any other good generic escaping tools out there.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ object TwirlCompiler {
// We need to double escape slashes, since it's a regex replacement
private val escapedTripleQuote = "\\\"" * 3
private val doubleEscapedTripleQuote = "\\\\\"" * 3
private val tripleQuoteReplacement = escapedTripleQuote + " + \\\"" + doubleEscapedTripleQuote + "\\\" + " + escapedTripleQuote
private val tripleQuoteReplacement =
escapedTripleQuote + " + \\\"" + doubleEscapedTripleQuote + "\\\" + " + escapedTripleQuote
private def quoteAndEscape(text: String): collection.Seq[String] = {
Seq(tripleQuote, text.replaceAll(tripleQuote, tripleQuoteReplacement), tripleQuote)
}
Expand All @@ -365,9 +366,7 @@ object TwirlCompiler {
val grouped = StringGrouper(text, 20000)
(if (previous.isEmpty) Nil else previous :+ ",") :+
"format.raw" :+ Source("(", p.pos) :+ quoteAndEscape(grouped.head) :+ ")" :+
grouped.tail.flatMap { t =>
Seq(",\nformat.raw(", quoteAndEscape(t), ")")
}
grouped.tail.flatMap { t => Seq(",\nformat.raw(", quoteAndEscape(t), ")") }
case Comment(msg) => previous
case Display(exp) =>
(if (previous.isEmpty) Nil else previous :+ ",") :+ displayVisitedChildren(visit(Seq(exp), Nil))
Expand Down
29 changes: 9 additions & 20 deletions parser/src/main/scala/play/twirl/parser/TwirlParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,9 @@ class TwirlParser(val shouldParseInclusiveDot: Boolean) {
if (check("{")) {
var buffer = new ListBuffer[TemplateTree]
buffer += position(Plain("{"), lbracepos)
for (m <- several[ListBuffer[TemplateTree], ListBuffer[ListBuffer[TemplateTree]]] { () =>
mixed()
})
buffer = buffer ++ m // creates a new object, but is constant in time, as opposed to buffer ++= m which is linear (proportional to size of m)
for (m <- several[ListBuffer[TemplateTree], ListBuffer[ListBuffer[TemplateTree]]] { () => mixed() })
buffer =
buffer ++ m // creates a new object, but is constant in time, as opposed to buffer ++= m which is linear (proportional to size of m)
val rbracepos = input.offset()
if (check("}"))
buffer += position(Plain("}"), rbracepos)
Expand Down Expand Up @@ -509,9 +508,7 @@ class TwirlParser(val shouldParseInclusiveDot: Boolean) {
val ws = whitespaceNoBreak()
if (check("{")) {
val blkArgs = if (blockArgsAllowed) Option(blockArgs()) else None
val mixeds = several[ListBuffer[TemplateTree], ListBuffer[ListBuffer[TemplateTree]]] { () =>
mixed()
}
val mixeds = several[ListBuffer[TemplateTree], ListBuffer[ListBuffer[TemplateTree]]] { () => mixed() }
accept("}")
// TODO - not use flatten here (if it's a performance problem)
result = position(Block(ws, blkArgs, mixeds.flatten), p)
Expand Down Expand Up @@ -632,9 +629,7 @@ class TwirlParser(val shouldParseInclusiveDot: Boolean) {
val pos = input.offset()
val code = methodCall()
if (code != null) {
val parts = several[ScalaExpPart, ListBuffer[ScalaExpPart]] { () =>
expressionPart(blockArgsAllowed = true)
}
val parts = several[ScalaExpPart, ListBuffer[ScalaExpPart]] { () => expressionPart(blockArgsAllowed = true) }
parts.prepend(position(Simple(code), pos))
result = Display(ScalaExp(parts))
} else input.regressTo(pos - 1) // don't consume the @
Expand Down Expand Up @@ -775,9 +770,7 @@ class TwirlParser(val shouldParseInclusiveDot: Boolean) {
val p = input.offset()
if (check("else if")) {
whitespaceNoBreak()
val args = several[String, ArrayBuffer[String]] { () =>
parentheses()
}
val args = several[String, ArrayBuffer[String]] { () => parentheses() }
position(Simple("else if" + args.mkString(",")), p)
} else {
input.regressTo(reset)
Expand Down Expand Up @@ -830,10 +823,8 @@ class TwirlParser(val shouldParseInclusiveDot: Boolean) {
if (name != null) {
val paramspos = input.offset()
val types = Option(squareBrackets()).getOrElse(PosString(""))
val args = several[String, ArrayBuffer[String]] { () =>
parentheses()
}
val params = position(PosString(types.toString + args.mkString), paramspos)
val args = several[String, ArrayBuffer[String]] { () => parentheses() }
val params = position(PosString(types.toString + args.mkString), paramspos)
if (params != null)
return (name, params)
} else input.regress(1) // don't consume @
Expand Down Expand Up @@ -903,9 +894,7 @@ class TwirlParser(val shouldParseInclusiveDot: Boolean) {
* Parse the template arguments.
*/
private def templateArgs(): String = {
val result = several[String, ArrayBuffer[String]] { () =>
parentheses()
}
val result = several[String, ArrayBuffer[String]] { () => parentheses() }
if (result.nonEmpty)
result.mkString
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ object TemplateCompiler {
case TemplateCompilationError(source, message, line, column) =>
val exception = TemplateProblem.exception(source, codec, message, line, column)
val reporter = new LoggedReporter(10, log)
exception.problems.foreach { p =>
reporter.log(p)
}
exception.problems.foreach { p => reporter.log(p) }
throw exception
case e => throw e
}
Expand Down
12 changes: 3 additions & 9 deletions sbt-twirl/src/main/scala/play/twirl/sbt/TemplateProblem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ object TemplateProblem {
}

def apply(generated: GeneratedSource, position: Position): TemplatePosition = {
val offset = toScala(position.offset).map { o =>
generated.mapPosition(o)
}
val location = offset.flatMap { o =>
TemplateMapping(generated.source, generated.codec).location(o)
}
val offset = toScala(position.offset).map { o => generated.mapPosition(o) }
val location = offset.flatMap { o => TemplateMapping(generated.source, generated.codec).location(o) }
new TemplatePosition(generated.source, location)
}
}
Expand All @@ -64,9 +60,7 @@ object TemplateProblem {
val pointer: java.util.Optional[Integer] = toJava { location.map(_.column) }

val pointerSpace: java.util.Optional[String] = toJava {
location.map { l =>
lineContent.take(l.column).map { case '\t' => '\t'; case _ => ' ' }
}
location.map { l => lineContent.take(l.column).map { case '\t' => '\t'; case _ => ' ' } }
}

val sourceFile: java.util.Optional[File] = toJava(source)
Expand Down

0 comments on commit 712dd9a

Please sign in to comment.