longyiqi/oclint — Issue #6: Detecting methods return constant boolean result for constant if statement rule
Author: lqi
Created: 2011-11-04 15:17:40+00:00
State: open

We need to detect the methods that return constant boolean result, for example, method like

- (BOOL)aMethod {
// some logic here
return YES;
}

will return YES no matter the internal logic. If we call this method as condition in if statement, like the test shown below, then it's a code smell.

void ConstantIfStatementRuleTest::testConstantMethod() {
checkRule("int alwaysTrue() { return 1; } int main() { if(alwaysTrue()) {;} return 0; }", true);
}