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

Fail to scan .m files with "typedef void" function #287

Closed cyw3 closed 4 years ago

cyw3 commented 4 years ago
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wbuiltin-macro-redefined"
#undef __FILE__
#define __FILE__ "demo"
#pragma clang diagnostic pop

typedef void (*componentEventFunc)(id, SEL, NSDictionary *, id);

#ifdef __cplusplus
extern "C" {
#endif
void test() {
    [[ReadInJoyServiceEngine shareInstance] fetchRecommChannelListWithCompletionBlock:NO resultBlock:nil];
}
#ifdef __cplusplus
}
#endif

@interface demo () <MQZoneTableFootLoadingViewDelegate>

@end

@implementation demo

- (NSMutableArray<NSDictionary *> *)test1 {
    if (!_playedVideoBehavious) {
        //        _playedVideoBehavious = [[NSMutableArray alloc] init];
        _playedVideoBehavious = [NSMutableArray.array retain];
    }
    return _playedVideoBehavious;
}

@end 

output is:

4,2,19,1,5,"(.test@12-16@/xxx/demo.m","/xxx/demo.m","(.test","(.test() { [ [ ReadInJoyServiceEngine shareInstance ] fetchRecommChannelListWithCompletionBlock : NO resultBlock : nil ] ; } }",12,16
  1. the function name is wrong;
  2. lizard can not scan all the function. just the first function.

And if I remove the "typedef void (componentEventFunc)(id, SEL, NSDictionary , id);" from the code file, lizard works and output is:

3,1,18,0,3,"test@13-15@/xxx/demo.m","/xxx/demo.m","test","test()",13,15
6,2,22,0,7,"test1@26-32@/xxx/demo.m","/xxx/demo.m","test1","test1",26,32
kingsword commented 4 years ago

@terryyin Please take a look at this question.

kingsword commented 4 years ago

Case 1: Test Code

//
//  TestLizard.m
#import "TestLizard.h"
typedef void(^alertActionHandler)(void);
@implementation TestLizard
- (void)method1 {

}

- (void)method2 {

}

- (void)method3 {

}
@end

Result:

================================================
  NLOC    CCN   token  PARAM  length  location  
------------------------------------------------
       3      1      8      1       4 TestLizard@5-8@/Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m
1 file analyzed.
==============================================================
NLOC    Avg.NLOC  AvgCCN  Avg.token  function_cnt    file
--------------------------------------------------------------
      9       3.0     1.0        8.0         1     /Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m

===============================================================================================================
No thresholds exceeded (cyclomatic_complexity > 15 or nloc > 1000000 or length > 1000 or parameter_count > 100)
==========================================================================================
Total nloc   Avg.NLOC  AvgCCN  Avg.token   Fun Cnt  Warning cnt   Fun Rt   nloc Rt
------------------------------------------------------------------------------------------
         9       3.0     1.0        8.0        1            0      0.00    0.00

but when I comment "typedef void(^alertActionHandler)(void);" in line 4

//
//  TestLizard.m
#import "TestLizard.h"
//typedef void(^alertActionHandler)(void);
@implementation TestLizard
- (void)method1 {

}

- (void)method2 {

}

- (void)method3 {

}
@end

Result is right。

================================================
  NLOC    CCN   token  PARAM  length  location  
------------------------------------------------
       2      1      3      0       3 method1@6-8@/Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m
       2      1      3      0       3 method2@10-12@/Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m
       2      1      3      0       3 method3@14-16@/Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m
1 file analyzed.
==============================================================
NLOC    Avg.NLOC  AvgCCN  Avg.token  function_cnt    file
--------------------------------------------------------------
      8       2.0     1.0        3.0         3     /Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m

===============================================================================================================
No thresholds exceeded (cyclomatic_complexity > 15 or nloc > 1000000 or length > 1000 or parameter_count > 100)
==========================================================================================
Total nloc   Avg.NLOC  AvgCCN  Avg.token   Fun Cnt  Warning cnt   Fun Rt   nloc Rt
------------------------------------------------------------------------------------------
         8       2.0     1.0        3.0        3            0      0.00    0.00
kingsword commented 4 years ago

Case 2: Test Code

//
//  TestLizard.m
#import "TestLizard.h"
typedef NS_ENUM(NSUInteger, TRMemoCellType) {
    TRMemoCellTypeHome = 0,
    TRMemoCellTypeSearch = 1,
    TRMemoCellTypeVoiceMemo = 2,
};
@implementation TestLizard
- (void)method1 {

}

- (void)method2 {

}

- (void)method3 {

}
@end

Result

================================================
  NLOC    CCN   token  PARAM  length  location  
------------------------------------------------
       5      1     20      2       5 NS_ENUM@4-8@/Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m
       2      1      3      0       3 method1@10-12@/Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m
       2      1      3      0       3 method2@14-16@/Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m
       2      1      3      0       3 method3@18-20@/Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m
1 file analyzed.
==============================================================
NLOC    Avg.NLOC  AvgCCN  Avg.token  function_cnt    file
--------------------------------------------------------------
     13       2.8     1.0        7.2         4     /Users/kingsword/Desktop/CommandLineTest/CommandLineTest/TestLizard.m

===============================================================================================================
No thresholds exceeded (cyclomatic_complexity > 15 or nloc > 1000000 or length > 1000 or parameter_count > 100)
==========================================================================================
Total nloc   Avg.NLOC  AvgCCN  Avg.token   Fun Cnt  Warning cnt   Fun Rt   nloc Rt
------------------------------------------------------------------------------------------
        13       2.8     1.0        7.2        4            0      0.00    0.00

”NS_ENUM@4-8@...“ in line 4 is not a function,but counted.

terryyin commented 4 years ago

case one fixed and passing: https://github.com/terryyin/lizard/commit/06a26064796b16f55bfd3e4b89b2ef94598b30c1

terryyin commented 4 years ago

oh, case 2 also pass.

Thanks!