From 712dd9ab721f1664c872f786bd41a5520d580beb Mon Sep 17 00:00:00 2001 From: Scala Steward Date: Sun, 23 Feb 2020 03:07:41 +0100 Subject: [PATCH] Update scalafmt-core to 2.4.2 --- .scalafmt.conf | 2 +- .../main/scala/play/twirl/api/Content.scala | 4 +-- .../main/scala/play/twirl/api/Formats.scala | 4 +-- .../play/twirl/compiler/TwirlCompiler.scala | 7 ++--- .../scala/play/twirl/parser/TwirlParser.scala | 29 ++++++------------- .../play/twirl/sbt/TemplateCompiler.scala | 4 +-- .../play/twirl/sbt/TemplateProblem.scala | 12 ++------ 7 files changed, 19 insertions(+), 43 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 3c538b40..3a75e8e1 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -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 diff --git a/api/shared/src/main/scala/play/twirl/api/Content.scala b/api/shared/src/main/scala/play/twirl/api/Content.scala index c0b65b9f..2ffd4e52 100644 --- a/api/shared/src/main/scala/play/twirl/api/Content.scala +++ b/api/shared/src/main/scala/play/twirl/api/Content.scala @@ -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) } diff --git a/api/shared/src/main/scala/play/twirl/api/Formats.scala b/api/shared/src/main/scala/play/twirl/api/Formats.scala index 844bc457..1c245d05 100644 --- a/api/shared/src/main/scala/play/twirl/api/Formats.scala +++ b/api/shared/src/main/scala/play/twirl/api/Formats.scala @@ -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. diff --git a/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala b/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala index 384624aa..cff45ef8 100644 --- a/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala +++ b/compiler/src/main/scala/play/twirl/compiler/TwirlCompiler.scala @@ -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) } @@ -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)) diff --git a/parser/src/main/scala/play/twirl/parser/TwirlParser.scala b/parser/src/main/scala/play/twirl/parser/TwirlParser.scala index bef7e2c3..6334bd61 100644 --- a/parser/src/main/scala/play/twirl/parser/TwirlParser.scala +++ b/parser/src/main/scala/play/twirl/parser/TwirlParser.scala @@ -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) @@ -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) @@ -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 @ @@ -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) @@ -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 @ @@ -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 diff --git a/sbt-twirl/src/main/scala/play/twirl/sbt/TemplateCompiler.scala b/sbt-twirl/src/main/scala/play/twirl/sbt/TemplateCompiler.scala index 22f1d1df..10a43e37 100644 --- a/sbt-twirl/src/main/scala/play/twirl/sbt/TemplateCompiler.scala +++ b/sbt-twirl/src/main/scala/play/twirl/sbt/TemplateCompiler.scala @@ -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 } diff --git a/sbt-twirl/src/main/scala/play/twirl/sbt/TemplateProblem.scala b/sbt-twirl/src/main/scala/play/twirl/sbt/TemplateProblem.scala index bf81f6da..45ac60a8 100644 --- a/sbt-twirl/src/main/scala/play/twirl/sbt/TemplateProblem.scala +++ b/sbt-twirl/src/main/scala/play/twirl/sbt/TemplateProblem.scala @@ -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) } } @@ -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)