代码之家  ›  专栏  ›  技术社区  ›  softshipper

在-Xfatal warnings下不能产生任何警告

  •  0
  • softshipper  · 技术社区  · 6 年前

    我想把包裹导入 sbt console 具体如下:

    scala> import cats.instances.string
    <console>:11: warning: Unused import
           import cats.instances.string
                                 ^
    error: No warnings can be incurred under -Xfatal-warnings. 
    

    你可以看到,我收到了一条错误信息。

    的内容 build.sbt

    scalaVersion := "2.12.8"
    
    scalacOptions ++= Seq(
      "-encoding", "UTF-8",   // source files are in UTF-8
      "-deprecation",         // warn about use of deprecated APIs
      "-unchecked",           // warn about unchecked type parameters
      "-feature",             // warn about misused language features
      "-language:higherKinds",// allow higher kinded types without `import scala.language.higherKinds`
      "-Xlint",               // enable handy linter warnings
      "-Xfatal-warnings",     // turn compiler warnings into errors
      "-Ypartial-unification" // allow the compiler to unify type constructors of different arities
    )
    
    libraryDependencies += "org.typelevel" %% "cats-core" % "1.4.0"
    libraryDependencies += "org.tpolecat" %% "atto-core"    % "0.6.5"
    libraryDependencies += "org.tpolecat" %% "atto-refined" % "0.6.5"
    
    addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.3")
    

    我做错什么了?

    0 回复  |  直到 6 年前
        1
  •  3
  •   Travis Brown    6 年前

    在这种情况下,最好的解决办法是 -Xlint 从用于控制台的Scala选项中:

    scalaVersion := "2.12.8"
    scalacOptions ++= Seq(
      "-Xlint",
      "-Xfatal-warnings"
    )
    
    scalacOptions in (Compile, console) ~= {
      _.filterNot(Set("-Xlint"))
    }
    
    libraryDependencies += "org.typelevel" %% "cats-core" % "1.6.0"
    

    使用此配置,项目中的任何源代码都将使用 -Xlint公司