Checks for array allocations that are not assigned or used, unless it is the last statement within a block (because it may be the intentional return value). Examples include:
int myMethod() { new String[3] // unused return -1 } String[] myMethod() { new String[3] // OK (last statement in block) } def closure = { doStuff() new Date[3] // unused doOtherStuff() } def closure = { new Date[3] } // OK (last statement in block)
Checks for object allocations that are not assigned or used, unless it is the last statement within a block (because it may be the intentional return value). Examples include:
This rule sets the default value of the doNotApplyToClassNames property to only match class names that do not end in 'Test', 'Tests' or 'TestCase'. Invoking constructors without using the result is a common pattern in tests.
int myMethod() { new BigDecimal("23.45") // unused return -1 } BigDecimal myMethod() { new BigDecimal("23.45") // OK (last statement in block) } def closure = { doStuff() new Date() // unused doOtherStuff() } def closure = { new Date() } // OK (last statement in block)
Checks for private fields that are not referenced within the same class. Note that the private modifier is not currently "respected" by Groovy code (i.e., Groovy can access private members within other classes). By default, fields named serialVersionUID are ignored. The rule has a property named ignoreFieldNames, which can be set to ignore other field names as well. For instance, to ignore fields named 'fieldx', set the property to the 'fieldx, serialVersionUID'
Property | Description | Default Value |
ignoreFieldNames | Specifies one or more (comma-separated) field names that should be ignored (i.e., that should not cause a rule violation). The names may optionally contain wildcards (*,?). |
serialVersionUID |
Known limitations:
Checks for private methods that are not referenced within the same class. Note that the private modifier is not currently "respected" by Groovy code (i.e., Groovy can access private members within other classes).
Known limitations:
Since CodeNarc 0.12
Checks for parameters to private methods that are not referenced within the method body. Note that the private modifier is not currently "respected" by Groovy code (i.e., Groovy can access private members within other classes).
Known limitations:
Checks for variables that are never referenced.
Known limitations: