Skip to content

Commit

Permalink
Rust: lines of code, exclude 'SourceFile' node
Browse files Browse the repository at this point in the history
  • Loading branch information
aibaars committed Sep 19, 2024
1 parent 32e3084 commit 23d2e03
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions rust/ql/lib/codeql/files/FileSystem.qll
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

private import codeql.Locations
private import codeql.util.FileSystem
private import codeql.rust.elements.SourceFile
private import codeql.rust.elements.AstNode

Check warning

Code scanning / CodeQL

Redundant import Warning

Redundant import, the module is already imported inside
codeql.rust.elements.SourceFile
.

private module Input implements InputSig {
abstract class ContainerBase extends @container {
Expand Down Expand Up @@ -41,8 +43,10 @@ class File extends Container, Impl::File {
int getNumberOfLinesOfCode() {
result =
count(int line |
exists(Location loc |
loc.getFile() = this and
exists(AstNode node, Location loc |
not node instanceof SourceFile and loc = node.getLocation()
|
node.getFile() = this and
line = [loc.getStartLine(), loc.getEndLine()] and
not loc instanceof EmptyLocation
)
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 |
| 48 |
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| 49 |
| 48 |
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 |
| lib.rs:0:0:0:0 | lib.rs | 7 |
| main.rs:0:0:0:0 | main.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 | 204 |
| Elements unextracted | 0 |
| Files extracted | 6 |
| Lines of code extracted | 49 |
| Lines of user code extracted | 49 |
| Lines of code extracted | 48 |
| Lines of user code extracted | 48 |

0 comments on commit 23d2e03

Please sign in to comment.