mirror of
https://github.com/github/codeql.git
synced 2025-12-23 20:26:32 +01:00
Remove Ruby specific parts from FileSystem.qll
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
/** Provides classes for working with files and folders. */
|
||||
|
||||
private import codeql_ruby.ast.internal.TreeSitter
|
||||
private import codeql.Locations
|
||||
|
||||
/** A file or folder. */
|
||||
@@ -169,28 +168,6 @@ class File extends Container, @file {
|
||||
/** Gets the URL of this file. */
|
||||
override string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }
|
||||
|
||||
/** Gets a token in this file. */
|
||||
private Generated::Token getAToken() { result.getLocation().getFile() = this }
|
||||
|
||||
/** Holds if `line` contains a token. */
|
||||
private predicate line(int line, boolean comment) {
|
||||
exists(Generated::Token token, Location l |
|
||||
token = this.getAToken() and
|
||||
l = token.getLocation() and
|
||||
line in [l.getStartLine() .. l.getEndLine()] and
|
||||
if token instanceof @token_comment then comment = true else comment = false
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the number of lines in this file. */
|
||||
int getNumberOfLines() { result = max([0, this.getAToken().getLocation().getEndLine()]) }
|
||||
|
||||
/** Gets the number of lines of code in this file. */
|
||||
int getNumberOfLinesOfCode() { result = count(int line | this.line(line, false)) }
|
||||
|
||||
/** 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) }
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import ast.Variable
|
||||
private import ast.internal.AST
|
||||
private import ast.internal.Scope
|
||||
private import ast.internal.Synthesis
|
||||
private import ast.internal.TreeSitter
|
||||
|
||||
/**
|
||||
* A node in the abstract syntax tree. This class is the base class for all Ruby
|
||||
@@ -104,3 +105,27 @@ class AstNode extends TAstNode {
|
||||
*/
|
||||
final AstNode getDesugared() { result = getSynthChild(this, -1) }
|
||||
}
|
||||
|
||||
class RubyFile extends File {
|
||||
/** Gets a token in this file. */
|
||||
private Ruby::Token getAToken() { result.getLocation().getFile() = this }
|
||||
|
||||
/** Holds if `line` contains a token. */
|
||||
private predicate line(int line, boolean comment) {
|
||||
exists(Ruby::Token token, Location l |
|
||||
token = this.getAToken() and
|
||||
l = token.getLocation() and
|
||||
line in [l.getStartLine() .. l.getEndLine()] and
|
||||
if token instanceof @ruby_token_comment then comment = true else comment = false
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the number of lines in this file. */
|
||||
int getNumberOfLines() { result = max([0, this.getAToken().getLocation().getEndLine()]) }
|
||||
|
||||
/** Gets the number of lines of code in this file. */
|
||||
int getNumberOfLinesOfCode() { result = count(int line | this.line(line, false)) }
|
||||
|
||||
/** Gets the number of lines of comments in this file. */
|
||||
int getNumberOfLinesOfComments() { result = count(int line | this.line(line, true)) }
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
|
||||
import ruby
|
||||
|
||||
from File f, int n
|
||||
from RubyFile f, int n
|
||||
where n = f.getNumberOfLines()
|
||||
select f, n order by n desc
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
|
||||
import ruby
|
||||
|
||||
from File f, int n
|
||||
from RubyFile f, int n
|
||||
where n = f.getNumberOfLinesOfCode()
|
||||
select f, n order by n desc
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
|
||||
import ruby
|
||||
|
||||
from File f, int n
|
||||
from RubyFile f, int n
|
||||
where n = f.getNumberOfLinesOfComments()
|
||||
select f, n order by n desc
|
||||
|
||||
@@ -12,4 +12,4 @@
|
||||
|
||||
import ruby
|
||||
|
||||
select sum(File f | exists(f.getRelativePath()) | f.getNumberOfLinesOfCode())
|
||||
select sum(RubyFile f | exists(f.getRelativePath()) | f.getNumberOfLinesOfCode())
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
import ruby
|
||||
|
||||
select sum(File f |
|
||||
select sum(RubyFile f |
|
||||
f.fromSource() and
|
||||
exists(f.getRelativePath()) and
|
||||
not f.getAbsolutePath().matches("%/vendor/%")
|
||||
|
||||
Reference in New Issue
Block a user