terryyin / lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
Other
1.85k stars 250 forks source link

[Objective-C]CCN wrongly reported on an "if" statement instead of a function #270

Closed iccengan closed 4 years ago

iccengan commented 5 years ago

I assume lizard should only report functions. But in the below case, if statement is detected. // #lizard forgives is not working for testFun(), unless I put this comment right before the if (testVar2) or inside if (testVar2).

Command I ran: python lizard.py test_ccn.mm -w -C 9 -L 100000

Result I got: test_ccn.mm->if->if( testVar2)->10-35-> 26->10->{32, 14, 15, 19, 20, 21, 24, 31} 10.0:1

File I scanned: test_ccn.mm

// #lizard forgives
- (void)testFun:(NSString *)testVar1 testCode
{
    // #lizard forgives
    testVar1 = [[self class] trimString:testVar1];
    if ([testVar1 length] == 0) {
        return;
    }

    if (testVar2) {        //line 10: ----------------Cyclomatic Complexity>10 detected
        NSString *listId = lid = testVar2.listId;
        idxStr = testVar2.indexStr;
        NSString *name = testVar2.nick;
        if (source == TestSource) {
            if (name.length == 0) {
                name = testVar2.name;
            }
        }
        if(testVar2.type == TestType){
            if(testVar2Latest){
                status = [self isEmpty:testVar2Latest.listId] ? 1 : 2;
                lid = testVar2Latest.listId;
                idxStr = testVar2Latest.indexStr;
                if (now >= testVar2Latest.exp_time) {
                    status = 3;
                }
            }
            else {
                status = 4;
            }
            if (testFunc) {
                testFunc(status, lid.length > 0 ? lid : nil, idxStr.length > 0 ? idxStr : nil);
            }
        }
    }
}
terryyin commented 4 years ago

Sorry for the super late reply. Lizard shouldn't report if as a function any more. So this seems to work fine for me now. BTW, // #lizard forgives does not work in a nested way. It will ignore the current or next function.