Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6bd2e4e

Browse files
authored
Merge pull request #175 from github/loc-summary-queries-1
Summary queries for total LOC and user-code LOC
2 parents 11949c6 + e589604 commit 6bd2e4e

9 files changed

Lines changed: 57 additions & 0 deletions

File tree

ql/src/codeql/files/FileSystem.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,7 @@ class File extends Container, @file {
190190

191191
/** Gets the number of lines of comments in this file. */
192192
int getNumberOfLinesOfComments() { result = count(int line | this.line(line, true)) }
193+
194+
/** Holds if this file was extracted from ordinary source code. */
195+
predicate fromSource() { files(this, _, _, _, 1) }
193196
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @id rb/summary/lines-of-code
3+
* @name Total lines of Ruby code in the database
4+
* @description The total number of lines of Ruby code across all files,
5+
* including vendored code, tests. This query counts the lines of code,
6+
* excluding whitespace or comments.
7+
* @kind metric
8+
* @tags summary
9+
*/
10+
11+
import ruby
12+
13+
select sum(File f | | f.getNumberOfLinesOfCode())
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @id rb/summary/lines-of-user-code
3+
* @name Lines of authored Ruby code in the database
4+
* @description The total number of lines of Ruby code across files, excluding library and generated code.
5+
* @kind metric
6+
* @tags summary
7+
*/
8+
9+
import ruby
10+
11+
select sum(File f |
12+
f.fromSource() and
13+
exists(f.getRelativePath()) and
14+
not f.getAbsolutePath().matches("%/vendor/%")
15+
|
16+
f.getNumberOfLinesOfCode()
17+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| 9 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/summary/LinesOfCode.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| 5 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/summary/LinesOfUserCode.ql
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# comment
2+
3+
def hello
4+
p "hello foo"
5+
end
6+
7+
# another one
8+
9+
hello
10+
11+
p "more code here"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# comment
2+
3+
def hello
4+
p "hello lib"
5+
end
6+
7+
# another one
8+
9+
hello

0 commit comments

Comments
 (0)