CodeNarc Report: Sample Project

Report timestamp: May 10, 2010 10:04:27 PM

Summary by Package

PackageTotal FilesFiles with ViolationsPriority 1Priority 2Priority 3
All Packages740115
org/codenarc/sample/domain21033
org/codenarc/sample/other10000
org/codenarc/sample/service43082

org/codenarc/sample/domain

org/codenarc/sample/domain/SampleDomain.groovy

Rule NamePriorityLine #Source Line / Message
EmptyElseBlock224

[SRC]else {

EmptyIfStatement221

[SRC]if (name) {

StringInstantiation217

[SRC]def title = new String('Sample Domain')

DuplicateImport35

[SRC]import org.codenarc.sample.other.Other

ImportFromSamePackage34

[SRC]import org.codenarc.sample.domain.OtherDomain

UnnecessaryGroovyImport33

[SRC]import java.util.Map

org/codenarc/sample/service

org/codenarc/sample/service/NewService.groovy

Rule NamePriorityLine #Source Line / Message
EmptyForStatement212

[SRC]for(int i=0; i < values.size(); i++) {

EmptyWhileStatement218

[SRC]while (!values.empty) {

org/codenarc/sample/service/OtherService.groovy

Rule NamePriorityLine #Source Line / Message
EmptyFinallyBlock213

[SRC]finally {

EmptyTryBlock210

[SRC]try {

ReturnFromFinallyBlock224

[SRC]return

org/codenarc/sample/service/SampleService.groovy

Rule NamePriorityLine #Source Line / Message
BooleanInstantiation217

[SRC]def shouldRun = new Boolean(true)

EmptyCatchBlock220

[SRC]} catch(Throwable t) {

ThrowExceptionFromFinallyBlock231

[SRC]throw new Exception('bad stuff')

UnnecessaryGroovyImport33

[SRC]import java.util.Map

UnusedImport34

[SRC]import org.codenarc.sample.domain.SampleDomain

Rule Descriptions

#Rule NameDescription
1BooleanInstantiationUse Boolean.valueOf() for variable values or Boolean.TRUE and Boolean.FALSE for constant values instead of calling the Boolean() constructor directly or calling Boolean.valueOf(true) or Boolean.valueOf(false).
2CloneableWithoutCloneA class that implements java.lang.Cloneable should define a clone() method.
3ConstantIfExpressionChecks for if statements with a constant value for the if expression, such as true, false, null, or a literal constant value.
4ConstantTernaryExpressionChecks for ternary expressions with a constant value for the boolean expression, such as true, false, null, or a literal constant value.
5DuplicateImportDuplicate import statements are unnecessary.
6EmptyCatchBlockIn most cases, exceptions should not be caught and ignored (swallowed).
7EmptyElseBlockEmpty else blocks are confusing and serve no purpose.
8EmptyFinallyBlockEmpty finally blocks are confusing and serve no purpose.
9EmptyForStatementEmpty for statements are confusing and serve no purpose.
10EmptyIfStatementEmpty if statements are confusing and serve no purpose.
11EmptySwitchStatementEmpty switch statements are confusing and serve no purpose.
12EmptySynchronizedStatementEmpty synchronized statements are confusing and serve no purpose.
13EmptyTryBlockEmpty try blocks are confusing and serve no purpose.
14EmptyWhileStatementEmpty while statements are confusing and serve no purpose.
15EqualsAndHashCodeIf either the boolean equals(Object) or the int hashCode() methods are overridden within a class, then both must be overridden.
16ImportFromSamePackageAn import of a class that is within the same package is unnecessary.
17ReturnFromFinallyBlockReturning from a finally block is confusing and can hide the original exception.
18StringInstantiationUse a String literal (e.g., "...") instead of calling the corresponding String constructor (new String("..")) directly.
19ThrowExceptionFromFinallyBlockThrowing an exception from a finally block is confusing and can hide the original exception.
20UnnecessaryGroovyImportA Groovy file does not need to include an import for classes from java.lang, java.util, java.io, java.net, groovy.lang and groovy.util, as well as the classes java.math.BigDecimal and java.math.BigInteger.
21UnnecessaryTernaryExpressionChecks for ternary expressions where the conditional expression always evaluates to a boolean and the true and false expressions are merely returning true and false constants. Also checks for ternary expressions where both expressions are the same constant or variable.
22UnusedImportImports for a class that is never referenced within the source file is unnecessary.

CodeNarc v0.9