Skip to content

Commit

Permalink
Handle diffs in non-scala files
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Nov 14, 2016
1 parent 3772f39 commit 1532643
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cli/src/main/scala/org/scalafmt/cli/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ object Cli {
"Unable to read diff. Specify --stdin enable project.git=true")
}
val fileDiffs = FileDiff.fromUnified(unifiedDiff)
fileDiffs.map { fd =>
fileDiffs.withFilter(x => canFormat(x.filename)).map { fd =>
val path =
AbsoluteFile.fromFile(new File(fd.filename),
options.common.workingDirectory)
Expand Down
71 changes: 44 additions & 27 deletions cli/src/test/scala/org/scalafmt/cli/CliTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,47 @@ class CliDiffTest extends AbstractCliTest with DiffAssertions {
|+ val x=1
""".stripMargin
)
check(
// no diff
"""|/edited.scala
|object A {
| val x=2 }
|""".stripMargin,
"""|/edited.scala
|object A {
| val x=2 }
|""".stripMargin,
""
)
check(
// 2 diffs
"""|/edited.scala
|object A {
| val x=1
| val y=2
| val z=3
|}
|""".stripMargin,
"""|/edited.scala
|object A {
| val x = 1
| val y=2
| val z = 3
|}
|""".stripMargin,
"""|--- a/edited.scala
|+++ b/edited.scala
|@@ -2,1 +2,1 @@ foo
|- val a=1
|+ val x = 1
|@@ -4,1 +4,1 @@ foo
|- val b=3
|+ val z = 3
""".stripMargin
)

check( // 2 diffs
"""|/edited.scala
|object A {
| val x=1
| val y=2
| val z=3
|}
|""".stripMargin,
"""|/edited.scala
|object A {
| val x = 1
| val y=2
| val z = 3
|}
|""".stripMargin,
"""|--- a/edited.scala
|+++ b/edited.scala
|@@ -2,1 +2,1 @@ foo
|- val a=1
|+ val x = 1
|@@ -4,1 +4,1 @@ foo
|- val b=3
|+ val z = 3
""".stripMargin)

check( // leave untouched comments alone
check(
// leave untouched comments alone
"""|/edited.scala
| /*
| * banana
Expand All @@ -110,7 +124,10 @@ class CliDiffTest extends AbstractCliTest with DiffAssertions {
|@@ -5,1 +5,1 @@ foo
|- val a=1
|+ val x = 1
""".stripMargin)
""".stripMargin
)
// TODO(olafur) argument list
// TODO(olafur) argument indentation
}

class CliTest extends AbstractCliTest with DiffAssertions {
Expand Down

0 comments on commit 1532643

Please sign in to comment.