Static code analysis

177 views
Skip to first unread message

Marek Kolodziej

unread,
Mar 24, 2014, 2:32:41 PM3/24/14
to scala...@googlegroups.com
All, 

I was 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?

Thanks in advance for the help!

Marek

Clint Gilbert

unread,
Mar 24, 2014, 2:44:24 PM3/24/14
to scala...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Someone posted here a few months ago about taking over development of
the Scala plugin for Sonar, but I haven't heard any more about that.
I would love more and better static analysis tools; I really miss
Sonar since switching to Scala.
> -- You received this message because you are subscribed to the
> Google Groups "scala-user" group. To unsubscribe from this group
> and stop receiving emails from it, send an email to
> scala-user+...@googlegroups.com
> <mailto:scala-user+...@googlegroups.com>. For more options,
> visit https://groups.google.com/d/optout.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAlMwfQgACgkQ0GFaTS4nYxs1sQCfR1BuyrJ2fHjTTcPrjc5jlquH
ZGIAniR7MzGm16clqWKegWcldpUf29yI
=LXdN
-----END PGP SIGNATURE-----

Marek Kolodziej

unread,
Mar 24, 2014, 2:46:49 PM3/24/14
to scala...@googlegroups.com
Yeah, I saw this one but I'm not sure how good either the plugin or ScalaStyle is at checking non-stylistic (Findbugs-like) issues.

Marek

> <mailto:scala-user+unsub...@googlegroups.com>. For more options,

Dennis Haupt

unread,
Mar 24, 2014, 2:47:41 PM3/24/14
to Marek Kolodziej, scala-user
not sure about the current state of it, but there are a bunch of inspection in intellij idea's scala plugin (free version)


To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.

Marek Kolodziej

unread,
Mar 24, 2014, 2:52:54 PM3/24/14
to scala...@googlegroups.com, Marek Kolodziej
Right, but the issue is how to get it working as part of the build-time inspection, not in the IDE - in the sense of warning developers in case they ignored IntelliJ's recommendations, for example. I assume that IntelliJ's ideas could be reused, but I'm not quite sure if the plugin could be reused directly unless it has an API that could call it. Maybe JetBrains have the code-checking logic available separately so it could be reused for a Sonar plugin, for instance. I just don't know, hence my questions :)

Marek
> <mailto:scala-user+unsubscribe@googlegroups.com>. For more options,
> visit https://groups.google.com/d/optout.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAlMwfQgACgkQ0GFaTS4nYxs1sQCfR1BuyrJ2fHjTTcPrjc5jlquH
ZGIAniR7MzGm16clqWKegWcldpUf29yI
=LXdN
-----END PGP SIGNATURE-----

Stephen Compall

unread,
Mar 24, 2014, 9:09:01 PM3/24/14
to Marek Kolodziej, scala...@googlegroups.com
On Mon, 2014-03-24 at 11:32 -0700, Marek Kolodziej wrote:
I was 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.
You found scalastyle; here are a couple other interesting tools:

https://github.com/typelevel/wartremover#wartremover
https://opensource.plausible.coop/src/projects/SNX/repos/nx/browse (very new)

Don't forget that the compiler can turn off things very usefully, but you have to ask it to do so:
https://gist.github.com/tpolecat/8812750


Or, is ScalaStyle good not only for style checking, but is it good for improving code quality?

Many of scalastyle's style checks have nothing to do with the location of whitespace, or whether something appeared on the same line as some other thing, or whether magic numbers appeared multiple times.  Some examples:



-- 
Stephen Compall
"^aCollection allSatisfy: [:each | aCondition]": less is better than

Marek Kolodziej

unread,
Mar 24, 2014, 9:32:41 PM3/24/14
to Stephen Compall, scala...@googlegroups.com
Hi Stephen,

This is very helpful, thanks! I also thought that ScalaStyle could probably do the job - after all CheckStyle also evolved from a formatting tool to check many more things, such as duplicated code, clone() overrides, etc. So it makes sense that ScalaStyle would do the same.

I will definitely check the other ones too.

Thanks again!

Marek

Haoyi Li

unread,
Mar 24, 2014, 11:41:10 PM3/24/14
to Marek Kolodziej, Stephen Compall, scala-user
DeprecatedJavaChecker notes that in Scala @Deprecated is deprecated in favor of @deprecated.

This is silly and irrational, but I thought that this line is hilarious.

Just to make my post worth reading, I'll mention my own project Acyclic, which checks that you didn't do bad things you probably didn't want to do anyway, but are incredibly easy to do. It's a pretty simple compiler plugin that you can use to start implementing your own.


Reply all
Reply to author
Forward
0 new messages