67

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.

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?

Also, what about Scala's integration with, say, Sonar? Is the Scala Sonar plugin (which works with Scalastyle) reliable?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
marekinfo
  • 1,434
  • 1
  • 12
  • 12

5 Answers5

64

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.

sksamuel
  • 16,154
  • 8
  • 60
  • 108
8

Would the wartremover be counted as an alternative? Also -Xlint and -Ywarn-adapted-args command line parameters of scalac might help catching certain types of bugs.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Gábor Bakos
  • 8,982
  • 52
  • 35
  • 52
5

Codacy developed a easy to customize tool - scala-meta: https://github.com/codacy/codacy-scalameta

take a look

and I think find-sec-bugs has some support for scala

pedrorijo91
  • 7,635
  • 9
  • 44
  • 82
2

According to Codacy, following are the tools (updated till Oct 2015)

  1. ScalaStyle
  2. WartRemover
  3. Abide
  4. Scapegoat - sbt-scapegoat works with Scala 2.11.x+

Source: Codacy blog on Scala Static Analysis tools

Balkrishan Aggarwal
  • 613
  • 1
  • 6
  • 20
0

Why don't you like to use a very powerful Scalac compiler? E.g. it has some useful options, e.g.

  • -unchecked
  • -deprecation
  • -feature

...etc.

Mitrakov Artem
  • 1,355
  • 2
  • 14
  • 22
  • 3
    The question is whether the compiler makes all the suggestions. For example, javac doesn't always suggest all the "lint" type stuff that the Eclipse and IntelliJ static analyzer suggests. If the compiler suggested everything, there would be no need for say Findbugs or PMD. I would assume that in the Scala world, the situation is the same - i.e. not all code smells are checked by the compiler, such as copy-and-paste (non-DRY) code, or whatever it may be. – marekinfo Mar 24 '14 at 20:26