Allow to override suppression key for inspections
This commit is contained in:
committed by
Nikolay Krasko
parent
8196621be5
commit
697132561f
+15
-12
@@ -30,7 +30,7 @@ public abstract class AbstractKotlinInspection: LocalInspectionTool(), CustomSup
|
||||
public override fun getSuppressActions(element: PsiElement?): Array<SuppressIntentionAction>? {
|
||||
if (element == null) return emptyArray()
|
||||
|
||||
return createSuppressWarningActions(element, toSeverity(defaultLevel), this.shortName).toTypedArray()
|
||||
return createSuppressWarningActions(element, toSeverity(defaultLevel), suppressionKey).toTypedArray()
|
||||
}
|
||||
|
||||
public override fun isSuppressedFor(element: PsiElement): Boolean {
|
||||
@@ -39,25 +39,28 @@ public abstract class AbstractKotlinInspection: LocalInspectionTool(), CustomSup
|
||||
}
|
||||
|
||||
val project = element.project
|
||||
if (KotlinCacheService.getInstance(project).getSuppressionCache().isSuppressed(element, this.shortName, toSeverity(defaultLevel))) {
|
||||
if (KotlinCacheService.getInstance(project).getSuppressionCache().isSuppressed(element, suppressionKey, toSeverity(defaultLevel))) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
public fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {
|
||||
return when (highlightDisplayLevel) {
|
||||
HighlightDisplayLevel.DO_NOT_SHOW -> Severity.INFO
|
||||
protected open val suppressionKey: String get() = this.shortName.removePrefix("Kotlin")
|
||||
}
|
||||
|
||||
HighlightDisplayLevel.WARNING,
|
||||
HighlightDisplayLevel.WEAK_WARNING -> Severity.WARNING
|
||||
private fun toSeverity(highlightDisplayLevel: HighlightDisplayLevel): Severity {
|
||||
return when (highlightDisplayLevel) {
|
||||
HighlightDisplayLevel.DO_NOT_SHOW -> Severity.INFO
|
||||
|
||||
HighlightDisplayLevel.ERROR,
|
||||
HighlightDisplayLevel.GENERIC_SERVER_ERROR_OR_WARNING,
|
||||
HighlightDisplayLevel.NON_SWITCHABLE_ERROR -> Severity.ERROR
|
||||
HighlightDisplayLevel.WARNING,
|
||||
HighlightDisplayLevel.WEAK_WARNING -> Severity.WARNING
|
||||
|
||||
else -> Severity.ERROR
|
||||
}
|
||||
HighlightDisplayLevel.ERROR,
|
||||
HighlightDisplayLevel.GENERIC_SERVER_ERROR_OR_WARNING,
|
||||
HighlightDisplayLevel.NON_SWITCHABLE_ERROR -> Severity.ERROR
|
||||
|
||||
else -> Severity.ERROR
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
|
||||
public class UnusedReceiverParameterInspection : AbstractKotlinInspection() {
|
||||
override val suppressionKey: String get() = "unused"
|
||||
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
return object : KtVisitorVoid() {
|
||||
private fun check(callableDeclaration: KtCallableDeclaration) {
|
||||
|
||||
@@ -189,6 +189,8 @@ public class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
}
|
||||
}
|
||||
|
||||
override val suppressionKey: String get() = "unused"
|
||||
|
||||
private fun classOrObjectHasTextUsages(classOrObject: KtClassOrObject): Boolean {
|
||||
var hasTextUsages = false
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
@file:Suppress("UnusedImport")
|
||||
|
||||
import java.io.* // unused
|
||||
@@ -0,0 +1,7 @@
|
||||
@Suppress("warnings")
|
||||
val Any.v: Int
|
||||
get() = 123
|
||||
|
||||
@Suppress("unused")
|
||||
val Any.v1: Int
|
||||
get() = 123
|
||||
@@ -2,13 +2,13 @@ class Klass {
|
||||
fun unusedFun() {
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun unusedNoWarn() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
class OtherKlass {
|
||||
fun unusedNoWarn() {
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@ fun outer() {
|
||||
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun localNoWarn() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun otherFun() {
|
||||
fun localNoWarn() {
|
||||
|
||||
|
||||
+4
-4
@@ -3,7 +3,7 @@ class Klass {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun fNoWarn() {}
|
||||
|
||||
val p = 5
|
||||
@@ -19,17 +19,17 @@ class Klass {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun fNoWarn() {}
|
||||
|
||||
val p = 5
|
||||
}
|
||||
|
||||
fun localObject3() = @Suppress("UnusedSymbol") object {
|
||||
fun localObject3() = @Suppress("unused") object {
|
||||
fun fNoWarn() {}
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
private val localObject4 = object {
|
||||
fun fNoWarn() {}
|
||||
}
|
||||
|
||||
+2
-2
@@ -14,13 +14,13 @@ fun main(args: Array<String>) {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun fNoWarn() {}
|
||||
|
||||
val p = 5
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun localObject3() = object {
|
||||
fun fNoWarn() {}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ fun main(args: Array<String>) {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun fNoWarn() {}
|
||||
|
||||
val p = 5
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
class OtherClass {
|
||||
fun fNoWarn() {}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ fun main(args: Array<String>) {
|
||||
LocalClass().p
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun other() {
|
||||
class OtherClass {
|
||||
fun fNoWarn() {}
|
||||
|
||||
@@ -7,5 +7,5 @@ fun onlyInImport() {
|
||||
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun onlyInImportNoWarn() {}
|
||||
|
||||
@@ -2,5 +2,5 @@ fun unusedFun() {
|
||||
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun unusedNoWarn() {}
|
||||
|
||||
@@ -2,7 +2,7 @@ fun usedOnlyRecursively() {
|
||||
usedOnlyRecursively()
|
||||
}
|
||||
|
||||
@Suppress("UnusedSymbol")
|
||||
@Suppress("unused")
|
||||
fun usedOnlyRecursivelyNoWarn() {
|
||||
usedOnlyRecursivelyNoWarn()
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package suppressed
|
||||
|
||||
@Suppress("InvalidBundleOrProperty")
|
||||
fun testSuppressedOnFun() {
|
||||
K.message("foo.bar")
|
||||
J.message("foo.bar")
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Suppress 'KotlinUnusedImport' for file ${file}" "true"
|
||||
// "Suppress 'UnusedImport' for file ${file}" "true"
|
||||
|
||||
import<caret> java.io.*
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// "Suppress 'KotlinUnusedImport' for file ${file}" "true"
|
||||
// "Suppress 'UnusedImport' for file ${file}" "true"
|
||||
|
||||
@file:Suppress("KotlinUnusedImport")
|
||||
@file:Suppress("UnusedImport")
|
||||
|
||||
import java.io.*
|
||||
|
||||
|
||||
Reference in New Issue
Block a user