Groovy and Grails Code QualityComments: 3
I’m involved in Grails project. Despite of development, my responsibility is taking care about code quality. I do Code Review, and I was wondering about tool to help me a little bit. In meantime I was reading GroovyMag issue and found out CodeNarc tool.
This tool do static analysis for groovy. Last CodeNarc version is 0.14, which means that it is still in development phase, but even now it has 241 rules. Also we can create our rules and rules set which make this tool really useful. Check this documents:
But good tool without integration do not exists. Fortunately CodeNarc comes with support with: Maven, Ant, Gradle, Grails, Griffon, Sonar and Hudson (coming soon).
I was delighted as IntelliJ user, because there is CodeNerc IntelliJ Plugin. After standard plugin activation we have to enable rules, which are disabled by default. See picture bellow.
Till now I disabled some rules, because from my point of view there was to much false positives:
- Ruleset naming : FieldName -> it complains a lot about DSL-s
- Ruleset dry: DuplicateStringLiteral -> we have something like this [save: “POST”, update: “POST”, delete: “POST”] and I think it is more readable than externalizing string “POST”
- Ruleset dry: DuplicateNumberLiteral -> false positives in tests
- Ruleset generic: StatelessClass – every class is by default “stateless” so this rule complains a lot about closure methods, fields etc.
I wonder what do you think about disabling this rules and which rules are useless from your point of view.
Last but not least is grails integration. CodeNerc comes with grail plugin, so everything is easy:
> grails install-plugin codenarc
> grails codenarc
CodeNarc completed: (p1=0; p2=0; p3=0) 7673msCodeNarc finished; report(s) generated: [CodeNarcReport.html]
And done, you have nice html file with: package, total files, files with violations, priority 1, priority 2 and priority 3. I cannot attach file so just look at images.
Happy quality code.