Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable UseAnyOrNoneInsteadOfFind #4362

Merged
merged 1 commit into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.none { 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.none { 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