Skip to content

Commit

Permalink
Merge pull request #1093 from yln/nop-check-with-diff-and-stdin
Browse files Browse the repository at this point in the history
Empty input with `--diff` and `--stdin` is okay
  • Loading branch information
olafurpg committed Dec 18, 2017
2 parents 7ab027d + e4117fc commit a20d612
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion scalafmt-cli/src/main/scala/org/scalafmt/cli/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ object Cli {

def run(options: CliOptions): Unit = {
val inputMethods = getInputMethods(options)
if (inputMethods.isEmpty) throw NoMatchingFiles
if (inputMethods.isEmpty && options.diff.isEmpty && !options.stdIn)
throw NoMatchingFiles
val counter = new AtomicInteger()
val termDisplayMessage =
if (options.testing) "Looking for unformatted files..."
Expand Down
4 changes: 1 addition & 3 deletions scalafmt-core/shared/src/main/scala/org/scalafmt/Error.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.scalafmt
import scala.meta.Case
import scala.meta.Tree
import scala.meta.tokens.Token
import scala.meta.tokens.Token
import scala.reflect.ClassTag
import scala.reflect.classTag

Expand Down Expand Up @@ -81,8 +80,7 @@ object Error {
case object NoMatchingFiles
extends Error(
"No files formatted/tested. " +
"Verify your configured include/exclude filters and " +
"supplied command line arguments.")
"Verify include/exclude filters and command line arguments.")

case class InvalidOption(option: String)
extends Error(s"Invalid option $option")
Expand Down
12 changes: 10 additions & 2 deletions scalafmt-tests/src/test/scala/org/scalafmt/cli/CliTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.scalafmt.cli

import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileNotFoundException
import java.io.PrintStream
import java.nio.charset.StandardCharsets
Expand All @@ -24,7 +23,7 @@ import FileTestOps._
abstract class AbstractCliTest extends FunSuite with DiffAssertions {

def mkArgs(str: String): Array[String] =
str.split(' ').toArray
str.split(' ')

def runWith(root: AbsoluteFile, argStr: String): Unit = {
val args = mkArgs(argStr)
Expand Down Expand Up @@ -280,6 +279,15 @@ class CliTest extends AbstractCliTest {
}
}

test("scalafmt (no matching files) is okay with --diff and --stdin") {
val diff = getConfig(Array("--diff"))
val stdin = getConfig(Array("--stdin")).copy(
common = CommonOptions(in = new ByteArrayInputStream("".getBytes))
)
Cli.run(diff)
Cli.run(stdin)
}

test("scalafmt (no arg) read config from git repo") {
val input = string2dir(
"""|/foo.scala
Expand Down

0 comments on commit a20d612

Please sign in to comment.