Skip to content

Commit

Permalink
Improve finding message of ExplicitItLambdaParameter (#5117)
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Jul 29, 2022
1 parent 0d6f790 commit ddd7ccf
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.psi.KtLambdaExpression
/**
* Lambda expressions are one of the core features of the language. They often include very small chunks of
* code using only one parameter. In this cases Kotlin can supply the implicit `it` parameter
* to make code more concise. It fits most usecases, but when faced larger or nested chunks of code,
* to make code more concise. It fits most use cases, but when faced larger or nested chunks of code,
* you might want to add an explicit name for the parameter. Naming it just `it` is meaningless and only
* makes your code misleading, especially when dealing with nested functions.
*
Expand Down Expand Up @@ -55,11 +55,16 @@ class ExplicitItLambdaParameter(val config: Config) : Rule(config) {
super.visitLambdaExpression(lambdaExpression)
val parameterNames = lambdaExpression.valueParameters.map { it.name }
if (IT_LITERAL in parameterNames) {
val message = if (parameterNames.size == 1) {
"This explicit usage of `it` as the lambda parameter name can be omitted."
} else {
"`it` should not be used as name for a lambda parameter."
}
report(
CodeSmell(
issue,
Entity.from(lambdaExpression),
"This explicit usage of `it` as the lambda parameter name can be omitted."
message
)
)
}
Expand Down

0 comments on commit ddd7ccf

Please sign in to comment.