【问题标题】:scalafmt: Getting meaningful error messagesscalafmt:获取有意义的错误消息
【发布时间】:2020-08-03 21:22:20
【问题描述】:

我正在使用“scalafmt”命令来确保我的 Scala 代码中没有格式错误。它一直失败并显示此错误消息:

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

这是最后两行。日志中没有其他错误消息。有没有我可以使用的配置来为我提供有关此故障的更多信息?

【问题讨论】:

    标签: scala scalastyle scalafmt


    【解决方案1】:

    默认情况下,Scalafmt 错误会报告给 System.err。扩展 org.scalafmt.interfaces.ScalafmtReporter 以自定义错误报告以处理解析和配置错误。

        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))
            }
        }
    

    检查:https://scalameta.org/scalafmt/docs/installation.html

    【讨论】:

      猜你喜欢
      • 2012-07-24
      • 2011-02-08
      • 2020-01-26
      • 1970-01-01
      • 2016-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-31
      相关资源
      最近更新 更多