mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Kotlin: Recognize generated files
This commit is contained in:
@@ -51,9 +51,9 @@ library class MarkerCommentGeneratedFile extends GeneratedFile {
|
||||
/**
|
||||
* A marker comment that indicates that it is in a generated file.
|
||||
*/
|
||||
private class GeneratedFileMarker extends Top instanceof JavadocElement {
|
||||
private class GeneratedFileMarker extends Top {
|
||||
GeneratedFileMarker() {
|
||||
exists(string msg | msg = this.getText() |
|
||||
exists(string msg | msg = this.(JavadocElement).getText() or msg = this.(KtComment).getText() |
|
||||
msg.regexpMatch("(?i).*\\bGenerated By\\b.*\\bDo not edit\\b.*") or
|
||||
msg.regexpMatch("(?i).*\\bThis (file|class|interface|art[ei]fact) (was|is|(has been)) (?:auto[ -]?)?gener(e?)ated.*") or
|
||||
msg.regexpMatch("(?i).*\\bAny modifications to this file will be lost\\b.*") or
|
||||
@@ -65,3 +65,10 @@ private class GeneratedFileMarker extends Top instanceof JavadocElement {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A file detected as generated by the Kotlin Annotation Processing Tool (kapt). Detection is based on file path.
|
||||
*/
|
||||
private class KaptFile extends GeneratedFile {
|
||||
KaptFile() { this.getRelativePath().matches("%/generated/source/kapt%") }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
| Generated.kt:0:0:0:0 | Generated |
|
||||
| generated/source/kapt/Generated.kt:0:0:0:0 | Generated |
|
||||
@@ -0,0 +1,3 @@
|
||||
// This file was auto generated by me
|
||||
|
||||
class B
|
||||
@@ -0,0 +1,4 @@
|
||||
import java
|
||||
|
||||
from GeneratedFile f
|
||||
select f
|
||||
@@ -0,0 +1,3 @@
|
||||
// This file was not generated
|
||||
|
||||
class A
|
||||
@@ -0,0 +1 @@
|
||||
class D
|
||||
@@ -0,0 +1 @@
|
||||
class C
|
||||
Reference in New Issue
Block a user