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

Improve finding message of ExplicitItLambdaParameter #5117

Merged
merged 1 commit into from Jul 29, 2022
Merged
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
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