forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#17464 from geoffw0/loc
Rust: Add lines-of-code queries
- Loading branch information
Showing
14 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* @name Total lines of Rust code in the database | ||
* @description The total number of lines of Rust code across all files, including any libraries and auto-generated files that the extractor sees. This is a useful metric of the size of a database. For all files that were seen during the build, this query counts the lines of code, excluding whitespace or comments. | ||
* @kind metric | ||
* @id rust/summary/lines-of-code | ||
* @tags summary | ||
* lines-of-code | ||
* telemetry | ||
*/ | ||
|
||
import rust | ||
import Stats | ||
|
||
select getLinesOfCode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* @name Total lines of user written Rust code in the database | ||
* @description The total number of lines of Rust code from the source code directory. This query counts the lines of code, excluding whitespace or comments. | ||
* @kind metric | ||
* @id rust/summary/lines-of-user-code | ||
* @tags summary | ||
* lines-of-code | ||
* debug | ||
*/ | ||
|
||
import rust | ||
import Stats | ||
|
||
select getLinesOfUserCode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @name Lines of user code in files | ||
* @description Measures the number of lines of code in each file from the source directory, ignoring lines that contain only comments or whitespace. | ||
* @kind metric | ||
* @id rust/summary/lines-of-user-code-in-files | ||
* @metricType file | ||
*/ | ||
|
||
import rust | ||
|
||
from File f, int n | ||
where | ||
exists(f.getRelativePath()) and | ||
n = f.getNumberOfLinesOfCode() | ||
select f, n order by n desc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Predicates used in summary queries. | ||
*/ | ||
|
||
import rust | ||
|
||
int getLinesOfCode() { result = sum(File f | | f.getNumberOfLinesOfCode()) } | ||
|
||
int getLinesOfUserCode() { | ||
result = sum(File f | exists(f.getRelativePath()) | f.getNumberOfLinesOfCode()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @name Summary Statistics | ||
* @description A table of summary statistics about a database. | ||
* @kind table | ||
* @id rust/summary/summary-statistics | ||
* @tags summary | ||
*/ | ||
|
||
import rust | ||
import Stats | ||
|
||
from string key, string value | ||
where | ||
key = "Lines of code" and value = getLinesOfCode().toString() | ||
or | ||
key = "Lines of user code" and value = getLinesOfUserCode().toString() | ||
select key, value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| 24 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
queries/summary/LinesOfCode.ql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| 24 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
queries/summary/LinesOfUserCode.ql |
6 changes: 6 additions & 0 deletions
6
rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
| my_struct.rs:0:0:0:0 | my_struct.rs | 11 | | ||
| main.rs:0:0:0:0 | main.rs | 4 | | ||
| my_macro.rs:0:0:0:0 | my_macro.rs | 4 | | ||
| does_not_compile.rs:0:0:0:0 | does_not_compile.rs | 3 | | ||
| error.rs:0:0:0:0 | error.rs | 2 | | ||
| lib.rs:0:0:0:0 | lib.rs | 0 | |
1 change: 1 addition & 0 deletions
1
rust/ql/test/query-tests/diagnostics/LinesOfUserCodeInFiles.qlref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
queries/summary/LinesOfUserCodeInFiles.ql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| Lines of code | 24 | | ||
| Lines of user code | 24 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
queries/summary/SummaryStats.ql |