Skip to content

Files

Latest commit

 

History

History
32 lines (22 loc) · 990 Bytes

UnusedObject.md

File metadata and controls

32 lines (22 loc) · 990 Bytes

Pattern: Unused object

Issue: -

Description

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:

By default, this rule does not analyze test files. This rule sets the default value of the doNotApplyToFilesMatching property to ignore file names ending in 'Test.groovy', 'Tests.groovy' or 'TestCase.groovy'. Invoking constructors without using the result is a common pattern in tests.

int someMethod() {
    new BigDecimal("23.45")     // unused
    return -1
}

BigDecimal someMethod() {
    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)

Further Reading