Are there any tools for performing static analysis of Scala code? [closed]

谁说胖子不能爱 提交于 2019-12-20 08:27:45

问题


Are there any tools for performing static analysis of Scala code, similar to FindBugs and PMD for Java or Splint for C/C++? I know that FindBugs works on the bytecode produced by compiling Java, so I'm curious as to how it would work on Scala.

Google searches (as of 27 October 2009) reveal very little.

Google searches (as of 01 February 2010) reveal this question.


回答1:


FindBugs analyzes JVM byte codes, regardless of the tool that generated them. I've tried using FindBugs to check .class files generated by Scala. Unfortunately, FindBugs produced many warnings, even for trivial Scala programs.




回答2:


There is now Scalastyle which does the job that Checkstyle does for Java. This includes not only formatting checks, but also some checks for known sources of bugs, such as a class which implements hashCode() but not equals.

There are currently about 40 checks, but we're adding them all of the time.

For more information, see www.scalastyle.org.




回答3:


There is some work going on in that direction. Some links:

  • https://github.com/alacscala/scala-corpus
  • https://github.com/alacscala/alacs
  • https://bitbucket.org/jmhofer/findbugs4sbt/wiki/Home

There is also a discussion on scala mail list, archive available here.




回答4:


Here is an updated answer as of August 2014 for some that are aimed or work well with 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.

  • 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



回答5:


Findbugs and other tools that are bytecode based will work, in the sense that they will find faults in your code. Unfortunately, the bytecode based approaches have been tuned against the output of the javac compilers, meaning they are likely to produce very high false positive rates, and miss basic issues, because Scala will be producing different idioms than the javac compiler.




回答6:


I'm having a lot of fun with Codacy (e.g. https://www.codacy.com/app/hejfelix/Frase/dashboard) for Open Source projects




回答7:


There is a SBT plugin for PMD copy paste detector CPD.

https://github.com/sbt/cpd4sbt




回答8:


scala copy paste detector, based on AST. Looking for copy-pasted subtrees/ASTs, and inform about it.

It's plugin for sbt.

https://github.com/ajtkulov/scala-cpd




回答9:


I don't know much about Scala but if is Java compatible Klocwork's Solo product might work. You can find it here Klocwork Solo



来源:https://stackoverflow.com/questions/1598882/are-there-any-tools-for-performing-static-analysis-of-scala-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!