From 339a5e5522c699f7a8a77751308255f6d75e03fa Mon Sep 17 00:00:00 2001 From: Hanns Holger Rutz Date: Fri, 1 Feb 2019 00:00:56 +0100 Subject: [PATCH] add support for Scala 2.13.0-M5 - add to cross-versions - update dependencies as necessary - some code clean up (explicit return types in public methods, no procedure syntax, return types for implicit values) --- build.sbt | 11 +++++----- .../commandline/ScalaFileWalker.scala | 11 +++++----- project/build.properties | 2 +- project/plugins.sbt | 8 +++---- .../scala/scalariform/ScalaVersions.scala | 2 +- .../scalariform/astselect/AstSelector.scala | 7 ++++-- .../formatter/CaseClauseFormatter.scala | 2 +- .../formatter/ScalaFormatter.scala | 6 ++--- .../preferences/PreferenceDescriptor.scala | 4 ++-- .../main/scala/scalariform/lexer/Tokens.scala | 11 ++++++---- .../scala/scalariform/parser/AstNodes.scala | 4 +++- .../main/scala/scalariform/utils/Range.scala | 8 +++---- .../scala/scalariform/utils/TextEdits.scala | 4 ++-- .../main/scala/scalariform/utils/Utils.scala | 2 +- .../astselect/AstSelectorTest.scala | 2 +- .../AbstractExpressionFormatterTest.scala | 4 ++-- .../formatter/AbstractFormatterTest.scala | 5 ++--- .../formatter/CaseClausesFormatterTest.scala | 15 ++++++++----- .../formatter/CommentFormatterTest.scala | 12 +++++----- .../CompactControlReadabilityTest.scala | 3 ++- .../formatter/DefOrDclFormatterTest.scala | 22 +++++++++++-------- ...DoubleIndentConstructorArgumentsTest.scala | 8 ++++--- .../DoubleIndentMethodFormatterTest.scala | 7 +++--- .../FormatterDirectiveParserTest.scala | 3 +-- .../formatter/FunctionFormatterTest.scala | 4 ++-- .../formatter/ImportFormatterTest.scala | 8 +++---- .../formatter/IndentWithTabsTest.scala | 13 ++++++----- .../MiscExpressionFormatterTest.scala | 18 ++++++++++----- .../formatter/MiscFormatterTest.scala | 5 +++-- .../scalariform/formatter/MutateTest.scala | 5 +++-- .../NewlineAtEndOfFileFormatterTest.scala | 11 ++++++---- .../formatter/PackageFormatterTest.scala | 7 +++--- .../formatter/ParamGroupsOnNewlineTest.scala | 7 +++--- .../ParenAndBracketSpacingTest.scala | 15 ++++++++----- .../formatter/RewriteArrowsTest.scala | 3 ++- .../formatter/ScriptFormatterTest.scala | 4 ++-- .../formatter/TemplateFormatterTest.scala | 18 +++++++++------ .../formatter/TypeFormatterTest.scala | 5 +++-- .../XmlExpressionFormatterTest.scala | 2 +- .../lexer/NewlineInferencerTest.scala | 9 ++++---- .../RedundantSemicolonDetectorTest.scala | 14 ++++++------ .../scalariform/lexer/ScalaLexerTest.scala | 19 ++++++++-------- .../scala/scalariform/parser/ParserTest.scala | 4 ++-- 43 files changed, 189 insertions(+), 145 deletions(-) diff --git a/build.sbt b/build.sbt index 47ed6850..0cef9f55 100644 --- a/build.sbt +++ b/build.sbt @@ -10,12 +10,13 @@ lazy val commonSettings = inConfig(Test)(Defaults.testSettings) ++ sonatypeProfileName := organization.value, scalaVersion := crossScalaVersions.value.head, crossScalaVersions := Seq( - "2.12.4", + "2.13.0-M5", + "2.12.8", "2.11.12", "2.10.7" ), scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 12)) => Seq( + case Some((2, major)) if major >= 12 => Seq( "-Xlint:-unused,_", "-Ywarn-unused:imports", "-language:postfixOps", "-language:implicitConversions", "-deprecation", "-feature" @@ -76,8 +77,8 @@ def subprojectSettings(projectName: String) = commonSettings ++ Seq( def scala2_11Dependencies = Def.setting { CrossVersion.partialVersion(scalaVersion.value) match { case Some((2, major)) if major >= 11 => Seq( - "org.scala-lang.modules" %% "scala-xml" % "1.0.6", - "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6" + "org.scala-lang.modules" %% "scala-xml" % "1.1.1", + "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.1" ) case _ => Nil } @@ -89,7 +90,7 @@ lazy val scalariform = (project settings(publishSettings("scalariform")) settings( libraryDependencies ++= scala2_11Dependencies.value, - libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test", + libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.6-SNAP6" % Test, // sbt doesn't automatically load the content of the MANIFST.MF file, therefore // we have to do it here by ourselves. Furthermore, the version format in the // MANIFEST.MF is `version.qualifier`, which means that we have to replace diff --git a/cli/src/main/scala/scalariform/commandline/ScalaFileWalker.scala b/cli/src/main/scala/scalariform/commandline/ScalaFileWalker.scala index 0b00446b..75fbbace 100644 --- a/cli/src/main/scala/scalariform/commandline/ScalaFileWalker.scala +++ b/cli/src/main/scala/scalariform/commandline/ScalaFileWalker.scala @@ -1,24 +1,25 @@ package scalariform.commandline import java.io.File -import java.util.{ ArrayList, Collection } -import scala.collection.JavaConverters._ +import java.util import org.apache.commons.io._ import org.apache.commons.io.filefilter._ +import scala.collection.JavaConverters._ + object ScalaFileWalker extends DirectoryWalker(TrueFileFilter.INSTANCE, FileFilterUtils.suffixFileFilter(".scala"), -1) { def findScalaFiles(path: String): List[File] = findScalaFiles(new File(path)) def findScalaFiles(path: File): List[File] = { - val results = new ArrayList[File] + val results = new util.ArrayList[File] walk(path, results) results.asScala.toList } - override protected def handleFile(file: File, depth: Int, results: Collection[_]) { - val castResults = results.asInstanceOf[Collection[File]] + override protected def handleFile(file: File, depth: Int, results: util.Collection[_]): Unit = { + val castResults = results.asInstanceOf[util.Collection[File]] castResults.add(file) } diff --git a/project/build.properties b/project/build.properties index a31be40f..c0bab049 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.0.4 \ No newline at end of file +sbt.version=1.2.8 diff --git a/project/plugins.sbt b/project/plugins.sbt index 1d025a58..c3cb80a9 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,6 @@ addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") -addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0") -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6") -addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.18") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9") +addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0") diff --git a/scalariform/src/main/scala/scalariform/ScalaVersions.scala b/scalariform/src/main/scala/scalariform/ScalaVersions.scala index 53499430..8204306b 100644 --- a/scalariform/src/main/scala/scalariform/ScalaVersions.scala +++ b/scalariform/src/main/scala/scalariform/ScalaVersions.scala @@ -29,7 +29,7 @@ case class ScalaVersion(major: Int, minor: Int, extra: String = "") extends Orde def compare(that: ScalaVersion): Int = Ordering[(Int, Int)].compare(this.majorMinor, that.majorMinor) - override def toString: String = major + "." + minor + "." + extra + override def toString: String = major.toString + "." + minor + "." + extra } diff --git a/scalariform/src/main/scala/scalariform/astselect/AstSelector.scala b/scalariform/src/main/scala/scalariform/astselect/AstSelector.scala index a2707057..a1f1d865 100644 --- a/scalariform/src/main/scala/scalariform/astselect/AstSelector.scala +++ b/scalariform/src/main/scala/scalariform/astselect/AstSelector.scala @@ -147,7 +147,10 @@ class AstSelector(source: String, scalaVersion: String = ScalaVersions.DEFAULT_V */ private def expandToEnclosingAst(node: AstNode, initialSelection: Range, enclosingNodes: List[AstNode]): Option[Range] = { - val nodeRange = adjustedNodeRange(node).getOrElse { return None } + val nodeRange = adjustedNodeRange(node) match { + case Some(r) => r + case None => return None + } if (!nodeRange.contains(initialSelection)) { return None } @@ -183,7 +186,7 @@ class AstSelector(source: String, scalaVersion: String = ScalaVersions.DEFAULT_V nodeStack match { case List(_: BlockExpr, _: MatchExpr, _*) ⇒ false case List(_: BlockExpr, _: ProcFunBody, _*) ⇒ false - case List(node, _*) ⇒ !(nonSelectableAstNodes contains node.getClass) + case node :: _ ⇒ !(nonSelectableAstNodes contains node.getClass) case Nil ⇒ false } diff --git a/scalariform/src/main/scala/scalariform/formatter/CaseClauseFormatter.scala b/scalariform/src/main/scala/scalariform/formatter/CaseClauseFormatter.scala index c16ef72e..8ae9609f 100644 --- a/scalariform/src/main/scala/scalariform/formatter/CaseClauseFormatter.scala +++ b/scalariform/src/main/scala/scalariform/formatter/CaseClauseFormatter.scala @@ -125,7 +125,7 @@ trait CaseClauseFormatter { self: HasFormattingPreferences with ExprFormatter wi statSeq.firstTokenOption.isDefined && newlineBefore(statSeq) || containsNewline(statSeq) && !singleExpr - def unindent(x: Map[Token, IntertokenFormatInstruction]) = x.map { + def unindent(x: Map[Token, IntertokenFormatInstruction]): Map[Token, IntertokenFormatInstruction] = x.map { case (k, EnsureNewlineAndIndent(indentLevel, relativeTo)) => k -> EnsureNewlineAndIndent(indentLevel - 1, relativeTo) case z => z diff --git a/scalariform/src/main/scala/scalariform/formatter/ScalaFormatter.scala b/scalariform/src/main/scala/scalariform/formatter/ScalaFormatter.scala index 859bdb41..014af2f9 100755 --- a/scalariform/src/main/scala/scalariform/formatter/ScalaFormatter.scala +++ b/scalariform/src/main/scala/scalariform/formatter/ScalaFormatter.scala @@ -554,7 +554,7 @@ abstract class ScalaFormatter object ScalaFormatter { // format: OFF - val ENSURE_SPACE_AFTER = Set( + val ENSURE_SPACE_AFTER: Set[TokenType] = Set( ABSTRACT, CASE, CATCH, CLASS, DEF, DO, ELSE, EXTENDS, FINAL, FINALLY, FOR, FORSOME, IF, IMPLICIT, @@ -566,7 +566,7 @@ object ScalaFormatter { /* USCORE, */ COLON, EQUALS, ARROW, LARROW, SUBTYPE, VIEWBOUND, SUPERTYPE, /* HASH, AT */ LBRACE, SEMI) - val ENSURE_SPACE_BEFORE = Set( + val ENSURE_SPACE_BEFORE: Set[TokenType] = Set( ABSTRACT, CASE, CATCH, CLASS, DEF, /* DO, */ ELSE, EXTENDS, FINAL, FINALLY, /* FOR, */ FORSOME, /* IF, */ IMPLICIT, @@ -589,7 +589,7 @@ object ScalaFormatter { @throws(classOf[ScalaParserException]) def formatAsEdits(source: String, formattingPreferences: IFormattingPreferences = FormattingPreferences(), lineDelimiter: Option[String] = None, initialIndentLevel: Int = 0, scalaVersion: String = ScalaVersions.DEFAULT_VERSION): List[TextEdit] = { - val specificFormatter = new SpecificFormatter { + val specificFormatter: SpecificFormatter = new SpecificFormatter { type Result = CompilationUnit diff --git a/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala b/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala index d49e6b18..d79235c5 100755 --- a/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala +++ b/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala @@ -50,9 +50,9 @@ case class IntegerPreference(min: Int, max: Int) extends PreferenceType[Int] { try { val n = Integer.parseInt(s) if (n < min) - Left(n + " is below minimum of " + min) + Left(n.toString + " is below minimum of " + min) else if (n > max) - Left(n + " is above maximum of " + max) + Left(n.toString + " is above maximum of " + max) else Right(n) } catch { diff --git a/scalariform/src/main/scala/scalariform/lexer/Tokens.scala b/scalariform/src/main/scala/scalariform/lexer/Tokens.scala index 49232cd6..a9adf60a 100644 --- a/scalariform/src/main/scala/scalariform/lexer/Tokens.scala +++ b/scalariform/src/main/scala/scalariform/lexer/Tokens.scala @@ -98,7 +98,7 @@ object Tokens { val XML_UNPARSED = TokenType("XML_UNPARSED", isXml = true) val XML_PROCESSING_INSTRUCTION = TokenType("XML_PROCESSING_INSTRUCTION", isXml = true) - val KEYWORDS = Set( + val KEYWORDS: Set[TokenType] = Set( ABSTRACT, CASE, CATCH, CLASS, DEF, DO, ELSE, EXTENDS, FINAL, FINALLY, FOR, FORSOME, IF, IMPLICIT, @@ -109,10 +109,13 @@ object Tokens { VAL, VAR, WHILE, WITH, YIELD ) - val COMMENTS = Set(LINE_COMMENT, MULTILINE_COMMENT, XML_COMMENT) + val COMMENTS: Set[TokenType] = Set(LINE_COMMENT, MULTILINE_COMMENT, XML_COMMENT) - val IDS = Set(VARID, PLUS, MINUS, STAR, PIPE, TILDE, EXCLAMATION) + val IDS: Set[TokenType] = Set(VARID, PLUS, MINUS, STAR, PIPE, TILDE, EXCLAMATION) - val LITERALS = Set(CHARACTER_LITERAL, INTEGER_LITERAL, FLOATING_POINT_LITERAL, STRING_LITERAL, STRING_PART, SYMBOL_LITERAL, TRUE, FALSE, NULL) + val LITERALS: Set[TokenType] = Set( + CHARACTER_LITERAL, INTEGER_LITERAL, FLOATING_POINT_LITERAL, STRING_LITERAL, + STRING_PART, SYMBOL_LITERAL, TRUE, FALSE, NULL + ) } diff --git a/scalariform/src/main/scala/scalariform/parser/AstNodes.scala b/scalariform/src/main/scala/scalariform/parser/AstNodes.scala index b0c13329..186e3c9a 100644 --- a/scalariform/src/main/scala/scalariform/parser/AstNodes.scala +++ b/scalariform/src/main/scala/scalariform/parser/AstNodes.scala @@ -32,7 +32,9 @@ sealed trait AstNode extends Product { case Right(f) ⇒ f.tokens } } - protected implicit def tokenToFlattenable(token: Token): Flattenable = new Flattenable { val tokens = List(token) } + protected implicit def tokenToFlattenable(token: Token): Flattenable = new Flattenable { + val tokens: List[Token] = List(token) + } protected def flatten(flattenables: Flattenable*): List[Token] = flattenables.toList flatMap { _.tokens } diff --git a/scalariform/src/main/scala/scalariform/utils/Range.scala b/scalariform/src/main/scala/scalariform/utils/Range.scala index c3537cf7..c81d9710 100644 --- a/scalariform/src/main/scala/scalariform/utils/Range.scala +++ b/scalariform/src/main/scala/scalariform/utils/Range.scala @@ -2,19 +2,19 @@ package scalariform.utils case class Range(offset: Int, length: Int) { - def contains(other: Range) = other.offset >= offset && other.offset + other.length <= offset + length + def contains(other: Range): Boolean = other.offset >= offset && other.offset + other.length <= offset + length - def strictlyContains(other: Range) = (this contains other) && this.length > other.length + def strictlyContains(other: Range): Boolean = (this contains other) && this.length > other.length /** * @return the smallest range that contains both this and other */ - def mergeWith(other: Range) = { + def mergeWith(other: Range): Range = { val List(earliest, latest) = List(this, other) sortBy (_.offset) Range(earliest.offset, latest.offset - earliest.offset + latest.length) } - def intersects(other: Range) = + def intersects(other: Range): Boolean = !(other.offset >= offset + length || other.offset + other.length - 1 < offset) def expandLeft(n: Int): Range = Range(offset - n, length + n) diff --git a/scalariform/src/main/scala/scalariform/utils/TextEdits.scala b/scalariform/src/main/scala/scalariform/utils/TextEdits.scala index 6dc4e276..99692c39 100644 --- a/scalariform/src/main/scala/scalariform/utils/TextEdits.scala +++ b/scalariform/src/main/scala/scalariform/utils/TextEdits.scala @@ -14,12 +14,12 @@ case class TextEdit(position: Int, length: Int, replacement: String) { require(length >= 0) - override lazy val toString = { + override lazy val toString: String = { val replacementDisplay = replacement.replace("\n", """\n""").replace("\r", """\r""") getClass.getSimpleName + "(position = " + position + ", length = " + length + ", replacement = '" + replacementDisplay + "')" } - def shift(n: Int) = copy(position = position + n) + def shift(n: Int): TextEdit = copy(position = position + n) } diff --git a/scalariform/src/main/scala/scalariform/utils/Utils.scala b/scalariform/src/main/scala/scalariform/utils/Utils.scala index 2abccf06..568a7712 100644 --- a/scalariform/src/main/scala/scalariform/utils/Utils.scala +++ b/scalariform/src/main/scala/scalariform/utils/Utils.scala @@ -7,7 +7,7 @@ import scala.collection.mutable.ListBuffer object Utils { - implicit def string2PimpedString(s: String) = new PimpedString(s) + implicit def string2PimpedString(s: String): PimpedString = new PimpedString(s) class PimpedString(s: String) { def toIntOpt: Option[Int] = try Some(s.toInt) catch { case _: NumberFormatException ⇒ None } diff --git a/scalariform/src/test/scala/scalariform/astselect/AstSelectorTest.scala b/scalariform/src/test/scala/scalariform/astselect/AstSelectorTest.scala index 25902646..08d17520 100644 --- a/scalariform/src/test/scala/scalariform/astselect/AstSelectorTest.scala +++ b/scalariform/src/test/scala/scalariform/astselect/AstSelectorTest.scala @@ -282,7 +282,7 @@ class AstSelectorTest extends FlatSpec with Matchers { */ { - implicit val scalaVersion = "2.10.0" + implicit val scalaVersion: String = "2.10.0" """ s"my name is ?{person.name}." """.replace('?', '$') ~ """ $$$$$$ " """ ~ diff --git a/scalariform/src/test/scala/scalariform/formatter/AbstractExpressionFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/AbstractExpressionFormatterTest.scala index 557d36de..24db64c1 100644 --- a/scalariform/src/test/scala/scalariform/formatter/AbstractExpressionFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/AbstractExpressionFormatterTest.scala @@ -6,8 +6,8 @@ abstract class AbstractExpressionFormatterTest extends AbstractFormatterTest { type Result = Expr - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState()) + def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState()) - def parse(parser: ScalaParser) = parser.expr() + def parse(parser: ScalaParser): Result = parser.expr() } diff --git a/scalariform/src/test/scala/scalariform/formatter/AbstractFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/AbstractFormatterTest.scala index e395b219..3fc9801c 100644 --- a/scalariform/src/test/scala/scalariform/formatter/AbstractFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/AbstractFormatterTest.scala @@ -23,7 +23,7 @@ abstract class AbstractFormatterTest extends FlatSpec with Matchers with Specifi require(formattingPreferences != null) - def ==>(expectedRaw: String) { + def ==>(expectedRaw: String): Unit = it should ("format >>>" + prettyPrint(source) + "<<< as >>>" + prettyPrint(expectedRaw) + "<<< with preferences " + formattingPreferences + " in version " + scalaVersion) in { val expected = expectedRaw.stripMargin val actual = format(source, scalaVersion = scalaVersion)(formattingPreferences) @@ -45,7 +45,6 @@ abstract class AbstractFormatterTest extends FlatSpec with Matchers with Specifi throw testFailedException("Idempotency token inconsistency:\n ---- One ---- \n" + afterTokens2 + "\n ---- Twice ---- \n" + afterTokens2 + "\n") } } - } def =/=>(expected: String): Because = { //println("Warning -- skipped test:\n" + source) @@ -53,7 +52,7 @@ abstract class AbstractFormatterTest extends FlatSpec with Matchers with Specifi } class Because(expected: String) { - def because(reason: String) = { + def because(reason: String): Unit = { //println("because " + reason) it should ("format >>>" + prettyPrint(source) + "<<< as >>>" + prettyPrint(expected) + "<<<, but did not because " + reason) in { throw new TestPendingException diff --git a/scalariform/src/test/scala/scalariform/formatter/CaseClausesFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/CaseClausesFormatterTest.scala index 731352dc..7e641576 100644 --- a/scalariform/src/test/scala/scalariform/formatter/CaseClausesFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/CaseClausesFormatterTest.scala @@ -85,7 +85,7 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest { |}""" { - implicit val formattingPreferences = FormattingPreferences.setPreference( + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference( SingleCasePatternOnNewline, false ) """a match { case a => b; c; @@ -187,7 +187,8 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest { |}""" { - implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesWithinPatternBinders, false) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(SpacesWithinPatternBinders, false) """a match { | case b(c @ ~()) => @@ -201,7 +202,8 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest { { - implicit val formattingPreferences = FormattingPreferences.setPreference(AlignSingleLineCaseStatements, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(AlignSingleLineCaseStatements, true) """a match { |case x => 1 @@ -285,7 +287,7 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest { |}""" { - implicit val formattingPreferences = + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference(AlignSingleLineCaseStatements, true).setPreference(RewriteArrowSymbols, true) """a match { @@ -300,7 +302,7 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest { { - implicit val formattingPreferences = + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences .setPreference(AlignSingleLineCaseStatements, true) .setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 5) @@ -354,7 +356,8 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest { |}""" { - implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesWithinPatternBinders, false) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(SpacesWithinPatternBinders, false) """(a: @switch) match { |case elem@Multi(values@_*) => diff --git a/scalariform/src/test/scala/scalariform/formatter/CommentFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/CommentFormatterTest.scala index 2d7e9fab..67e99a39 100755 --- a/scalariform/src/test/scala/scalariform/formatter/CommentFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/CommentFormatterTest.scala @@ -8,9 +8,9 @@ class CommentFormatterTest extends AbstractFormatterTest { type Result = CompilationUnit - def parse(parser: ScalaParser) = parser.scriptBody() + def parse(parser: ScalaParser): Result = parser.scriptBody() - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState()) + def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState()) override val debug = false @@ -142,7 +142,8 @@ class CommentFormatterTest extends AbstractFormatterTest { | */ """ { - implicit val formattingPreferences = FormattingPreferences.setPreference(MultilineScaladocCommentsStartOnFirstLine, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(MultilineScaladocCommentsStartOnFirstLine, true) """/** This method applies f to each | * element of the given list. @@ -175,7 +176,8 @@ class CommentFormatterTest extends AbstractFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true) """/** This method applies f to each | * element of the given list. @@ -211,7 +213,7 @@ class CommentFormatterTest extends AbstractFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences .setPreference(MultilineScaladocCommentsStartOnFirstLine, true) .setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true) """/** This method applies f to each diff --git a/scalariform/src/test/scala/scalariform/formatter/CompactControlReadabilityTest.scala b/scalariform/src/test/scala/scalariform/formatter/CompactControlReadabilityTest.scala index 20ea842b..7029523e 100644 --- a/scalariform/src/test/scala/scalariform/formatter/CompactControlReadabilityTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/CompactControlReadabilityTest.scala @@ -5,7 +5,8 @@ import scalariform.formatter.preferences._ // format: OFF class CompactControlReadabilityTest extends AbstractExpressionFormatterTest { - implicit val formattingPreferences = FormattingPreferences.setPreference(CompactControlReadability, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(CompactControlReadability, true) """if(a){ |foo diff --git a/scalariform/src/test/scala/scalariform/formatter/DefOrDclFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/DefOrDclFormatterTest.scala index e806c8ae..2a8dbc1d 100644 --- a/scalariform/src/test/scala/scalariform/formatter/DefOrDclFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/DefOrDclFormatterTest.scala @@ -114,7 +114,7 @@ class DefOrDclFormatterTest extends AbstractFormatterTest { { // SpaceBeforeColon should add a space for the context colon (for backwards-compatibility). - implicit val formattingPreferences = + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference(SpaceBeforeColon, true).setPreference(SpaceBeforeContextColon, false) """class Foo[A : B]() {}""" ==> @@ -123,7 +123,7 @@ class DefOrDclFormatterTest extends AbstractFormatterTest { { // Typeclass formatting should not be affected by the SpaceBeforeColon setting. - implicit val formattingPreferences = + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference(SpaceBeforeColon, false).setPreference(SpaceBeforeContextColon, true) """class Foo[A : B]() {}""" ==> @@ -138,7 +138,7 @@ class DefOrDclFormatterTest extends AbstractFormatterTest { } { // Typeclass formatting should not be affected by the SpaceBeforeColon setting. - implicit val formattingPreferences = + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference(SpaceBeforeColon, true).setPreference(SpaceBeforeContextColon, true) """class Foo[A : B]() {}""" ==> @@ -154,7 +154,7 @@ class DefOrDclFormatterTest extends AbstractFormatterTest { { - implicit val formattingPreferences = + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences .setPreference(IndentLocalDefs, true) @@ -207,7 +207,8 @@ class DefOrDclFormatterTest extends AbstractFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference(DanglingCloseParenthesis, Preserve) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(DanglingCloseParenthesis, Preserve) """def foo( | alpha: Int, @@ -247,7 +248,8 @@ class DefOrDclFormatterTest extends AbstractFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference(DanglingCloseParenthesis, Prevent) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(DanglingCloseParenthesis, Prevent) """private def foo( | alpha: Int, @@ -292,7 +294,8 @@ class DefOrDclFormatterTest extends AbstractFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference(DanglingCloseParenthesis, Force) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(DanglingCloseParenthesis, Force) """private def foo( | alpha: Int, @@ -319,10 +322,11 @@ class DefOrDclFormatterTest extends AbstractFormatterTest { """def test(test: ^^ *)""" ==> """def test(test: ^^ *)""" - def parse(parser: ScalaParser) = parser.nonLocalDefOrDcl() + def parse(parser: ScalaParser): Result = parser.nonLocalDefOrDcl() type Result = FullDefOrDcl - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0)) + def format(formatter: ScalaFormatter, result: Result): FormatResult = + formatter.format(result)(FormatterState(indentLevel = 0)) } diff --git a/scalariform/src/test/scala/scalariform/formatter/DoubleIndentConstructorArgumentsTest.scala b/scalariform/src/test/scala/scalariform/formatter/DoubleIndentConstructorArgumentsTest.scala index 8782c14c..9990e7f4 100644 --- a/scalariform/src/test/scala/scalariform/formatter/DoubleIndentConstructorArgumentsTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/DoubleIndentConstructorArgumentsTest.scala @@ -6,13 +6,15 @@ import scalariform.parser._ class DoubleIndentConstructorArgumentsTest extends AbstractFormatterTest { override val debug = false - def parse(parser: ScalaParser) = parser.nonLocalDefOrDcl() + def parse(parser: ScalaParser): Result = parser.nonLocalDefOrDcl() type Result = FullDefOrDcl - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0)) + def format(formatter: ScalaFormatter, result: Result): FormatResult = + formatter.format(result)(FormatterState(indentLevel = 0)) - implicit val formattingPreferences = FormattingPreferences.setPreference(DoubleIndentConstructorArguments, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(DoubleIndentConstructorArguments, true) """class Person( | name: String, | age: Int) diff --git a/scalariform/src/test/scala/scalariform/formatter/DoubleIndentMethodFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/DoubleIndentMethodFormatterTest.scala index 6126ba55..ba986c7f 100644 --- a/scalariform/src/test/scala/scalariform/formatter/DoubleIndentMethodFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/DoubleIndentMethodFormatterTest.scala @@ -10,7 +10,7 @@ class DoubleIndentMethodFormatterTest extends AbstractFormatterTest { { - implicit val formattingPreferences = + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference(DoubleIndentMethodDeclaration, true) // Test basic formatting for regressions. @@ -81,9 +81,10 @@ class DoubleIndentMethodFormatterTest extends AbstractFormatterTest { | b: String)""" } - def parse(parser: ScalaParser) = parser.nonLocalDefOrDcl() + def parse(parser: ScalaParser): Result = parser.nonLocalDefOrDcl() type Result = FullDefOrDcl - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0)) + def format(formatter: ScalaFormatter, result: Result): FormatResult = + formatter.format(result)(FormatterState(indentLevel = 0)) } diff --git a/scalariform/src/test/scala/scalariform/formatter/FormatterDirectiveParserTest.scala b/scalariform/src/test/scala/scalariform/formatter/FormatterDirectiveParserTest.scala index ae6311fc..19f03009 100644 --- a/scalariform/src/test/scala/scalariform/formatter/FormatterDirectiveParserTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/FormatterDirectiveParserTest.scala @@ -28,9 +28,8 @@ class FormatterDirectiveParserTest extends FlatSpec with Matchers { implicit def string2FormatTest(s: String): FormatTest = FormatTest(s.stripMargin) case class FormatTest(source: String) { - def ==>(expectedDirectives: FormatterDirective*) { + def ==>(expectedDirectives: FormatterDirective*): Unit = getDirectives(source) should be (expectedDirectives) - } } } diff --git a/scalariform/src/test/scala/scalariform/formatter/FunctionFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/FunctionFormatterTest.scala index 6f88c1aa..5afdbe42 100644 --- a/scalariform/src/test/scala/scalariform/formatter/FunctionFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/FunctionFormatterTest.scala @@ -39,8 +39,8 @@ class FunctionFormatterTest extends AbstractFormatterTest { type Result = CompilationUnit - def parse(parser: ScalaParser) = parser.compilationUnitOrScript() + def parse(parser: ScalaParser): Result = parser.compilationUnitOrScript() - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState()) + def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState()) } diff --git a/scalariform/src/test/scala/scalariform/formatter/ImportFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/ImportFormatterTest.scala index 46e56a8b..7fa6fc8f 100644 --- a/scalariform/src/test/scala/scalariform/formatter/ImportFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/ImportFormatterTest.scala @@ -7,7 +7,7 @@ import scalariform.formatter.preferences.{SpacesAroundMultiImports, FormattingPr class ImportFormatterTest extends AbstractFormatterTest { { - implicit val formattingPreferences = FormattingPreferences.setPreference( + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference( SpacesAroundMultiImports, true) "import foo . _" ==> "import foo._" @@ -23,7 +23,7 @@ class ImportFormatterTest extends AbstractFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference( + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference( SpacesAroundMultiImports, false) "import foo . _" ==> "import foo._" @@ -42,8 +42,8 @@ class ImportFormatterTest extends AbstractFormatterTest { type Result = CompilationUnit - def parse(parser: ScalaParser) = parser.compilationUnit() + def parse(parser: ScalaParser): Result = parser.compilationUnit() - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState()) + def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState()) } diff --git a/scalariform/src/test/scala/scalariform/formatter/IndentWithTabsTest.scala b/scalariform/src/test/scala/scalariform/formatter/IndentWithTabsTest.scala index f5bc604d..0c39c0b5 100644 --- a/scalariform/src/test/scala/scalariform/formatter/IndentWithTabsTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/IndentWithTabsTest.scala @@ -6,7 +6,8 @@ import scalariform.formatter.preferences._ // format: OFF class IndentWithTabsTest extends AbstractFormatterTest { - implicit val formattingPreferences = FormattingPreferences.setPreference(IndentWithTabs, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(IndentWithTabs, true) """class A { | @@ -60,7 +61,7 @@ class IndentWithTabsTest extends AbstractFormatterTest { |\tfalse)""".replace("\\t", "\t") { - implicit val formattingPreferences = FormattingPreferences + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences .setPreference(IndentWithTabs, true) .setPreference(DanglingCloseParenthesis, Force) @@ -96,7 +97,7 @@ class IndentWithTabsTest extends AbstractFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences .setPreference(IndentWithTabs, true) .setPreference(DanglingCloseParenthesis, Preserve) @@ -146,7 +147,7 @@ class IndentWithTabsTest extends AbstractFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences .setPreference(IndentWithTabs, true) .setPreference(DanglingCloseParenthesis, Prevent) @@ -185,8 +186,8 @@ class IndentWithTabsTest extends AbstractFormatterTest { type Result = CompilationUnit - def parse(parser: ScalaParser) = parser.compilationUnitOrScript + def parse(parser: ScalaParser): Result = parser.compilationUnitOrScript() - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState()) + def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState()) } diff --git a/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala index ba6a683b..a16ca45b 100644 --- a/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala @@ -115,7 +115,8 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { |}""" { - implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesWithinPatternBinders, false) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(SpacesWithinPatternBinders, false) """42 match { | case foo_ @Bar => @@ -192,7 +193,8 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { |})""" { - implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesWithinPatternBinders, false) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(SpacesWithinPatternBinders, false) """b match { |case y@ => @@ -354,7 +356,8 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { "()" ==> "()" { - implicit val formattingPreferences = FormattingPreferences.setPreference(SpaceBeforeColon, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(SpaceBeforeColon, true) "(a: Int) => 3" ==> "(a : Int) => 3" } @@ -368,7 +371,8 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { "_.a" ==> "_.a" { - implicit val formattingPreferences = FormattingPreferences.setPreference(CompactStringConcatenation, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(CompactStringConcatenation, true) """"foo"+"bar"""" ==> """"foo"+"bar"""" """"foo" + "bar"""" ==> """"foo"+"bar"""" """foo + "bar"""" ==> """foo+"bar"""" @@ -637,7 +641,8 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { { - implicit val formattingPreferences = FormattingPreferences.setPreference(PreserveSpaceBeforeArguments, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(PreserveSpaceBeforeArguments, true) "getDirectives(source) should be (expectedDirectives)" ==> "getDirectives(source) should be (expectedDirectives)" @@ -799,7 +804,8 @@ class MiscExpressionFormatterTest extends AbstractExpressionFormatterTest { | g)""" { - implicit val formattingPreferences = FormattingPreferences.setPreference(AlignArguments, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(AlignArguments, true) """Method(a, b, c)""" ==> """Method(a, b, c)""" diff --git a/scalariform/src/test/scala/scalariform/formatter/MiscFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/MiscFormatterTest.scala index 9ad2c4fd..255af8d8 100644 --- a/scalariform/src/test/scala/scalariform/formatter/MiscFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/MiscFormatterTest.scala @@ -35,10 +35,11 @@ class MiscFormatterTest extends AbstractFormatterTest { """def a(b: Int)""" ==> """def a(b: Int)""" - def parse(parser: ScalaParser) = parser.nonLocalDefOrDcl() + def parse(parser: ScalaParser): Result = parser.nonLocalDefOrDcl() type Result = FullDefOrDcl - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0)) + def format(formatter: ScalaFormatter, result: Result): FormatResult = + formatter.format(result)(FormatterState(indentLevel = 0)) } diff --git a/scalariform/src/test/scala/scalariform/formatter/MutateTest.scala b/scalariform/src/test/scala/scalariform/formatter/MutateTest.scala index 104c0e4c..937271a2 100644 --- a/scalariform/src/test/scala/scalariform/formatter/MutateTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/MutateTest.scala @@ -28,10 +28,11 @@ class MutateTest extends AbstractFormatterTest { override val debug = false - def parse(parser: ScalaParser) = parser.nonLocalDefOrDcl() + def parse(parser: ScalaParser): Result = parser.nonLocalDefOrDcl() type Result = FullDefOrDcl - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0)) + def format(formatter: ScalaFormatter, result: Result): FormatResult = + formatter.format(result)(FormatterState(indentLevel = 0)) } diff --git a/scalariform/src/test/scala/scalariform/formatter/NewlineAtEndOfFileFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/NewlineAtEndOfFileFormatterTest.scala index 3a9afd34..6c2e7d3b 100644 --- a/scalariform/src/test/scala/scalariform/formatter/NewlineAtEndOfFileFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/NewlineAtEndOfFileFormatterTest.scala @@ -8,14 +8,16 @@ class NewlineAtEndOfFileFormatterTest extends AbstractFormatterTest { type Result = CompilationUnit // Must parse as a full script to verify the newline formatting. - def parse(parser: ScalaParser) = parser.scriptBody() + def parse(parser: ScalaParser): Result = parser.scriptBody() - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState()) + def format(formatter: ScalaFormatter, result: Result): FormatResult = + formatter.format(result)(FormatterState()) override val debug = false { - implicit val formattingPreferences = FormattingPreferences.setPreference(NewlineAtEndOfFile, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(NewlineAtEndOfFile, true) // No newline; should have one added. """import foo.bar @@ -40,7 +42,8 @@ class NewlineAtEndOfFileFormatterTest extends AbstractFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference(NewlineAtEndOfFile, false) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(NewlineAtEndOfFile, false) // No newline; should stay the same. """import foo.bar diff --git a/scalariform/src/test/scala/scalariform/formatter/PackageFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/PackageFormatterTest.scala index d0353b20..46b5f5f5 100644 --- a/scalariform/src/test/scala/scalariform/formatter/PackageFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/PackageFormatterTest.scala @@ -10,9 +10,9 @@ class PackageFormatterTest extends AbstractFormatterTest { type Result = CompilationUnit - def parse(parser: ScalaParser) = parser.compilationUnit() + def parse(parser: ScalaParser): Result = parser.compilationUnit() - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState()) + def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState()) "" ==> "" @@ -47,7 +47,8 @@ class PackageFormatterTest extends AbstractFormatterTest { { - implicit val formattingPreferences = FormattingPreferences.setPreference(IndentPackageBlocks, false) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(IndentPackageBlocks, false) """package foo { |package bar { diff --git a/scalariform/src/test/scala/scalariform/formatter/ParamGroupsOnNewlineTest.scala b/scalariform/src/test/scala/scalariform/formatter/ParamGroupsOnNewlineTest.scala index 63b407a3..2aa16b05 100644 --- a/scalariform/src/test/scala/scalariform/formatter/ParamGroupsOnNewlineTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/ParamGroupsOnNewlineTest.scala @@ -7,7 +7,7 @@ import scalariform.formatter.preferences._ class ParamGroupsOnNewlineTest extends AbstractFormatterTest { { - implicit val formattingPreferences = FormattingPreferences. + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences. setPreference(AllowParamGroupsOnNewlines, true). setPreference(DanglingCloseParenthesis, Force) @@ -162,10 +162,11 @@ class ParamGroupsOnNewlineTest extends AbstractFormatterTest { override val debug = false - def parse(parser: ScalaParser) = parser.nonLocalDefOrDcl() + def parse(parser: ScalaParser): Result = parser.nonLocalDefOrDcl() type Result = FullDefOrDcl - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0)) + def format(formatter: ScalaFormatter, result: Result): FormatResult = + formatter.format(result)(FormatterState(indentLevel = 0)) } diff --git a/scalariform/src/test/scala/scalariform/formatter/ParenAndBracketSpacingTest.scala b/scalariform/src/test/scala/scalariform/formatter/ParenAndBracketSpacingTest.scala index 8b07b5fb..dc7a4871 100644 --- a/scalariform/src/test/scala/scalariform/formatter/ParenAndBracketSpacingTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/ParenAndBracketSpacingTest.scala @@ -5,7 +5,8 @@ import scalariform.formatter.preferences._ class ParenAndBracketSpacingTest extends AbstractExpressionFormatterTest { { - implicit val formattingPreferences = FormattingPreferences.setPreference(SpaceInsideParentheses, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(SpaceInsideParentheses, true) "()" ==> "()" "(a: Int) => 3" ==> "( a: Int ) => 3" "(3)" ==> "( 3 )" @@ -14,7 +15,8 @@ class ParenAndBracketSpacingTest extends AbstractExpressionFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference(SpaceInsideBrackets, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(SpaceInsideBrackets, true) "x: List[String]" ==> "x: List[ String ]" "foo[Bar](baz)" ==> "foo[ Bar ](baz)" "{ class A[B] { private[this] val bob } }" ==> "{ class A[ B ] { private[ this ] val bob } }" @@ -60,7 +62,8 @@ class ParenAndBracketSpacingTest extends AbstractExpressionFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference(DanglingCloseParenthesis, Force) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(DanglingCloseParenthesis, Force) """foo( |alpha = "foo", |beta = "bar", @@ -98,7 +101,8 @@ class ParenAndBracketSpacingTest extends AbstractExpressionFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference(DanglingCloseParenthesis, Preserve) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(DanglingCloseParenthesis, Preserve) """foo( |alpha = "foo", |beta = "bar", @@ -141,7 +145,8 @@ class ParenAndBracketSpacingTest extends AbstractExpressionFormatterTest { } { - implicit val formattingPreferences = FormattingPreferences.setPreference(DanglingCloseParenthesis, Prevent) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(DanglingCloseParenthesis, Prevent) """foo( |alpha = "foo", |beta = "bar", diff --git a/scalariform/src/test/scala/scalariform/formatter/RewriteArrowsTest.scala b/scalariform/src/test/scala/scalariform/formatter/RewriteArrowsTest.scala index 7ac301ae..f2ccb3dd 100644 --- a/scalariform/src/test/scala/scalariform/formatter/RewriteArrowsTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/RewriteArrowsTest.scala @@ -6,7 +6,8 @@ import scalariform.formatter.preferences._ class RewriteArrowsTest extends AbstractExpressionFormatterTest { { - implicit val formattingPreferences = FormattingPreferences.setPreference(RewriteArrowSymbols, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(RewriteArrowSymbols, true) "(a: Int) => 3" ==> "(a: Int) ⇒ 3" "for (i <- 1 to 10) yield i" ==> "for (i ← 1 to 10) yield i" diff --git a/scalariform/src/test/scala/scalariform/formatter/ScriptFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/ScriptFormatterTest.scala index 9de0fb0f..4cbef2c3 100644 --- a/scalariform/src/test/scala/scalariform/formatter/ScriptFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/ScriptFormatterTest.scala @@ -17,8 +17,8 @@ class ScriptFormatterTest extends AbstractFormatterTest { type Result = CompilationUnit - def parse(parser: ScalaParser) = parser.scriptBody() + def parse(parser: ScalaParser): Result = parser.scriptBody() - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState()) + def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState()) } diff --git a/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala index cccb4595..529316f4 100644 --- a/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala @@ -67,7 +67,8 @@ class TemplateFormatterTest extends AbstractFormatterTest { { -implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesWithinPatternBinders, true) +implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(SpacesWithinPatternBinders, true) "@(Id@Field) class A" ==> "@(Id @Field) class A" @@ -318,7 +319,7 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW | })""" { - implicit val formattingPreferences = FormattingPreferences. + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences. setPreference(AlignParameters, true). setPreference(SpaceBeforeColon, true). setPreference(SpaceInsideBrackets, true) @@ -339,7 +340,7 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW } { - implicit val formattingPreferences = FormattingPreferences. + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences. setPreference(AlignParameters, true). setPreference(RewriteArrowSymbols, true) @@ -385,7 +386,8 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW } { - implicit val formattingPreferences = FormattingPreferences.setPreference(AlignParameters, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(AlignParameters, true) // Make sure spacing in same line implicit parameters is preserved """class A[T](a: T)(implicit b: B)""" ==> @@ -600,7 +602,8 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW |})""" { - implicit val formattingPreferences = FormattingPreferences.setPreference(DoubleIndentClassDeclaration, true) + implicit val formattingPreferences: FormattingPreferences = + FormattingPreferences.setPreference(DoubleIndentClassDeclaration, true) """class Person( | name: String, | age: Int) @@ -826,10 +829,11 @@ implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesW override val debug = false - def parse(parser: ScalaParser) = parser.nonLocalDefOrDcl() + def parse(parser: ScalaParser): Result = parser.nonLocalDefOrDcl() type Result = FullDefOrDcl - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0)) + def format(formatter: ScalaFormatter, result: Result): FormatResult = + formatter.format(result)(FormatterState(indentLevel = 0)) } diff --git a/scalariform/src/test/scala/scalariform/formatter/TypeFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/TypeFormatterTest.scala index 97b6957e..71124e7d 100644 --- a/scalariform/src/test/scala/scalariform/formatter/TypeFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/TypeFormatterTest.scala @@ -71,8 +71,9 @@ class TypeFormatterTest extends AbstractFormatterTest { type Result = Type - def parse(parser: ScalaParser) = parser.typ() // TODO: ensure EOF + def parse(parser: ScalaParser): Result = parser.typ() // TODO: ensure EOF - def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState(indentLevel = 0)) + def format(formatter: ScalaFormatter, result: Result): FormatResult = + formatter.format(result)(FormatterState(indentLevel = 0)) } diff --git a/scalariform/src/test/scala/scalariform/formatter/XmlExpressionFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/XmlExpressionFormatterTest.scala index 4814ec4c..f2d49a6c 100644 --- a/scalariform/src/test/scala/scalariform/formatter/XmlExpressionFormatterTest.scala +++ b/scalariform/src/test/scala/scalariform/formatter/XmlExpressionFormatterTest.scala @@ -241,7 +241,7 @@ class XmlExpressionFormatterTest extends AbstractExpressionFormatterTest { |}""" { - implicit val formattingPreferences = FormattingPreferences.setPreference(FormatXml, false) + implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference(FormatXml, false) """ |b""" ==> diff --git a/scalariform/src/test/scala/scalariform/lexer/NewlineInferencerTest.scala b/scalariform/src/test/scala/scalariform/lexer/NewlineInferencerTest.scala index 98673848..b1e1bd32 100644 --- a/scalariform/src/test/scala/scalariform/lexer/NewlineInferencerTest.scala +++ b/scalariform/src/test/scala/scalariform/lexer/NewlineInferencerTest.scala @@ -9,7 +9,8 @@ import org.scalatest.{FlatSpec, Matchers} */ class NewlineInferencerTest extends FlatSpec with Matchers { - implicit def string2TestString(s: String)(implicit forgiveErrors: Boolean = false, scalaVersion: ScalaVersion = ScalaVersions.DEFAULT) = + implicit def string2TestString(s: String)(implicit forgiveErrors: Boolean = false, + scalaVersion: ScalaVersion = ScalaVersions.DEFAULT): TestString = new TestString(s, forgiveErrors, scalaVersion) // See issue #60 @@ -27,11 +28,10 @@ class NewlineInferencerTest extends FlatSpec with Matchers { class TestString(s: String, forgiveErrors: Boolean = false, scalaVersion: ScalaVersion = ScalaVersions.DEFAULT) { - def shouldProduceTokens(toks: TokenType*)() { + def shouldProduceTokens(toks: TokenType*)(): Unit = check(s.stripMargin, toks.toList) - } - private def check(s: String, expectedTokens: List[TokenType]) { + private def check(s: String, expectedTokens: List[TokenType]): Unit = it should ("tokenise >>>" + s + "<<< as >>>" + expectedTokens + "<<< forgiveErrors = " + forgiveErrors + ", scalaVersion = " + scalaVersion) in { val actualTokens: List[Token] = ScalaLexer.tokenise(s, forgiveErrors, scalaVersion.toString) val actualTokenTypes = actualTokens.map(_.tokenType) @@ -39,7 +39,6 @@ class NewlineInferencerTest extends FlatSpec with Matchers { require(actualTokenTypes.count(_ == EOF) == 1, "There must only be one EOF token") require(actualTokenTypes.init == expectedTokens, "Tokens do not match. Expected " + expectedTokens + ", but was " + actualTokenTypes.init) } - } } diff --git a/scalariform/src/test/scala/scalariform/lexer/RedundantSemicolonDetectorTest.scala b/scalariform/src/test/scala/scalariform/lexer/RedundantSemicolonDetectorTest.scala index 40f7cae1..eb838832 100644 --- a/scalariform/src/test/scala/scalariform/lexer/RedundantSemicolonDetectorTest.scala +++ b/scalariform/src/test/scala/scalariform/lexer/RedundantSemicolonDetectorTest.scala @@ -7,21 +7,21 @@ import org.scalatest.{FlatSpec, Matchers} class RedundantSemicolonDetectorTest extends FlatSpec with Matchers { - implicit def stringToCheckable(s: String)(implicit scalaVersion: String = ScalaVersions.DEFAULT_VERSION) = - new { def check() = checkSemis(s, scalaVersion) }; // Expected redundant semicolons are indicated with <;> + implicit def stringToCheckable(s: String)(implicit scalaVersion: String = ScalaVersions.DEFAULT_VERSION): Any { def check(): Unit } = + new { def check(): Unit = checkSemis(s, scalaVersion) } // Expected redundant semicolons are indicated with <;> """ class A { def foo = 42<;> def bar = 123; def baz = 1234 }<;> - """.check(); + """.check() """ { println("Foo")<;> } - """.check(); + """.check() """ class A { @@ -33,13 +33,13 @@ class RedundantSemicolonDetectorTest extends FlatSpec with Matchers { """.check() { - implicit val scalaVersion = "2.10.0"; + implicit val scalaVersion: String = "2.10.0" """ s"my name is ?{person.name<;>}" - """.replace('?', '$').check + """.replace('?', '$').check() } - private def checkSemis(encodedSource: String, scalaVersion: String) { + private def checkSemis(encodedSource: String, scalaVersion: String): Unit = { val ordinarySource = encodedSource.replace("<;>", ";") val semis = RedundantSemicolonDetector.findRedundantSemis(ordinarySource, scalaVersion) val encodedSourceAgain = semis.reverse.foldLeft(ordinarySource) { (s, semi) ⇒ replaceRange(s, semi.range, "<;>") } diff --git a/scalariform/src/test/scala/scalariform/lexer/ScalaLexerTest.scala b/scalariform/src/test/scala/scalariform/lexer/ScalaLexerTest.scala index b97db1e0..80744ab8 100644 --- a/scalariform/src/test/scala/scalariform/lexer/ScalaLexerTest.scala +++ b/scalariform/src/test/scala/scalariform/lexer/ScalaLexerTest.scala @@ -6,7 +6,8 @@ import org.scalatest.{FlatSpec, Matchers} class ScalaLexerTest extends FlatSpec with Matchers { - implicit def string2TestString(s: String)(implicit forgiveErrors: Boolean = false, scalaVersion: ScalaVersion = ScalaVersions.DEFAULT) = + implicit def string2TestString(s: String)(implicit forgiveErrors: Boolean = false, + scalaVersion: ScalaVersion = ScalaVersions.DEFAULT): TestString = new TestString(s, forgiveErrors, scalaVersion) "" producesTokens () @@ -99,26 +100,26 @@ class ScalaLexerTest extends FlatSpec with Matchers { "42.toString" producesTokens (INTEGER_LITERAL, DOT, VARID) { - implicit val scalaVersion = ScalaVersions.Scala_2_9 + implicit val scalaVersion: ScalaVersion = ScalaVersions.Scala_2_9 "5.f" producesTokens (FLOATING_POINT_LITERAL) "5.d" producesTokens (FLOATING_POINT_LITERAL) "5." producesTokens (FLOATING_POINT_LITERAL) } { - implicit val scalaVersion = ScalaVersions.Scala_2_11 + implicit val scalaVersion: ScalaVersion = ScalaVersions.Scala_2_11 "5.f" producesTokens (INTEGER_LITERAL, DOT, VARID) "5.d" producesTokens (INTEGER_LITERAL, DOT, VARID) "5." producesTokens (INTEGER_LITERAL, DOT) } { - implicit val scalaVersion = ScalaVersions.Scala_2_9 + implicit val scalaVersion: ScalaVersion = ScalaVersions.Scala_2_9 """ X s"" """ producesTokens (WS, VARID, WS, VARID, STRING_LITERAL, WS) } { - implicit val scalaVersion = ScalaVersions.Scala_2_10 + implicit val scalaVersion: ScalaVersion = ScalaVersions.Scala_2_10 """ X s"" """ producesTokens (WS, VARID, WS, INTERPOLATION_ID, STRING_LITERAL, WS) """ X s "$foo" """ producesTokens (WS, VARID, WS, VARID, WS, STRING_LITERAL, WS) """ s"$foo" """ producesTokens (WS, INTERPOLATION_ID, STRING_PART, VARID, STRING_LITERAL, WS) @@ -247,7 +248,7 @@ println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VAR } { - implicit val forgiveErrors = true + implicit val forgiveErrors: Boolean = true "\"\"\"" producesTokens (STRING_LITERAL) "'" producesTokens (CHARACTER_LITERAL) @@ -261,11 +262,10 @@ println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VAR class TestString(s: String, forgiveErrors: Boolean = false, scalaVersion: ScalaVersion = ScalaVersions.DEFAULT) { - def producesTokens(toks: TokenType*)() { + def producesTokens(toks: TokenType*)(): Unit = check(s.stripMargin, toks.toList) - } - private def check(s: String, expectedTokens: List[TokenType]) { + private def check(s: String, expectedTokens: List[TokenType]): Unit = it should ("tokenise >>>" + s + "<<< as >>>" + expectedTokens + "<<< forgiveErrors = " + forgiveErrors + ", scalaVersion = " + scalaVersion) in { val actualTokens: List[Token] = ScalaLexer.rawTokenise(s, forgiveErrors, scalaVersion.toString) val actualTokenTypes = actualTokens.map(_.tokenType) @@ -275,7 +275,6 @@ println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VAR require(actualTokenTypes.init == expectedTokens, "Tokens do not match. Expected " + expectedTokens + ", but was " + actualTokenTypes.init) require(s == reconstitutedSource, "tokens do not partition text correctly: " + s + " vs " + reconstitutedSource) } - } } diff --git a/scalariform/src/test/scala/scalariform/parser/ParserTest.scala b/scalariform/src/test/scala/scalariform/parser/ParserTest.scala index 3cbcb365..96b3dda8 100644 --- a/scalariform/src/test/scala/scalariform/parser/ParserTest.scala +++ b/scalariform/src/test/scala/scalariform/parser/ParserTest.scala @@ -54,7 +54,7 @@ class ParserTest extends FlatSpec with Matchers { } private def parser(s: String) = new ScalaParser(ScalaLexer.tokenise(s).toArray) - private def parseExpression(s: String) = parser(s).expr - private def parseCompilationUnit(s: String) = parser(s).compilationUnit + private def parseExpression(s: String) = parser(s).expr() + private def parseCompilationUnit(s: String) = parser(s).compilationUnit() }