Skip to content

Commit 78c9fb3

Browse files
committed
QL: don't flag up comments placed on the same line as non-comments
1 parent f2222d3 commit 78c9fb3

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

ql/ql/src/queries/style/NonDocBlock.ql

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,31 @@ int getLineAboveNodeThatCouldHaveDoc(File file) {
2929

3030
pragma[noinline]
3131
BlockComment getACommentThatCouldBeQLDoc(File file) {
32-
file = result.getLocation().getFile() and
33-
result.getLocation().getFile().getExtension() = "qll" and
34-
not result.getContents().matches("/**%") and
35-
(
36-
// above something that can be commented.
37-
result.getLocation().getEndLine() = getLineAboveNodeThatCouldHaveDoc(file)
38-
or
39-
// toplevel in file.
40-
result.getLocation().getStartLine() = 1 and
41-
result.getLocation().getStartColumn() = 1
32+
exists(Location loc | loc = result.getLocation() |
33+
file = loc.getFile() and
34+
loc.getFile().getExtension() = "qll" and
35+
not result.getContents().matches("/**%") and
36+
not [loc.getStartLine(), loc.getEndLine()] = getLinesWithNonComment(file) and
37+
(
38+
// above something that can be commented.
39+
loc.getEndLine() = getLineAboveNodeThatCouldHaveDoc(file)
40+
or
41+
// toplevel in file.
42+
loc.getStartLine() = 1 and
43+
loc.getStartColumn() = 1
44+
)
45+
)
46+
}
47+
48+
pragma[noinline]
49+
int getLinesWithNonComment(File f) {
50+
exists(AstNode n, Location loc |
51+
not n instanceof Comment and
52+
not n instanceof TopLevel and
53+
loc = n.getLocation() and
54+
loc.getFile() = f
55+
|
56+
result = [loc.getEndLine(), loc.getStartLine()]
4257
)
4358
}
4459

ql/ql/test/queries/style/NonDocBlock/Foo.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ predicate foo() { any() }
1111
class Foo extends string {
1212
Foo() { this = "FOo" }
1313
}
14+
15+
/**
16+
* This is also fine.
17+
*/
18+
/*abstract*/ class Bar extends string {
19+
string getMergeRaw() { none() } // <- fine. The abstract comment is fine, it doesn't need to be QLDoc.
20+
21+
Bar() { this = "bar" }
22+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| Foo.qll:1:1:3:3 | BlockComment | Block comment could be QLDoc for $@. | Foo.qll:1:1:13:2 | TopLevel | the file |
1+
| Foo.qll:1:1:3:3 | BlockComment | Block comment could be QLDoc for $@. | Foo.qll:1:1:22:2 | TopLevel | the file |
22
| Foo.qll:10:1:10:24 | BlockComment | Block comment could be QLDoc for $@. | Foo.qll:11:7:11:9 | Class Foo | the below code |

0 commit comments

Comments
 (0)