Named Arguments
ID |
kotlin.named_arguments |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Kotlin |
Tags |
readability, style |
Description
Reports function calls that pass many positional arguments without using Kotlin’s named-argument syntax.
Calls with four or more unnamed positional arguments are read-hostile — move(10, 20, true, false, "fast") is
virtually unparseable by a reader without checking the function declaration.
Rationale
Positional-only calls silently accept transposed or swapped arguments, and their intent is opaque at the call site. Named arguments document the mapping between values and parameters, and allow the compiler to catch accidental transpositions.
// Bad — no named arguments; what do true, false, "fast" mean?
move(10, 20, true, false, "fast") // FLAW
// Good — self-documenting call
move(x = 10, y = 20, smooth = true, force = false, speed = "fast")
Remediation
Add named arguments at the call site. The threshold (default 4) is configurable via the threshold property.