Merge pull request #175 from github/loc-summary-queries-1

Summary queries for total LOC and user-code LOC
This commit is contained in:
Alex Ford
2021-05-14 15:51:45 +01:00
committed by GitHub
9 changed files with 57 additions and 0 deletions

View File

@@ -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) }
}

View 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())

View 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()
)

View File

@@ -0,0 +1 @@
| 9 |

View File

@@ -0,0 +1 @@
queries/summary/LinesOfCode.ql

View File

@@ -0,0 +1 @@
| 5 |

View File

@@ -0,0 +1 @@
queries/summary/LinesOfUserCode.ql

View File

@@ -0,0 +1,11 @@
# comment
def hello
p "hello foo"
end
# another one
hello
p "more code here"

View File

@@ -0,0 +1,9 @@
# comment
def hello
p "hello lib"
end
# another one
hello