Merge pull request #10949 from tamasvajk/kotlin-underscore-var

Kotlin: exclude Kotlin files from `java/underscore-identifier`
This commit is contained in:
Tamás Vajk
2022-10-24 13:32:49 +02:00
committed by GitHub
6 changed files with 23 additions and 1 deletions

View File

@@ -22,7 +22,7 @@ class IdentifierElement extends Element {
from IdentifierElement e, string msg
where
e.fromSource() and
e.getCompilationUnit().isJavaSourceFile() and
not e.(Constructor).isDefaultConstructor() and
(
e.getName() = "_" and

View File

@@ -0,0 +1,11 @@
fun fn() {
try {
val l = listOf(1, 2, 3)
l.forEachIndexed { index, _ -> println(index) }
val p = Pair(1, 2)
val (first, _) = p
} catch (_: Exception) {
// expected
}
}

View File

@@ -0,0 +1 @@
Compatibility/JDK9/UnderscoreIdentifier.ql

View File

@@ -0,0 +1,7 @@
| Test.kt:3:9:3:31 | List<Integer> l |
| Test.kt:4:28:4:32 | index |
| Test.kt:4:35:4:35 | p1 |
| Test.kt:6:9:6:26 | Pair<Integer,Integer> p |
| Test.kt:7:14:7:18 | int first |
| Test.kt:7:26:7:26 | Pair<Integer,Integer> tmp0_container |
| Test.kt:8:14:8:25 | Exception _ |

View File

@@ -0,0 +1,3 @@
import java
query predicate variables(Variable v) { v.fromSource() }