mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
* Reverse behaviour change introduced in #4139 https://github.com/detekt/detekt/pull/4139/files#r719991365 * Handle nullability at call site https://github.com/detekt/detekt/pull/4139/files#r719992612
This commit is contained in:
@@ -32,8 +32,9 @@ fun main(args: Array<String>) {
|
||||
else -> cause.printStackTrace()
|
||||
}
|
||||
}
|
||||
else -> exitProcess(result.exitCode())
|
||||
else -> Unit // print nothing extra when there is no error
|
||||
}
|
||||
exitProcess(result.exitCode())
|
||||
}
|
||||
|
||||
@NotApiButProbablyUsedByUsers
|
||||
|
||||
@@ -37,7 +37,7 @@ fun getIntValueForPsiElement(element: PsiElement): Int? {
|
||||
|
||||
fun KtClass.companionObject() = this.companionObjects.singleOrNull { it.isCompanion() }
|
||||
|
||||
inline fun <reified T : Any> Any?.safeAs(): T? = this as? T
|
||||
inline fun <reified T : Any> Any.safeAs(): T? = this as? T
|
||||
|
||||
fun KtCallExpression.receiverIsUsed(context: BindingContext): Boolean =
|
||||
(parent as? KtQualifiedExpression)?.let {
|
||||
|
||||
@@ -77,7 +77,7 @@ class UseIsNullOrEmpty(config: Config = Config.empty) : Rule(config) {
|
||||
right.isNullKeyword() -> left
|
||||
left.isNullKeyword() -> right
|
||||
else -> null
|
||||
}.safeAs<KtSimpleNameExpression>()?.takeIf { it.getType(bindingContext)?.isNullable() == true }
|
||||
}?.safeAs<KtSimpleNameExpression>()?.takeIf { it.getType(bindingContext)?.isNullable() == true }
|
||||
}
|
||||
|
||||
private fun KtExpression.sizeCheckedExpression(): KtSimpleNameExpression? {
|
||||
@@ -131,8 +131,8 @@ class UseIsNullOrEmpty(config: Config = Config.empty) : Rule(config) {
|
||||
private fun KtExpression?.isEmptyString() = this?.text == "\"\""
|
||||
|
||||
private fun KtExpression?.isCalling(fqNames: List<FqName>): Boolean {
|
||||
val callExpression = safeAs()
|
||||
?: safeAs<KtDotQualifiedExpression>()?.selectorExpression.safeAs<KtCallExpression>()
|
||||
val callExpression = this?.safeAs()
|
||||
?: safeAs<KtDotQualifiedExpression>()?.selectorExpression?.safeAs<KtCallExpression>()
|
||||
?: return false
|
||||
return callExpression.calleeExpression?.text in fqNames.map { it.shortName().asString() } &&
|
||||
callExpression.getResolvedCall(bindingContext)?.resultingDescriptor?.fqNameOrNull() in fqNames
|
||||
|
||||
Reference in New Issue
Block a user