During the last two months I was working on several tasks in the scalafix repository (See my last post and scalafix docs for more cool stuff). Among them was porting wartremover rules to the scalafix. I’ve created a simple repo with example configs and tests to illustrate the current state of porting. Please visit it if you’re interested :) It’s still in progress, and some rules aren’t implemented yet, but the existing ones are already quite impressive! Let’s take a closer look at them.

Wartremover

Wartremover rules consist of two parts: Unsafe subset and … others. I won’t describe the behavior of every rule, you can find description in the official doc. Besides the names are quite expressive, it’s not hard to guess what the particular rule does.

Unsafe

Unsafe rules are most common and guard you from the most obvious bugs, like using None.get or .asInstanceOf instead of pattern-matching. Here’s a list of these rules:

  • Any
  • AsInstanceOf
  • EitherProjectionPartial
  • IsInstanceOf
  • NonUnitStatements (not implemented in the scalafix yet)
  • Null
  • OptionPartial
  • Product
  • Return
  • Serializable
  • StringPlusAny (partially implemented)
  • Throw
  • TraversableOps [will be soon]
  • TryPartial
  • Var

Scalafix porting lacks one rule and one is half done. This is due to the absence of proper type detection of arbitrary term in the SemanticDB. After fixing this issue it will be easy to finally complete this list :)

To look at the example scalafix config and tests of Unsafe rules you can visit my small repo.

All rules

Consider the rest of wartremover rules that aren’t in the Unsafe set:

  • AnyVal
  • ArrayEquals (not implemented because of the aforementioned SemanticDB issue)
  • DefaultArguments
  • Enumeration
  • Equals
  • ExplicitImplicitTypes (this rule’s covered by more general scalafix ExplicitResultTypes, but still need to be polished)
  • FinalCaseClass
  • FinalVal
  • ImplicitConversion
  • ImplicitParameter (not implemented yet)
  • JavaConversions [will be soon]
  • JavaSerializable
  • LeakingSealed
  • MutableDataStructures [will be soon]
  • Nothing (not implemented yet)
  • Option2Iterable
  • Overloading (not implemented yet, arguable rule)
  • PublicInference (not implemented yet)
  • Recursion (not implemented yet, arguable rule)
  • ToString
  • While

Yeah, this list is more pessimistic than the last. But these rules aren’t so common and some of them should be definitely discussed before adding to the scalafix (for instance, blocking of overloading or recursion).

Again you can go to the my repo to take a look at the scalafix config that contains all already implemented wartremover rules.

Small conclusion

There’s a lot of work to be done, as you see. Some rules merely aren’t implemented because of bugs and lack of the time, some of them are implemented only partially and some require more thoughtful discussion. But nevertheless current functionality is a good reason to start using scalafix from scratch or port your wartremover config.