scalafmt: Getting meaningful error messages

1k Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

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.