Skip to content

Commit

Permalink
Merge pull request #600 from jchyb/fix/format-check
Browse files Browse the repository at this point in the history
Fix #588: fmt --check not being passed to scalafmt
  • Loading branch information
jchyb authored Feb 1, 2022
2 parents f9a1087 + 4a6f227 commit 868e6b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules/cli/src/main/scala/scala/cli/commands/Fmt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ object Fmt extends ScalaCommand[FmtOptions] {
val command = Seq(fmtLauncher.toString) ++
sourceFiles.map(_.toString) ++
dialectArgs ++
options.scalafmtArg
options.scalafmtCliOptions
Runner.run(
"scalafmt",
command,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ final case class FmtOptions(
def buildOptions: BuildOptions =
shared.buildOptions(enableJmh = false, jmhVersion = None, ignoreErrors = false)

def scalafmtCliOptions: List[String] =
scalafmtArg ::: (if (check) List("--check") else Nil)

}

object FmtOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import com.eed3si9n.expecty.Expecty.expect

class FmtTests extends munit.FunSuite {

val simpleInputsUnformattedContent =
"""package foo
|
| object Foo extends java.lang.Object {
| def get() = 2
| }
|""".stripMargin
val simpleInputs = TestInputs(
Seq(
os.rel / ".scalafmt.conf" ->
"""runner.dialect = scala213
|""".stripMargin,
os.rel / "Foo.scala" ->
"""package foo
|
| object Foo extends java.lang.Object {
| def get() = 2
| }
|""".stripMargin
os.rel / "Foo.scala" -> simpleInputsUnformattedContent
)
)
val expectedSimpleInputsFormattedContent = noCrLf {
Expand Down Expand Up @@ -46,4 +47,13 @@ class FmtTests extends munit.FunSuite {
}
}

test("with --check") {
simpleInputs.fromRoot { root =>
val out = os.proc(TestUtil.cli, "fmt", "--check").call(cwd = root, check = false).out.text()
val updatedContent = noCrLf(os.read(root / "Foo.scala"))
expect(updatedContent == noCrLf(simpleInputsUnformattedContent))
expect(noCrLf(out) == "error: --test failed\n")
}
}

}

0 comments on commit 868e6b3

Please sign in to comment.