Skip to content

Files

Latest commit

 

History

History
28 lines (20 loc) · 988 Bytes

ParameterAssignmentInFilterClosure.md

File metadata and controls

28 lines (20 loc) · 988 Bytes

Pattern: Parameter assignment in filter closure

Issue: -

Description

An assignment operator was used on a parameter, or a property or subproperty of the parameter, in a filtering or searching closure. This is usually a typo, and the comparison operator (==) was intended.

This rule will check the following filter methods: find, findAll, findIndexOf, every, any, filter, grep, dropWhile and takeWhile.

Examples

List someList = [1,2,3]
someList.find {it == 2}
someList.find {it = 2}                  // violation, this actually finds 1 instead.
someList.find { int integer ->
	integer == 2
}
someList.find { int integer ->
	integer = 2                         // violation, this actually finds 1 instead.
}
someList.takeWhile { it.name = 42 }     // violation

Further Reading