Skip to content

Commit

Permalink
Reformat with 0.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Feb 2, 2017
1 parent 8342379 commit dedaf9e
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 61 deletions.
2 changes: 0 additions & 2 deletions bin/scalafmt

This file was deleted.

13 changes: 6 additions & 7 deletions core/src/main/scala/org/scalafmt/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 5 additions & 6 deletions core/src/main/scala/org/scalafmt/config/hocon/Hocon2Class.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
22 changes: 10 additions & 12 deletions core/src/main/scala/org/scalafmt/internal/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/org/scalafmt/rewrite/Patch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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 {
Expand Down
44 changes: 21 additions & 23 deletions core/src/main/scala/org/scalafmt/rewrite/SortImports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 2 additions & 1 deletion core/src/test/scala/org/scalafmt/util/FormatAssertions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Binary file modified scalafmt
Binary file not shown.
8 changes: 3 additions & 5 deletions utils/src/main/scala/org/scalafmt/util/GitOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit dedaf9e

Please sign in to comment.