Menu

#76 create "should use collect" rule

open
nobody
None
5
2013-02-16
2010-11-11
No

create "should use collect" rule

Fails:
def x = []
y.each {
y = it * 2
x.add y
}
---
def x = []
5.times {
x.add it
}
---
def x = []
for (Object o1 : o2) {
x.add o1
}

Passes:
def x = y.collect { it }
---
def x = []
y.each {
y = it * 2
x.add y
println x // passes b/c add is not last statement in block
}
---
def x = []
foo().times {
y = it * 2
x.add y
println x // passes b/c add is not last statement in block
}
---
def x = []
for (Object o1 : o2) {
x.add o1
println x // passes b/c add is not last statement in block
}

Discussion


Log in to post a comment.