From dedaf9eaf602c6960fe159bbd9b24d913db6256a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93lafur=20P=C3=A1ll=20Geirsson?= Date: Thu, 2 Feb 2017 11:06:33 +0100 Subject: [PATCH] Reformat with 0.5.5 --- bin/scalafmt | 2 - .../scala/org/scalafmt/config/Config.scala | 13 +++--- .../scalafmt/config/hocon/Hocon2Class.scala | 11 ++--- .../scala/org/scalafmt/internal/Router.scala | 22 ++++----- .../scala/org/scalafmt/rewrite/Patch.scala | 2 +- .../scalafmt/rewrite/RedundantBraces.scala | 6 ++- .../org/scalafmt/rewrite/SortImports.scala | 44 +++++++++--------- .../org/scalafmt/util/FormatAssertions.scala | 3 +- .../org/scalafmt/intellij/IdeaUtils.scala | 2 +- project/plugins.sbt | 2 +- scalafmt | Bin 12615 -> 12523 bytes .../main/scala/org/scalafmt/util/GitOps.scala | 8 ++-- 12 files changed, 54 insertions(+), 61 deletions(-) delete mode 100644 bin/scalafmt diff --git a/bin/scalafmt b/bin/scalafmt deleted file mode 100644 index b32c137bf9..0000000000 --- a/bin/scalafmt +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -java -jar PATH_TO/scalafmt.jar $@ diff --git a/core/src/main/scala/org/scalafmt/config/Config.scala b/core/src/main/scala/org/scalafmt/config/Config.scala index 570132b956..6b5b5a51b0 100644 --- a/core/src/main/scala/org/scalafmt/config/Config.scala +++ b/core/src/main/scala/org/scalafmt/config/Config.scala @@ -14,13 +14,12 @@ object Config { def toHocon(any: Any): Seq[String] = any match { case String2AnyMap(m) => m.flatMap { - case (k, v) => - toHocon(v).map { x => - if (x.startsWith(" ")) s"$k$x" - else s"$k.$x" - } - } - .toSeq + case (k, v) => + toHocon(v).map { x => + if (x.startsWith(" ")) s"$k$x" + else s"$k.$x" + } + }.toSeq case x: HasFields => toHocon(x.fields) case x: Traversable[_] => Seq( diff --git a/core/src/main/scala/org/scalafmt/config/hocon/Hocon2Class.scala b/core/src/main/scala/org/scalafmt/config/hocon/Hocon2Class.scala index 193f66d006..db4a6be515 100644 --- a/core/src/main/scala/org/scalafmt/config/hocon/Hocon2Class.scala +++ b/core/src/main/scala/org/scalafmt/config/hocon/Hocon2Class.scala @@ -11,11 +11,9 @@ object Hocon2Class { import scala.collection.JavaConverters._ def loop(obj: Any): Any = obj match { case map: java.util.Map[_, _] => - map.asScala - .map { - case (key, value) => key -> loop(value) - } - .toMap + map.asScala.map { + case (key, value) => key -> loop(value) + }.toMap case map: java.util.List[_] => map.asScala.map(loop).toList case e => e @@ -29,7 +27,8 @@ object Hocon2Class { try { val config = ConfigFactory.parseString(str) val extracted = path match { - case Some(p) => config.getConfig(p).resolve(ConfigResolveOptions.noSystem) + case Some(p) => + config.getConfig(p).resolve(ConfigResolveOptions.noSystem) case _ => config } Right(config2map(extracted)) diff --git a/core/src/main/scala/org/scalafmt/internal/Router.scala b/core/src/main/scala/org/scalafmt/internal/Router.scala index 48021946de..b35d91b23a 100644 --- a/core/src/main/scala/org/scalafmt/internal/Router.scala +++ b/core/src/main/scala/org/scalafmt/internal/Router.scala @@ -427,8 +427,8 @@ class Router(formatOps: FormatOps) { case _ => None } val lastParen = loop(open).get // find the last param on the def - // so that we can apply our `policy` till - // the end. + // so that we can apply our `policy` till + // the end. // Our policy is a combination of OneArgLineSplit and a custom splitter // for parameter groups. @@ -437,21 +437,19 @@ class Router(formatOps: FormatOps) { // Indent seperators `)(` by `indentSep` case Decision(t @ FormatToken(_, rp @ RightParen(), _), _) => Decision(t, - Seq( - Split(Newline, 0) - .withIndent(indentSep, rp, Left) - ) - ) + Seq( + Split(Newline, 0) + .withIndent(indentSep, rp, Left) + )) // Do NOT Newline the first param after the split `)(`. But let // following ones get newlined by the oneLinePerArg policy. case Decision(t @ FormatToken(open2 @ LeftParen(), _, _), _) => val close2 = matchingParentheses(hash(open2)) Decision(t, - Seq( - Split(NoSplit, 0) - .withIndent(indentParam, close2, Right) - ) - ) + Seq( + Split(NoSplit, 0) + .withIndent(indentParam, close2, Right) + )) } val policy = diff --git a/core/src/main/scala/org/scalafmt/rewrite/Patch.scala b/core/src/main/scala/org/scalafmt/rewrite/Patch.scala index 2006e16d71..b04146cb57 100644 --- a/core/src/main/scala/org/scalafmt/rewrite/Patch.scala +++ b/core/src/main/scala/org/scalafmt/rewrite/Patch.scala @@ -12,7 +12,7 @@ case class Patch(from: Token, to: Token, replace: String) { token.input.eq(from.input) && token.end <= to.end && token.start >= from.start - + val tokens = replace.tokenize.get.tokens.toSeq def runOn(str: Seq[Token]): Seq[Token] = { str.flatMap { diff --git a/core/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala b/core/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala index 9b25bc211d..d970f66832 100644 --- a/core/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala +++ b/core/src/main/scala/org/scalafmt/rewrite/RedundantBraces.scala @@ -46,7 +46,8 @@ object RedundantBraces extends Rewrite { bodyIsNotTooBig } - def isIdentifierAtStart(value: String) = value.nonEmpty && (Character.isLetterOrDigit(value.head) || value.head == '_') + def isIdentifierAtStart(value: String) = + value.nonEmpty && (Character.isLetterOrDigit(value.head) || value.head == '_') override def rewrite(code: Tree, ctx: RewriteCtx): Seq[Patch] = { import ctx.tokenTraverser._ @@ -55,7 +56,8 @@ object RedundantBraces extends Rewrite { code.collect { case t: Term.Interpolate if settings.stringInterpolation => t.parts.tail.zip(t.args).collect { - case (Lit(value: String), arg @ Term.Name(name)) if !isIdentifierAtStart(value) => + case (Lit(value: String), arg @ Term.Name(name)) + if !isIdentifierAtStart(value) => val openBrace = prevToken(arg.tokens.head) val closeBrace = nextToken(arg.tokens.head) (openBrace, closeBrace) match { diff --git a/core/src/main/scala/org/scalafmt/rewrite/SortImports.scala b/core/src/main/scala/org/scalafmt/rewrite/SortImports.scala index 34dc610dcd..ecb1c116c7 100644 --- a/core/src/main/scala/org/scalafmt/rewrite/SortImports.scala +++ b/core/src/main/scala/org/scalafmt/rewrite/SortImports.scala @@ -36,30 +36,28 @@ object SortImports extends Rewrite { } override def rewrite(code: Tree, ctx: RewriteCtx): Seq[Patch] = { - code - .collect { - case q"import ..$imports" => - imports.flatMap { `import` => - if (`import`.importees.exists(!_.is[Importee.Name])) { - // Do nothing if an importee has for example rename - // import a.{d, b => c} - // I think we are safe to sort these, just want to convince myself - // it's 100% safe first. - Nil - } else { - val sortedImporteesByIndex: Map[Int, String] = - sorted(`import`.importees.map(_.syntax)).zipWithIndex - .map(_.swap) - .toMap - `import`.importees.zipWithIndex.collect { - case (importee, i) => - Patch(importee.tokens.head, - importee.tokens.last, - sortedImporteesByIndex(i)) - } + code.collect { + case q"import ..$imports" => + imports.flatMap { `import` => + if (`import`.importees.exists(!_.is[Importee.Name])) { + // Do nothing if an importee has for example rename + // import a.{d, b => c} + // I think we are safe to sort these, just want to convince myself + // it's 100% safe first. + Nil + } else { + val sortedImporteesByIndex: Map[Int, String] = + sorted(`import`.importees.map(_.syntax)).zipWithIndex + .map(_.swap) + .toMap + `import`.importees.zipWithIndex.collect { + case (importee, i) => + Patch(importee.tokens.head, + importee.tokens.last, + sortedImporteesByIndex(i)) } } - } - .flatten + } + }.flatten } } diff --git a/core/src/test/scala/org/scalafmt/util/FormatAssertions.scala b/core/src/test/scala/org/scalafmt/util/FormatAssertions.scala index 0a33ed0528..50af5b9e11 100644 --- a/core/src/test/scala/org/scalafmt/util/FormatAssertions.scala +++ b/core/src/test/scala/org/scalafmt/util/FormatAssertions.scala @@ -14,7 +14,8 @@ import org.scalatest.FunSuiteLike trait FormatAssertions extends FunSuiteLike with DiffAssertions { def assertFormatPreservesAst[T <: Tree](original: String, obtained: String)( - implicit ev: Parse[T], dialect: Dialect): Unit = { + implicit ev: Parse[T], + dialect: Dialect): Unit = { import scala.meta._ original.parse[T] match { case Parsed.Error(pos, message, details) => diff --git a/intellij/src/main/scala/org/scalafmt/intellij/IdeaUtils.scala b/intellij/src/main/scala/org/scalafmt/intellij/IdeaUtils.scala index 82f2855a5c..3a5ec736dc 100644 --- a/intellij/src/main/scala/org/scalafmt/intellij/IdeaUtils.scala +++ b/intellij/src/main/scala/org/scalafmt/intellij/IdeaUtils.scala @@ -21,7 +21,7 @@ object IdeaUtils { val PluginName = "Scalafmt" - def displayMessage(msg: String, notificationType: NotificationType): Unit = + def displayMessage(msg: String, notificationType: NotificationType): Unit = Notifications.Bus.notify( new Notification(PluginName, PluginName, diff --git a/project/plugins.sbt b/project/plugins.sbt index b8d6d1cd50..6f6564fa9a 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,6 @@ resolvers ++= Seq( Classpaths.sbtPluginReleases, - Resolver.bintrayIvyRepo("dancingrobot84","sbt-plugins") + Resolver.bintrayIvyRepo("dancingrobot84", "sbt-plugins") ) addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1") diff --git a/scalafmt b/scalafmt index d31bb50b9f0a8ce90201037a12babf91e7885e2e..df84cee2867046908c5e36d3dbb8776e7a5b19ae 100755 GIT binary patch delta 1292 zcmX?}^g3~Z8SlG1DbFm!S%E7V7#MmcIxE)ihvUMw4G0k$WGfoLKe7juo z&E06JH-)VPs%n zpL{_3cepoNU^7;*PMGoo7AEoqG z>|7Ysaxt#Nd3JM?lx)Xlme!q{-&fB|ReH?6uUnG4r=Gz!^gs9WW#62OgtnNr{$_Jp z=(uXr)iX-56OQ!l|D@BXb6_dAMr33CPOrd*Qr-!!*Q{3NeJj8B>hl{B?qF|m&84ev zP4+)&vabHyFZQ}GAOA3l9T2)|QL=KjSznFIH1>I2S}P63WKZmh)d`%m)vepl!hF|+ zr?wB2?Uzkq-F2_vhH_Vu#NxG<7N0w#{;8beygS1^V(ALm(^F;CjUJvho~irlX3@Q% z6T$V5+Y0XetWBC*TAq8ssd14$$NX*AckJEpVN(|SOeR~Nr=1P!78xInPdZVxW1rQY z=eJ%IruLlJwQ9%vS*E&AXUzUAu;%}}DVrRw|CV)2K5cmC#jeXUM53LhheyBpwVG9X zf7D}xtV1ICd4-?Cd-hvh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fjU?2779S zeu-KOFhX;H9z#`FrvX-2s?VyK%K2X7bFA#MY1V5 diff --git a/utils/src/main/scala/org/scalafmt/util/GitOps.scala b/utils/src/main/scala/org/scalafmt/util/GitOps.scala index ebc650ba44..46fb257a41 100644 --- a/utils/src/main/scala/org/scalafmt/util/GitOps.scala +++ b/utils/src/main/scala/org/scalafmt/util/GitOps.scala @@ -70,10 +70,8 @@ class GitOpsImpl(workingDirectory: AbsoluteFile) extends GitOps { "--name-only", "HEAD", branch - )).lines - .map { x => - AbsoluteFile.fromFile(new File(x), workingDirectory) - } - .toSeq + )).lines.map { x => + AbsoluteFile.fromFile(new File(x), workingDirectory) + }.toSeq } }