mirror of
https://github.com/github/codeql.git
synced 2026-04-20 14:34:04 +02:00
Merge pull request #175 from github/loc-summary-queries-1
Summary queries for total LOC and user-code LOC
This commit is contained in:
@@ -190,4 +190,7 @@ class File extends Container, @file {
|
||||
|
||||
/** Gets the number of lines of comments in this file. */
|
||||
int getNumberOfLinesOfComments() { result = count(int line | this.line(line, true)) }
|
||||
|
||||
/** Holds if this file was extracted from ordinary source code. */
|
||||
predicate fromSource() { files(this, _, _, _, 1) }
|
||||
}
|
||||
|
||||
13
ql/src/queries/summary/LinesOfCode.ql
Normal file
13
ql/src/queries/summary/LinesOfCode.ql
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @id rb/summary/lines-of-code
|
||||
* @name Total lines of Ruby code in the database
|
||||
* @description The total number of lines of Ruby code across all files,
|
||||
* including vendored code, tests. This query counts the lines of code,
|
||||
* excluding whitespace or comments.
|
||||
* @kind metric
|
||||
* @tags summary
|
||||
*/
|
||||
|
||||
import ruby
|
||||
|
||||
select sum(File f | | f.getNumberOfLinesOfCode())
|
||||
17
ql/src/queries/summary/LinesOfUserCode.ql
Normal file
17
ql/src/queries/summary/LinesOfUserCode.ql
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @id rb/summary/lines-of-user-code
|
||||
* @name Lines of authored Ruby code in the database
|
||||
* @description The total number of lines of Ruby code across files, excluding library and generated code.
|
||||
* @kind metric
|
||||
* @tags summary
|
||||
*/
|
||||
|
||||
import ruby
|
||||
|
||||
select sum(File f |
|
||||
f.fromSource() and
|
||||
exists(f.getRelativePath()) and
|
||||
not f.getAbsolutePath().matches("%/vendor/%")
|
||||
|
|
||||
f.getNumberOfLinesOfCode()
|
||||
)
|
||||
1
ql/test/query-tests/summary/LinesOfCode.expected
Normal file
1
ql/test/query-tests/summary/LinesOfCode.expected
Normal file
@@ -0,0 +1 @@
|
||||
| 9 |
|
||||
1
ql/test/query-tests/summary/LinesOfCode.qlref
Normal file
1
ql/test/query-tests/summary/LinesOfCode.qlref
Normal file
@@ -0,0 +1 @@
|
||||
queries/summary/LinesOfCode.ql
|
||||
1
ql/test/query-tests/summary/LinesOfUserCode.expected
Normal file
1
ql/test/query-tests/summary/LinesOfUserCode.expected
Normal file
@@ -0,0 +1 @@
|
||||
| 5 |
|
||||
1
ql/test/query-tests/summary/LinesOfUserCode.qlref
Normal file
1
ql/test/query-tests/summary/LinesOfUserCode.qlref
Normal file
@@ -0,0 +1 @@
|
||||
queries/summary/LinesOfUserCode.ql
|
||||
11
ql/test/query-tests/summary/src/foo.rb
Normal file
11
ql/test/query-tests/summary/src/foo.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# comment
|
||||
|
||||
def hello
|
||||
p "hello foo"
|
||||
end
|
||||
|
||||
# another one
|
||||
|
||||
hello
|
||||
|
||||
p "more code here"
|
||||
9
ql/test/query-tests/summary/src/vendor/cache/lib.rb
vendored
Normal file
9
ql/test/query-tests/summary/src/vendor/cache/lib.rb
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# comment
|
||||
|
||||
def hello
|
||||
p "hello lib"
|
||||
end
|
||||
|
||||
# another one
|
||||
|
||||
hello
|
||||
Reference in New Issue
Block a user