Skip to content

Commit f7db47b

Browse files
authored
Merge pull request #17588 from geoffw0/loc2
Rust: Improve lines-of-code counts.
2 parents d6415cd + 0b6ec46 commit f7db47b

File tree

9 files changed

+79
-18
lines changed

9 files changed

+79
-18
lines changed

rust/ql/lib/codeql/files/FileSystem.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class File extends Container, Impl::File {
5050
loc = node.getLocation()
5151
|
5252
node.getFile() = this and
53-
line = [loc.getStartLine(), loc.getEndLine()] and
53+
line = [/*loc.getStartLine(), */ loc.getEndLine()] and // ignore start locations for now as we're getting them wrong for things with a comment attached
5454
not loc instanceof EmptyLocation
5555
)
5656
)

rust/ql/test/query-tests/diagnostics/ExtractedFiles.expected

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| comments.rs:0:0:0:0 | comments.rs | File successfully extracted. |
12
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | File successfully extracted. |
23
| error.rs:0:0:0:0 | error.rs | File successfully extracted. |
34
| lib.rs:0:0:0:0 | lib.rs | File successfully extracted. |
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| 48 |
1+
| 61 |
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| 48 |
1+
| 61 |
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
| my_struct.rs:0:0:0:0 | my_struct.rs | 21 |
2-
| my_macro.rs:0:0:0:0 | my_macro.rs | 8 |
3-
| main.rs:0:0:0:0 | main.rs | 7 |
4-
| lib.rs:0:0:0:0 | lib.rs | 6 |
1+
| my_struct.rs:0:0:0:0 | my_struct.rs | 20 |
2+
| comments.rs:0:0:0:0 | comments.rs | 13 |
3+
| main.rs:0:0:0:0 | main.rs | 8 |
4+
| lib.rs:0:0:0:0 | lib.rs | 7 |
5+
| my_macro.rs:0:0:0:0 | my_macro.rs | 7 |
56
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 |
67
| error.rs:0:0:0:0 | error.rs | 3 |
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
| Elements extracted | 210 |
1+
| Elements extracted | 290 |
22
| Elements unextracted | 0 |
3-
| Files extracted | 6 |
4-
| Lines of code extracted | 48 |
5-
| Lines of user code extracted | 48 |
3+
| Files extracted | 7 |
4+
| Lines of code extracted | 61 |
5+
| Lines of user code extracted | 61 |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* total lines in this file: 61
3+
* of which code: 16
4+
* of which only comments: 33
5+
* of which blank: 12
6+
*/
7+
8+
// a comment
9+
10+
/**
11+
* Comment attached to a struct.
12+
*/
13+
struct StructWithComments
14+
{
15+
/**
16+
* Another attached comment.
17+
*/
18+
a: i32,
19+
20+
// And another attached comment.
21+
b: i32,
22+
23+
/*
24+
* And yet another attached comment.
25+
*/
26+
c: i32,
27+
28+
// informal
29+
// comment
30+
// block.
31+
cd: i32,
32+
33+
// Just a comment.
34+
}
35+
36+
pub fn my_simple_func()
37+
{
38+
}
39+
40+
/**
41+
* Comment attached to a function.
42+
*/
43+
pub fn my_func_with_comments()
44+
{
45+
// comment
46+
let a = 1; // comment
47+
// comment
48+
let b = 2;
49+
50+
// comment
51+
52+
/*
53+
* Comment.
54+
*/
55+
my_simple_func();
56+
}
57+
58+
/*
59+
* Comment.
60+
*/

rust/ql/test/query-tests/diagnostics/main.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/**
22
* total lines in this file: 18
3-
* of which code: 7
4-
* of which only comments: 7
3+
* of which code: 8
4+
* of which only comments: 6
55
* of which blank: 4
66
*/
77

88
mod my_struct;
99
mod my_macro;
10+
mod comments;
1011

11-
// another comment
12-
13-
fn main() { // another comment
14-
//println!("Hello, world!"); // currently causes consistency issues
12+
fn main() {
13+
println!("Hello, world!");
1514

1615
my_struct::my_func();
1716
my_macro::my_func();

rust/ql/test/query-tests/diagnostics/my_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
macro_rules! myMacro {
99
() => {
10-
//println!("Hello, world!"); // currently causes consistency issues
10+
println!("Hello, world!");
1111
};
1212
}
1313

0 commit comments

Comments
 (0)