Skip to content

Commit

Permalink
Enable UseAnyOrNoneInsteadOfFind
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Dec 9, 2021
1 parent 92433ea commit 15b265a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions config/detekt/detekt.yml
Expand Up @@ -227,6 +227,8 @@ style:
UnusedPrivateMember:
active: true
allowedNames: '(_|ignored|expected)'
UseAnyOrNoneInsteadOfFind:
active: true
UseCheckOrError:
active: true
UseEmptyCounterpart:
Expand Down
Expand Up @@ -28,8 +28,7 @@ class AnnotationExcluder(
* Is true if any given annotation name is declared in the SplitPattern
* which basically describes entries to exclude.
*/
fun shouldExclude(annotations: List<KtAnnotationEntry>): Boolean =
annotations.firstOrNull(::isExcluded) != null
fun shouldExclude(annotations: List<KtAnnotationEntry>): Boolean = annotations.any(::isExcluded)

private fun isExcluded(annotation: KtAnnotationEntry): Boolean {
val annotationText = annotation.typeReference?.text
Expand Down
Expand Up @@ -25,7 +25,7 @@ class FileProcessorLocatorSpec : Spek({

assertThat(processorClasses).isNotEmpty
processorClasses
.filter { clazz -> processors.firstOrNull { clazz == it.javaClass } == null }
.filter { clazz -> processors.any { clazz == it.javaClass } }
.forEach { fail("$it processor is not loaded by the FileProcessorLocator") }
}

Expand Down
Expand Up @@ -20,7 +20,7 @@ class RuleSetLocatorSpec : Spek({

assertThat(providerClasses).isNotEmpty
providerClasses
.filter { clazz -> providers.firstOrNull { it.javaClass == clazz } == null }
.filter { clazz -> providers.any { it.javaClass == clazz } }
.forEach { fail("$it rule set is not loaded by the RuleSetLocator") }
}

Expand Down
Expand Up @@ -41,5 +41,5 @@ class Deprecation(config: Config) : Rule(config) {
private fun hasDeprecationCompilerWarnings(element: PsiElement) =
bindingContext.diagnostics
.forElement(element)
.firstOrNull { it.factory == Errors.DEPRECATION } != null
.any { it.factory == Errors.DEPRECATION }
}
Expand Up @@ -79,7 +79,8 @@ class MandatoryBracesLoops(config: Config = Config.empty) : Rule(config) {
val hasNoBraces = expression.rightParenthesis
?.siblings(forward = true, withItself = false)
?.filterIsInstance<PsiWhiteSpace>()
?.firstOrNull { it.textContains('\n') } != null
?.any { it.textContains('\n') }
?: false
if (hasNoBraces) {
report(CodeSmell(issue, Entity.from(expression.body ?: expression), message = DESCRIPTION))
}
Expand All @@ -92,7 +93,7 @@ class MandatoryBracesLoops(config: Config = Config.empty) : Rule(config) {
val hasNoBraces = expression.siblings(forward = true, withItself = false)
.takeWhile { it != expression.whileKeyword }
.filterIsInstance<PsiWhiteSpace>()
.firstOrNull { it.textContains('\n') } != null
.any { it.textContains('\n') }
if (hasNoBraces) {
report(CodeSmell(issue, Entity.from(expression.body ?: expression), message = DESCRIPTION))
}
Expand Down

0 comments on commit 15b265a

Please sign in to comment.