diff --git a/ql/src/codeql/files/FileSystem.qll b/ql/src/codeql/files/FileSystem.qll index 372a53b53c0..d9da4d01cac 100644 --- a/ql/src/codeql/files/FileSystem.qll +++ b/ql/src/codeql/files/FileSystem.qll @@ -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) } } diff --git a/ql/src/queries/summary/LinesOfUserCode.ql b/ql/src/queries/summary/LinesOfUserCode.ql new file mode 100644 index 00000000000..c7dbb7ee5ba --- /dev/null +++ b/ql/src/queries/summary/LinesOfUserCode.ql @@ -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() + )