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 rule documentaion and smell message of NamedArguments #4796

Merged
merged 1 commit into from May 8, 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 @@ -17,7 +17,8 @@ import org.jetbrains.kotlin.resolve.calls.util.getParameterForArgument
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall

/**
* Reports function invocations which have more parameters than a certain threshold and are all not named.
* Reports function invocations which have more arguments than a certain threshold and are all not named. Calls with
* too many arguments are more difficult to understand so a named arguments help.
*
* <noncompliant>
* fun sum(a: Int, b: Int, c: Int, d: Int) {
Expand All @@ -37,7 +38,7 @@ class NamedArguments(config: Config = Config.empty) : Rule(config) {
override val issue = Issue(
"NamedArguments",
Severity.Maintainability,
"Named arguments are required for function invocation with many parameters.",
"Named arguments are required for function calls with many arguments.",
Debt.FIVE_MINS
)

Expand All @@ -51,7 +52,9 @@ class NamedArguments(config: Config = Config.empty) : Rule(config) {
if (bindingContext == BindingContext.EMPTY) return
val valueArguments = expression.valueArguments
if (valueArguments.size > threshold && expression.canNameArguments()) {
report(CodeSmell(issue, Entity.from(expression), issue.description))
val message = "This function call has ${valueArguments.size} arguments. To call a function with more " +
"than $threshold arguments you should set the name of each argument."
report(CodeSmell(issue, Entity.from(expression), message))
} else {
super.visitCallExpression(expression)
}
Expand Down