Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Groovy code quality tools

Groovy code quality tools

Grygoriy Mykhalyuno

October 12, 2013
Tweet

More Decks by Grygoriy Mykhalyuno

Other Decks in Programming

Transcript

  1. CodeNarc http://codenarc.sourceforge.net/ CodeNarc analyzes Groovy code for defects, bad practices,

    inconsistencies, style issues and more. A flexible framework for rules, rulesets and custom rules means it's easy to configure CodeNarc to fit into your project. Build tool, framework support, and report generation are all enterprise ready.
  2. CodeNarc Can be runed from - command line - as

    ant task - as maven task - as gradle task - as grails plugin
  3. CodeNarc ruleset ruleset { description 'Rules Sample Groovy Gradle Project'

    ruleset('rulesets/basic.xml') ruleset('rulesets/braces.xml') ruleset('rulesets/exceptions.xml') ruleset('rulesets/imports.xml') ruleset('rulesets/logging.xml') ruleset('rulesets/naming.xml') { 'ClassName' { enabled = false } } ruleset('rulesets/unnecessary.xml') { 'UnnecessaryReturnKeyword' { enabled = false } } ruleset('rulesets/unused.xml') }
  4. CodeNarc custome rules import org.codenarc.rule.AbstractRule import org.codenarc.source.SourceCode /** * Sample

    rule. Checks for static fields. */ class MyStaticFieldRule extends AbstractRule { String name = 'MyStaticField' int priority = 2 void applyTo(SourceCode sourceCode, List violations) { sourceCode.ast.classes.each { clazz -> clazz.fields.each { fieldNode -> if (fieldNode.static) { violations << createViolation(sourceCode, fieldNode) } } } } }
  5. Gmetrics http://gmetrics.sourceforge.net/ The GMetrics project provides calculation and reporting of

    size and complexity metrics for Groovy source code. GMetrics scans Groovy source code, applying a set of metrics, and generates an HTML report of the results.
  6. Gmetrics • Cyclomatic Complexity. • ABC Size/Complexity. Also see the

    C2 Wiki page. • Lines per method • Lines per class