File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,18 @@ private predicate looksLikeCode(string line) {
2020 exists ( string trimmed |
2121 trimmed = line .regexpReplaceAll ( "(?i)(^\\s+|&#?[a-z0-9]{1,31};|\\s+$)" , "" ) |
2222 trimmed .regexpMatch ( ".*[{};]" )
23+ and (
24+ // If this line looks like code because it ends with a closing
25+ // brace that's preceded by something other than whitespace ...
26+ trimmed .regexpMatch ( ".*.\\}" )
27+ implies
28+ // ... then there has to be ") {" (with some variation of
29+ // whitespace) on the line, suggesting it's a statement like `if`
30+ // or a function declaration. Otherwise it's likely to be a
31+ // benign use of braces such as a JSON example or explanatory
32+ // pseudocode.
33+ trimmed .regexpMatch ( ".*\\)\\s*\\{.*" )
34+ )
2335 and not trimmed .regexpMatch ( "(>.*|.*[\\\\@][{}].*|(optional|repeated) .*;|.*(\\{\\{\\{|\\}\\}\\}).*|\\{[-0-9a-zA-Z]+\\})" ) )
2436}
2537
Original file line number Diff line number Diff line change 1+ | test2.cpp:37:1:37:39 | // int myFunction() { return myValue; } | This comment appears to contain commented-out code |
12| test.c:2:1:2:22 | // commented out code; | This comment appears to contain commented-out code |
23| test.c:4:1:7:8 | // some; | This comment appears to contain commented-out code |
34| test.c:9:1:13:8 | // also; | This comment appears to contain commented-out code |
Original file line number Diff line number Diff line change 1+ /*
2+ * This sentence contains a semicolon;
3+ * however, this doesn't make it code.
4+ */
5+
6+ // This sentence contains a semicolon;
7+ // however, this doesn't make it code.
8+
9+ /* Mention a ';' */
10+
11+ /* Mention a '{' */
12+
13+ /* JSON example: {"foo":"bar"} */
14+
15+ /* JSON example in backticks: `{"foo":"bar"}` */
16+
17+ /* JSON example in quotes: '{"foo":"bar"}' */
18+
19+ /*
20+ * Code example: `return 0;`.
21+ */
22+
23+ // Code example:
24+ //
25+ // return 0;
26+
27+ // Code example:
28+ //
29+ // ```
30+ // return 0;
31+ // ```
32+
33+ // { 1, 2, 3, 4 }
34+
35+ // Example: { 1, 2, 3, 4 }
36+
37+ // int myFunction() { return myValue; }
You can’t perform that action at this time.
0 commit comments