the last days I’ve spend my time writing a static code analysis tool for Kotlin.
Here it is → gitlabRepo and githubMirror
It currently supports 13 different rules categorized into three categories: code smells, style violations and document violations. (e.g. LongMethod/-Complex, LargeClass, LongParameterList, NamingConventions, MissingKDoc over public members, some style violations according to kotlin coding conventions etc).
It is organized in modules and uses the ServiceLoader-Pattern to be extendable by ownrules/rule sets. The module detekt-cli provides the currently only interface to analyze your projects.
In future I want to add more rules like GodClass and FeatureEnvy (+ more style violations) and write a gradle plugin to create reports on builds.
Feel free to file an issue with your ideas, thoughts and rule requests for the default rule set! Your feedback is very much appreciated. Thx in advance!
PS: I’m using Spek as the testing framework. On Bintray the version 1.1.18 was deleted when 1.1.19 was released. Is this the common way Bintray/Spek handles versions or is it done to the fact that the 1.1 is still in Beta? I don’t like my builds to fail on Jenkins, I’m using the experimental SubjectSpek class
I had a good look on KtLint and found out it is specialized in findings formatting violations. I also use some similar mechanisms as KtLint but a more classical visitor approach with a KtTreeVisitor. As in KtLint were no new rules since august and one tool to have it all would be great, I made an effort to port the existing rules of it to detekt.
Today I released the third milestone with a total of seven rulesets (~45 rules). New rule sets are:
formatting - detects indentation and spacing problems in code
exceptions - too general exceptions are used in throw and catch statements like RuntimeException
empty - finds empty block statements
potential-bugs - code is structured in a way it can lead to bugs like ‘only equals but not hashcode is implemented’,
no else case in when statements, explicit garbage collection calls
Formatting can be configurated to auto correct rule violations:
ktlint checks your code if it is formatted according to kotlin style guide and detekt checks if your code is not too complicated (long methods, complex conditions, many parameters etc). detekt also provides a formatting rule set which is based on ktlint.