mirror of
https://github.com/github/codeql.git
synced 2025-12-20 18:56:32 +01:00
Code quality improvements + add dedicated DeadRefTypes test
This commit is contained in:
@@ -1224,7 +1224,7 @@ ktPropertyDelegates(
|
||||
)
|
||||
|
||||
compiler_generated(
|
||||
unique int id: @top ref,
|
||||
unique int id: @element ref,
|
||||
int kind: int ref
|
||||
// 1: Kotlin declaring classes of adapter functions
|
||||
);
|
||||
// 1: Declaring classes of adapter functions in Kotlin
|
||||
)
|
||||
|
||||
@@ -41,6 +41,9 @@ class Element extends @element, Top {
|
||||
|
||||
/** Cast this element to a `Documentable`. */
|
||||
Documentable getDoc() { result = this }
|
||||
|
||||
/** Holds if this is an auxiliary program element generated by the compiler. */
|
||||
predicate isCompilerGenerated() { compiler_generated(this, _) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,7 +52,7 @@ predicate dead(RefType dead) {
|
||||
// Insist all source ancestors are dead as well.
|
||||
forall(RefType t | t.fromSource() and t = getASuperTypePlus(dead) | dead(t)) and
|
||||
// Exclude compiler generated classes (e.g. declaring type of adapter functions in Kotlin)
|
||||
not compiler_generated(dead, _)
|
||||
not dead.isCompilerGenerated()
|
||||
}
|
||||
|
||||
from RefType t, string kind
|
||||
|
||||
@@ -87,4 +87,4 @@ query predicate modifiers(ClassInstanceExpr e, Method m, string modifier) {
|
||||
m.hasModifier(modifier)
|
||||
}
|
||||
|
||||
query predicate compGenerated(Top t, int i) { compiler_generated(t, i) }
|
||||
query predicate compGenerated(Element e, int i) { compiler_generated(e, i) }
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
| test.kt:1:1:1:20 | C1 | Unused class: C1 is not referenced within this codebase. If not used as an external API it should be removed. |
|
||||
@@ -0,0 +1 @@
|
||||
Violations of Best Practice/Dead Code/DeadRefTypes.ql
|
||||
15
java/ql/test/kotlin/query-tests/DeadRefTypes/test.kt
Normal file
15
java/ql/test/kotlin/query-tests/DeadRefTypes/test.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
private class C1 { }
|
||||
|
||||
private class C2 { }
|
||||
|
||||
fun fn() {
|
||||
val c = C2()
|
||||
}
|
||||
|
||||
fun fn1() = 5
|
||||
|
||||
fun fn2(f: () -> Unit) = f()
|
||||
|
||||
fun adapted() {
|
||||
fn2(::fn1)
|
||||
}
|
||||
Reference in New Issue
Block a user