mirror of
https://github.com/github/codeql.git
synced 2026-05-03 04:39:29 +02:00
Java: Delete filter queries.
This commit is contained in:
55
java/ql/src/external/DefectFilter.qll
vendored
55
java/ql/src/external/DefectFilter.qll
vendored
@@ -1,55 +0,0 @@
|
||||
/** Provides a class for working with defect query results stored in dashboard databases. */
|
||||
|
||||
import java
|
||||
|
||||
/**
|
||||
* Holds if `id` in the opaque identifier of a result reported by query `queryPath`,
|
||||
* such that `message` is the associated message and the location of the result spans
|
||||
* column `startcolumn` of line `startline` to column `endcolumn` of line `endline`
|
||||
* in file `filepath`.
|
||||
*
|
||||
* For more information, see [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
|
||||
*/
|
||||
external predicate defectResults(
|
||||
int id, string queryPath, string file, int startline, int startcol, int endline, int endcol,
|
||||
string message
|
||||
);
|
||||
|
||||
/**
|
||||
* A defect query result stored in a dashboard database.
|
||||
*/
|
||||
class DefectResult extends int {
|
||||
DefectResult() { defectResults(this, _, _, _, _, _, _, _) }
|
||||
|
||||
/** Gets the path of the query that reported the result. */
|
||||
string getQueryPath() { defectResults(this, result, _, _, _, _, _, _) }
|
||||
|
||||
/** Gets the file in which this query result was reported. */
|
||||
File getFile() {
|
||||
exists(string path | defectResults(this, _, path, _, _, _, _, _) |
|
||||
result.getAbsolutePath() = path
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the line on which the location of this query result starts. */
|
||||
int getStartLine() { defectResults(this, _, _, result, _, _, _, _) }
|
||||
|
||||
/** Gets the column on which the location of this query result starts. */
|
||||
int getStartColumn() { defectResults(this, _, _, _, result, _, _, _) }
|
||||
|
||||
/** Gets the line on which the location of this query result ends. */
|
||||
int getEndLine() { defectResults(this, _, _, _, _, result, _, _) }
|
||||
|
||||
/** Gets the column on which the location of this query result ends. */
|
||||
int getEndColumn() { defectResults(this, _, _, _, _, _, result, _) }
|
||||
|
||||
/** Gets the message associated with this query result. */
|
||||
string getMessage() { defectResults(this, _, _, _, _, _, _, result) }
|
||||
|
||||
/** Gets the URL corresponding to the location of this query result. */
|
||||
string getURL() {
|
||||
result =
|
||||
"file://" + getFile().getAbsolutePath() + ":" + getStartLine() + ":" + getStartColumn() + ":" +
|
||||
getEndLine() + ":" + getEndColumn()
|
||||
}
|
||||
}
|
||||
44
java/ql/src/external/MetricFilter.qll
vendored
44
java/ql/src/external/MetricFilter.qll
vendored
@@ -1,44 +0,0 @@
|
||||
import java
|
||||
|
||||
external predicate metricResults(
|
||||
int id, string queryPath, string file, int startline, int startcol, int endline, int endcol,
|
||||
float value
|
||||
);
|
||||
|
||||
class MetricResult extends int {
|
||||
MetricResult() { metricResults(this, _, _, _, _, _, _, _) }
|
||||
|
||||
string getQueryPath() { metricResults(this, result, _, _, _, _, _, _) }
|
||||
|
||||
File getFile() {
|
||||
exists(string path |
|
||||
metricResults(this, _, path, _, _, _, _, _) and result.getAbsolutePath() = path
|
||||
)
|
||||
}
|
||||
|
||||
int getStartLine() { metricResults(this, _, _, result, _, _, _, _) }
|
||||
|
||||
int getStartColumn() { metricResults(this, _, _, _, result, _, _, _) }
|
||||
|
||||
int getEndLine() { metricResults(this, _, _, _, _, result, _, _) }
|
||||
|
||||
int getEndColumn() { metricResults(this, _, _, _, _, _, result, _) }
|
||||
|
||||
predicate hasMatchingLocation() { exists(this.getMatchingLocation()) }
|
||||
|
||||
Location getMatchingLocation() {
|
||||
result.getFile() = this.getFile() and
|
||||
result.getStartLine() = this.getStartLine() and
|
||||
result.getEndLine() = this.getEndLine() and
|
||||
result.getStartColumn() = this.getStartColumn() and
|
||||
result.getEndColumn() = this.getEndColumn()
|
||||
}
|
||||
|
||||
float getValue() { metricResults(this, _, _, _, _, _, _, result) }
|
||||
|
||||
string getURL() {
|
||||
result =
|
||||
"file://" + getFile().getAbsolutePath() + ":" + getStartLine() + ":" + getStartColumn() + ":" +
|
||||
getEndLine() + ":" + getEndColumn()
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* @name Filter: only keep results from source
|
||||
* @description Shows how to filter for only certain files
|
||||
* @kind problem
|
||||
* @id java/source-filter
|
||||
*/
|
||||
|
||||
import java
|
||||
import external.DefectFilter
|
||||
|
||||
from DefectResult res, CompilationUnit cu
|
||||
where
|
||||
cu = res.getFile() and
|
||||
cu.fromSource()
|
||||
select res, res.getMessage()
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* @name Filter: non-generated files
|
||||
* @description Only keep results that aren't in generated files
|
||||
* @kind problem
|
||||
* @id java/not-generated-file-filter
|
||||
*/
|
||||
|
||||
import java
|
||||
import external.DefectFilter
|
||||
|
||||
from DefectResult res
|
||||
where not res.getFile() instanceof GeneratedFile
|
||||
select res, res.getMessage()
|
||||
@@ -1,13 +0,0 @@
|
||||
/**
|
||||
* @name Metric Filter: non-generated files
|
||||
* @description Only keep metric results that aren't in generated files
|
||||
* @kind treemap
|
||||
* @id java/not-generated-file-metric-filter
|
||||
*/
|
||||
|
||||
import java
|
||||
import external.MetricFilter
|
||||
|
||||
from MetricResult res
|
||||
where not res.getFile() instanceof GeneratedFile
|
||||
select res, res.getValue()
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
* @name Filter: Suppression comments
|
||||
* @description Recognise comments containing `NOSEMMLE` as suppression comments
|
||||
* when they appear on a line containing an alert or the
|
||||
* immediately preceding line. As further customisations,
|
||||
* `NOSEMMLE(some text)` will only suppress alerts where the
|
||||
* message contains "some text", and `NOSEMMLE/some regex/` will
|
||||
* only suppress alerts where the message contains a match of the
|
||||
* regex. No special way of escaping `)` or `/` in the suppression
|
||||
* comment argument is provided.
|
||||
* @kind problem
|
||||
* @id java/nosemmle-suppression-comment-filter
|
||||
*/
|
||||
|
||||
import java
|
||||
import external.DefectFilter
|
||||
|
||||
class SuppressionComment extends Javadoc {
|
||||
SuppressionComment() { this.getAChild*().getText().matches("%NOSEMMLE%") }
|
||||
|
||||
private string getASuppressionDirective() {
|
||||
result = this.getAChild*().getText().regexpFind("\\bNOSEMMLE\\b(\\([^)]+?\\)|/[^/]+?/|)", _, 0)
|
||||
}
|
||||
|
||||
private string getAnActualSubstringArg() {
|
||||
result = this.getASuppressionDirective().regexpCapture("NOSEMMLE\\((.*)\\)", 1)
|
||||
}
|
||||
|
||||
private string getAnActualRegexArg() {
|
||||
result = ".*" + this.getASuppressionDirective().regexpCapture("NOSEMMLE/(.*)/", 1) + ".*"
|
||||
}
|
||||
|
||||
private string getASuppressionRegex() {
|
||||
result = getAnActualRegexArg()
|
||||
or
|
||||
exists(string substring | substring = getAnActualSubstringArg() |
|
||||
result = "\\Q" + substring.replaceAll("\\E", "\\E\\\\E\\Q") + "\\E"
|
||||
)
|
||||
or
|
||||
result = ".*" and getASuppressionDirective() = "NOSEMMLE"
|
||||
}
|
||||
|
||||
predicate suppresses(DefectResult res) {
|
||||
this.getFile() = res.getFile() and
|
||||
res.getEndLine() - this.getLocation().getEndLine() in [0 .. 2] and
|
||||
res.getMessage().regexpMatch(this.getASuppressionRegex())
|
||||
}
|
||||
}
|
||||
|
||||
from DefectResult res
|
||||
where not exists(SuppressionComment s | s.suppresses(res))
|
||||
select res, res.getMessage()
|
||||
Reference in New Issue
Block a user