From d43ca9fe35c4ec4970d376c6277e023bd6887724 Mon Sep 17 00:00:00 2001 From: AleksandrSl Date: Mon, 30 Jul 2018 23:36:35 +0300 Subject: [PATCH] Regard SuppressWarnings also Add more test for different annotations use sites. --- .../kotlin/com/pinterest/ktlint/core/KtLint.kt | 4 +++- .../resources/spec/string-template/lint.kt.spec | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt index 8038e087a5..3cab5b07a8 100644 --- a/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt +++ b/ktlint-core/src/main/kotlin/com/pinterest/ktlint/core/KtLint.kt @@ -468,7 +468,7 @@ object KtLint { psi.annotationEntries .filter { it.calleeExpression?.constructorReferenceExpression - ?.getReferencedName() == "Suppress" + ?.getReferencedName() in suppressAnnotations }.flatMap(KtAnnotationEntry::getValueArguments) .mapNotNull { it.getArgumentExpression()?.text?.removeSurrounding("\"") } .mapNotNull(suppressAnnotationRuleMap::get) @@ -507,6 +507,8 @@ object KtLint { private val suppressAnnotationRuleMap = mapOf( "RemoveCurlyBracesFromTemplate" to "string-template" ) + + private val suppressAnnotations = setOf("Suppress", "SuppressWarnings") } } diff --git a/ktlint-ruleset-standard/src/test/resources/spec/string-template/lint.kt.spec b/ktlint-ruleset-standard/src/test/resources/spec/string-template/lint.kt.spec index a4d463dc34..a36ca8b1dc 100644 --- a/ktlint-ruleset-standard/src/test/resources/spec/string-template/lint.kt.spec +++ b/ktlint-ruleset-standard/src/test/resources/spec/string-template/lint.kt.spec @@ -26,6 +26,10 @@ fun main() { class B(val k: String) { override fun toString(): String = "${super.toString()}, ${super.hashCode().toString()}, k=$k" + + @Suppress("RemoveCurlyBracesFromTemplate", "Shit") + val a + get() = "${s0}" } @Suppress("RemoveCurlyBracesFromTemplate") @@ -33,9 +37,22 @@ class C { override fun toString(): String = "${s0}" } +class D { + @Suppress("RemoveCurlyBracesFromTemplate") + override fun toString(): String = "${s0}" + + fun test() = "${s0}" +} + +@SuppressWarnings("RemoveCurlyBracesFromTemplate") +class E { + override fun toString(): String = "${s0}" +} + // expect // 2:29:Redundant "toString()" call in string template // 3:28:Redundant "toString()" call in string template // 6:15:Redundant curly braces // 7:15:Redundant curly braces // 28:79:Redundant "toString()" call in string template +// 44:20:Redundant curly braces