@@ -12,19 +12,26 @@ private predicate looksLikeCode(string line) {
1212 // * HTML entities in hexadecimal notation (e.g. 灟)
1313 trimmed = line .regexpReplaceAll ( "(?i)(^\\s+|&#?[a-z0-9]{1,31};|\\s+$)" , "" )
1414 |
15- // Match comment lines ending with '{', '}' or ';'
16- trimmed .regexpMatch ( ".*[{};]" ) and
1715 (
18- // If this line looks like code because it ends with a closing
19- // brace that's preceded by something other than whitespace ...
20- trimmed .regexpMatch ( ".*.\\}" )
21- implies
22- // ... then there has to be ") {" (or some variation)
23- // on the line, suggesting it's a statement like `if`
24- // or a function declaration. Otherwise it's likely to be a
25- // benign use of braces such as a JSON example or explanatory
26- // pseudocode.
27- trimmed .regexpMatch ( ".*(\\)|const|volatile|override|final|noexcept|&)\\s*\\{.*" )
16+ (
17+ // Match comment lines ending with '{', '}' or ';'
18+ trimmed .regexpMatch ( ".*[{};]" ) and
19+ (
20+ // If this line looks like code because it ends with a closing
21+ // brace that's preceded by something other than whitespace ...
22+ trimmed .regexpMatch ( ".*.\\}" )
23+ implies
24+ // ... then there has to be ") {" (or some variation)
25+ // on the line, suggesting it's a statement like `if`
26+ // or a function declaration. Otherwise it's likely to be a
27+ // benign use of braces such as a JSON example or explanatory
28+ // pseudocode.
29+ trimmed .regexpMatch ( ".*(\\)|const|volatile|override|final|noexcept|&)\\s*\\{.*" )
30+ )
31+ ) or (
32+ // Match comment lines that look like preprocessor code
33+ trimmed .regexpMatch ( "#(include|define|undef|if|ifdef|ifndef|elif|else|endif|error)(\\s.*|)" )
34+ )
2835 ) and (
2936 // Exclude lines that start with '>' or contain '@{' or '@}'.
3037 // To account for the code generated by protobuf, we also insist that the comment
0 commit comments