Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: Improve lines-of-code counts. #17588

Merged
merged 10 commits into from
Oct 2, 2024
2 changes: 2 additions & 0 deletions rust/ql/lib/codeql/files/FileSystem.qll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ private import codeql.util.FileSystem
private import codeql.rust.elements.SourceFile
private import codeql.rust.elements.AstNode
private import codeql.rust.elements.Comment
private import codeql.rust.elements.internal.generated.ParentChild

private module Input implements InputSig {
abstract class ContainerBase extends @container {
Expand Down Expand Up @@ -47,6 +48,7 @@ class File extends Container, Impl::File {
exists(AstNode node, Location loc |
not node instanceof Comment and
not node instanceof SourceFile and
not getImmediateParent(node) instanceof SourceFile and // ignore top-level elements for now as we're getting their locations wrong when a comment is attached
geoffw0 marked this conversation as resolved.
Show resolved Hide resolved
loc = node.getLocation()
|
node.getFile() = this and
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 |
| 46 |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| 48 |
| 46 |
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| my_struct.rs:0:0:0:0 | my_struct.rs | 21 |
| my_macro.rs:0:0:0:0 | my_macro.rs | 8 |
| my_struct.rs:0:0:0:0 | my_struct.rs | 20 |
| main.rs:0:0:0:0 | main.rs | 7 |
| my_macro.rs:0:0:0:0 | my_macro.rs | 7 |
| lib.rs:0:0:0:0 | lib.rs | 6 |
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 |
| error.rs:0:0:0:0 | error.rs | 3 |
6 changes: 3 additions & 3 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 | 216 |
| Elements unextracted | 0 |
| Files extracted | 6 |
| Lines of code extracted | 48 |
| Lines of user code extracted | 48 |
| Lines of code extracted | 46 |
| Lines of user code extracted | 46 |
2 changes: 1 addition & 1 deletion rust/ql/test/query-tests/diagnostics/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod my_macro;
// another comment

fn main() { // another comment
//println!("Hello, world!"); // currently causes consistency issues
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
Loading