Skip to content

Commit

Permalink
Rust: For now exclude top-level AST elements from LOC counts. This is…
Browse files Browse the repository at this point in the history
… not ideal.
  • Loading branch information
geoffw0 committed Oct 1, 2024
1 parent 7482603 commit 3a54c10
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
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
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 @@
| 49 |
| 46 |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| 49 |
| 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 |
| main.rs:0:0:0:0 | main.rs | 8 |
| 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 |
4 changes: 2 additions & 2 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 | 216 |
| Elements unextracted | 0 |
| Files extracted | 6 |
| Lines of code extracted | 49 |
| Lines of user code extracted | 49 |
| Lines of code extracted | 46 |
| Lines of user code extracted | 46 |

0 comments on commit 3a54c10

Please sign in to comment.