A static code analysis plugin for the Scala compiler.
Use sbt and package to compile the plugin.
In order to run the unit tests, use SBT's testOnly. Standalone tests can be run using src/standaloneTest. As a first example, you can run ScalaSCA on ScalaSCA's source itself, using the src/autoCheck script.
Once the plugin has been compiled, it can be used as an additional phase for the compiler: scalac -Xplugin:target/scala-XXX/scalasca_XXX-0.1.jar, where XXX stands for the current scala version.
ScalaSCA has four warning levels, that are displayed in their respective colours, if your terminal supports them:
- Notice (white): for rules of any kind, that do not check the "correctness" of the code. General static analyses (e.g. constant propagation) typically fall into this category
- Warning (yellow): generally used when a rule discovered a potential bug (medium probability)
- Severe warning (dark yellow): used when a rule discovered a potential bug (high probability)
- Fatal (red): used when a rule discovered a piece of code that will crash at runtime, if executed
| Rule Error Code | Description | Category |
|---|---|---|
| ASS_USELESSASSIGNMENT | (Re-)assignment to val/var has no effect | Bad Practice |
| MEM_MISSING_RESOURCE_CLOSING | Resource not freed after usage | Bad Practice |
| CLS_PUBLIC_MUTABLE_FIELDS | Public vars in classes/objects/traits | Bad Practice |
| MET_DOUBLE_TRIPLE_EQUALS | (Akka.Actor) Use of == vs === |
Dodgy Code |
| ARI_DIV_BY_ZERO | Divison by 0 | Fatal |
| GEN_UNUSED_CODE_REMOVAL | Removes unused code | General |
| GEN_BLOCK_CONST_PROP | Propagates constant values | General |
BlockConstantPropagationcasts toStringandIntinConstant val built from other constants. Any clean quasiquotish solution for this (not being able to be lifted toAny)?BlockConstantPropagationdoes not consider arbitrary methods