Skip to content

Commit

Permalink
Merge pull request #17588 from geoffw0/loc2
Browse files Browse the repository at this point in the history
Rust: Improve lines-of-code counts.
  • Loading branch information
geoffw0 authored Oct 2, 2024
2 parents d6415cd + 0b6ec46 commit f7db47b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 18 deletions.
2 changes: 1 addition & 1 deletion rust/ql/lib/codeql/files/FileSystem.qll
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class File extends Container, Impl::File {
loc = node.getLocation()
|
node.getFile() = this and
line = [loc.getStartLine(), loc.getEndLine()] and
line = [/*loc.getStartLine(), */ loc.getEndLine()] and // ignore start locations for now as we're getting them wrong for things with a comment attached
not loc instanceof EmptyLocation
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
| comments.rs:0:0:0:0 | comments.rs | File successfully extracted. |
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | File successfully extracted. |
| error.rs:0:0:0:0 | error.rs | File successfully extracted. |
| lib.rs:0:0:0:0 | lib.rs | File successfully extracted. |
Expand Down
2 changes: 1 addition & 1 deletion rust/ql/test/query-tests/diagnostics/LinesOfCode.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| 48 |
| 61 |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| 48 |
| 61 |
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
| my_struct.rs:0:0:0:0 | my_struct.rs | 21 |
| my_macro.rs:0:0:0:0 | my_macro.rs | 8 |
| main.rs:0:0:0:0 | main.rs | 7 |
| lib.rs:0:0:0:0 | lib.rs | 6 |
| my_struct.rs:0:0:0:0 | my_struct.rs | 20 |
| comments.rs:0:0:0:0 | comments.rs | 13 |
| main.rs:0:0:0:0 | main.rs | 8 |
| lib.rs:0:0:0:0 | lib.rs | 7 |
| my_macro.rs:0:0:0:0 | my_macro.rs | 7 |
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 |
| error.rs:0:0:0:0 | error.rs | 3 |
8 changes: 4 additions & 4 deletions rust/ql/test/query-tests/diagnostics/SummaryStats.expected
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| Elements extracted | 210 |
| Elements extracted | 290 |
| Elements unextracted | 0 |
| Files extracted | 6 |
| Lines of code extracted | 48 |
| Lines of user code extracted | 48 |
| Files extracted | 7 |
| Lines of code extracted | 61 |
| Lines of user code extracted | 61 |
60 changes: 60 additions & 0 deletions rust/ql/test/query-tests/diagnostics/comments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* total lines in this file: 61
* of which code: 16
* of which only comments: 33
* of which blank: 12
*/

// a comment

/**
* Comment attached to a struct.
*/
struct StructWithComments
{
/**
* Another attached comment.
*/
a: i32,

// And another attached comment.
b: i32,

/*
* And yet another attached comment.
*/
c: i32,

// informal
// comment
// block.
cd: i32,

// Just a comment.
}

pub fn my_simple_func()
{
}

/**
* Comment attached to a function.
*/
pub fn my_func_with_comments()
{
// comment
let a = 1; // comment
// comment
let b = 2;

// comment

/*
* Comment.
*/
my_simple_func();
}

/*
* Comment.
*/
11 changes: 5 additions & 6 deletions rust/ql/test/query-tests/diagnostics/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/**
* total lines in this file: 18
* of which code: 7
* of which only comments: 7
* of which code: 8
* of which only comments: 6
* of which blank: 4
*/

mod my_struct;
mod my_macro;
mod comments;

// another comment

fn main() { // another comment
//println!("Hello, world!"); // currently causes consistency issues
fn main() {
println!("Hello, world!");

my_struct::my_func();
my_macro::my_func();
Expand Down
2 changes: 1 addition & 1 deletion rust/ql/test/query-tests/diagnostics/my_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

macro_rules! myMacro {
() => {
//println!("Hello, world!"); // currently causes consistency issues
println!("Hello, world!");
};
}

Expand Down

0 comments on commit f7db47b

Please sign in to comment.