Scala 静态分析工具的现状如何?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22617713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the current state of static analysis tools for Scala?
提问by marekinfo
I saw a StackOverflow question regarding static analysis in Scala, but that one was answered in 2009. As you know, the Scala tools are changing very rapidly.
我在 StackOverflow 上看到了一个关于 Scala 静态分析的问题,但那个问题在 2009 年得到了回答。如您所知,Scala 工具正在快速变化。
I was therefore wondering if someone familiar with the current state of static analysis tools in Scala could tell me if there's, say, a Findbugs equivalent for Scala. I found that Findbugs issues many unnecessary warnings for Scala, probably having to do with the way the "object" singleton compiles to bytecode, due to traits, etc. I heard that Scalastyle is not only a Scala version of Java's CheckStyle, that it also includes bits of Findbugs and PMD. But if it doesn't implement all of Findbugs and/or PMD, then are there other tools that supplement it? Or, is Scalastyle good not only for style checking, but is it good for improving code quality?
因此,我想知道是否有人熟悉 Scala 中静态分析工具的当前状态,可以告诉我是否有与 Scala 等效的 Findbugs。我发现 Findbugs 为 Scala 发出了许多不必要的警告,可能与“对象”单例编译为字节码的方式有关,由于特征等。我听说 Scalastyle 不仅是 Java 的 CheckStyle 的 Scala 版本,它还包括一些 Findbugs 和 PMD。但是如果它没有实现所有的 Findbugs 和/或 PMD,那么还有其他工具可以补充它吗?或者,Scalastyle 不仅适用于样式检查,还适用于提高代码质量吗?
Also, what about Scala's integration with, say, Sonar? Is the Scala Sonar plugin (which works with Scalastyle) reliable?
另外,Scala 与 Sonar 的集成怎么样?Scala 声纳插件(与 Scalastyle 一起使用)可靠吗?
回答by monkHyman
Here is an updated answer as of August 2014 for some that are aimed or work well with Scala.
这是截至 2014 年 8 月针对一些针对 Scala 或与 Scala 配合良好的更新答案。
Personally I think the JVM or Java ones end up with far too many false positives, or have inspections that are aimed mostly at Java specific classes. For example, since in Scala we don't tend to use the Java Collections, all the findbugs collection based inspections are not needed. Another example is the inspections for use of static fields which are irrelevant in Scala.
我个人认为 JVM 或 Java 最终会出现太多误报,或者进行主要针对 Java 特定类的检查。例如,由于在 Scala 中我们不倾向于使用 Java 集合,因此不需要所有基于 findbugs 集合的检查。另一个例子是检查静态字段的使用,这在 Scala 中是不相关的。
- Scalastyle https://github.com/scalastyle/scalastyle
- Scapegoat https://github.com/sksamuel/scalac-scapegoat-plugin
- Wart remover https://github.com/typelevel/wartremover
- Linter https://github.com/HairyFotr/linter
- CPD https://github.com/sbt/cpd4sbt
- Abide https://github.com/scala/scala-abide
- Codacy-scalameta https://github.com/codacy/codacy-scalameta
- Scalastyle https://github.com/scalastyle/scalastyle
- 替罪羊https://github.com/sksamuel/scalac-scapegoat-plugin
- 去疣剂https://github.com/typelevel/wartremover
- Linter https://github.com/HairyFotr/linter
- CPD https://github.com/sbt/cpd4sbt
- 遵守https://github.com/scala/scala-abide
- Codacy-scalameta https://github.com/codacy/codacy-scalameta
回答by Gábor Bakos
Would the wartremoverbe counted as an alternative? Also -Xlintand -Ywarn-adapted-argscommand line parameters of scalac might help catching certain types of bugs.
请问wartremover算作另类?另外-Xlint和-Ywarn-adapted-args的scalac可能帮助命令行参数,捕捉某些类型的错误。
回答by pedrorijo91
Codacydeveloped a easy to customize tool - scala-meta: https://github.com/codacy/codacy-scalameta
Codacy开发了一个易于定制的工具——scala-meta:https: //github.com/codacy/codacy-scalameta
take a look
看一看
and I think find-sec-bugs has some support for scala
我认为find-sec-bugs对 Scala 有一些支持
回答by Balkrishan Aggarwal
According to Codacy, following are the tools (updated till Oct 2015)
根据 Codacy,以下是工具(更新至 2015 年 10 月)
- ScalaStyle
- WartRemover
- Abide
- Scapegoat - sbt-scapegoat works with Scala 2.11.x+
回答by Mitrakov Artem
Why don't you like to use a very powerful Scalac compiler? E.g. it has some useful options, e.g.
为什么不喜欢使用非常强大的 Scalac 编译器?例如它有一些有用的选项,例如
- -unchecked
- -deprecation
- -feature
- -未选中
- - 弃用
- -特征
...etc.
...等等。

