1

I am using 'scalafmt' command to ensure that I've no formatting errors in my Scala code. It keeps failing with this error message:

Looking for unformatted files... (98.35 %, 238 / 242)
error: --test failed

Those are the last two lines. There's no other error message in the log. Is there a configuration I can use that will give me more information about this failure?

DilTeam
  • 2,551
  • 9
  • 42
  • 69

2 Answers2

1

By default, Scalafmt errors are reported to System.err. Extend org.scalafmt.interfaces.ScalafmtReporter to customize error reporting to handle parse and config errors.

    class ScalafmtErrReport(out: PrintStream) extends ScalafmtReporter {
        override def error(file: Path, e: Throwable): Unit = {
            out.print(s"error: $file: ")
            trimStacktrace(e)
            e.printStackTrace(out)
        }

        override def error(path: Path, message: String): Unit = {
            out.println(s"error: $path: $message")
        }

        override def error(file: Path, message: String, e: Throwable): Unit = {
            error(file, ScalafmtException(message, e))
        }
    }

check: https://scalameta.org/scalafmt/docs/installation.html

Rex
  • 558
  • 2
  • 9
0

If you run scalafmt --test from the command line it will give you a diff between what you have and what it thinks you should have. Unfortunately it only shows you the difference, and not which rule indicated the change.

Adam Mackler
  • 1,980
  • 1
  • 18
  • 32