-
-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support suppressing of different rules - #6
- Loading branch information
1 parent
8cb34a8
commit f0356c9
Showing
6 changed files
with
105 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/Suppressible.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.gitlab.arturbosch.detekt.api | ||
|
||
import org.jetbrains.kotlin.preprocessor.typeReferenceName | ||
import org.jetbrains.kotlin.psi.KtAnnotated | ||
import org.jetbrains.kotlin.psi.KtElement | ||
|
||
/** | ||
* @author Artur Bosch | ||
*/ | ||
|
||
/** | ||
* Checks if this psi element is suppressed by @Suppress or @SuppressWarnings annotations. | ||
*/ | ||
fun KtElement.isSuppressedBy(id: String): Boolean { | ||
return this is KtAnnotated && this.isSuppressedBy(id) | ||
} | ||
|
||
/** | ||
* Checks if this kt element is suppressed by @Suppress or @SuppressWarnings annotations. | ||
*/ | ||
fun KtAnnotated.isSuppressedBy(id: String): Boolean { | ||
return annotationEntries.find { it.typeReferenceName == "SuppressWarnings" } | ||
?.valueArguments | ||
?.find { it.getArgumentExpression()?.text?.replace("\"", "") == id } != null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @author Artur Bosch | ||
*/ | ||
|
||
@SuppressWarnings("LongParameterList") | ||
fun lpl(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) = (a + b + c + d + e + f).apply { | ||
assert(false) { "FAILED TEST" } | ||
} | ||
|
||
@SuppressWarnings("LongMethod") | ||
fun lm() { | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
lpl(1, 2, 3, 4, 5, 6) | ||
assert(false) { "FAILED TEST" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,6 @@ | |
object SuppressedObject { | ||
|
||
fun stuff() { | ||
println("Stuff") | ||
println("FAILED TEST") | ||
} | ||
} | ||
} |