mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
Merge pull request #6073 from geoffw0/loc
C++: Add lines of user code query
This commit is contained in:
17
cpp/ql/src/Summary/LinesOfUserCode.ql
Normal file
17
cpp/ql/src/Summary/LinesOfUserCode.ql
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @name Total lines of user written C/C++ code in the database
|
||||
* @description The total number of lines of C/C++ code from the source code directory, excluding auto-generated files. This query counts the lines of code, excluding whitespace or comments. Note: If external libraries are included in the codebase either in a checked-in virtual environment or as vendored code, that will currently be counted as user written code.
|
||||
* @kind metric
|
||||
* @tags summary
|
||||
* lines-of-code
|
||||
* @id cpp/summary/lines-of-user-code
|
||||
*/
|
||||
|
||||
import cpp
|
||||
import semmle.code.cpp.AutogeneratedFile
|
||||
|
||||
select sum(File f |
|
||||
f.fromSource() and exists(f.getRelativePath()) and not f instanceof AutogeneratedFile
|
||||
|
|
||||
f.getMetrics().getNumberOfLinesOfCode()
|
||||
)
|
||||
@@ -1 +1 @@
|
||||
| 93 |
|
||||
| 96 |
|
||||
|
||||
1
cpp/ql/test/query-tests/Summary/LinesOfUserCode.expected
Normal file
1
cpp/ql/test/query-tests/Summary/LinesOfUserCode.expected
Normal file
@@ -0,0 +1 @@
|
||||
| 93 |
|
||||
1
cpp/ql/test/query-tests/Summary/LinesOfUserCode.qlref
Normal file
1
cpp/ql/test/query-tests/Summary/LinesOfUserCode.qlref
Normal file
@@ -0,0 +1 @@
|
||||
Summary/LinesOfUserCode.ql
|
||||
12
cpp/ql/test/query-tests/Summary/generated-file.cpp
Normal file
12
cpp/ql/test/query-tests/Summary/generated-file.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* This file is generated by abc.xyz. Do not edit!
|
||||
*
|
||||
* (except that this isn't really a generated file, but the above is the typical sort of comment
|
||||
* you see at the beginning of a true generated file).
|
||||
*/
|
||||
|
||||
int generated_function() {
|
||||
// ...
|
||||
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user