Function declares six or more parameters
ID |
rust.maintainability.max_params |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Complexity |
Language |
Rust |
Description
Reports a function or method whose parameter list holds six or more parameters, not counting a self receiver. The threshold is fixed at six, since OpenGrep matches a declared arity rather than counting one.
Rationale
A long parameter list is easy to call incorrectly: adjacent parameters of the same type can be swapped and still compile, and callers have to keep the order in their head because Rust has no named arguments. It is also a reliable sign that the function is doing several jobs, or that a group of the parameters really belongs together as one value.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Function declares six or more parameters
pub fn render(title: &str, width: u32, height: u32, dpi: u32, margin: u32, footer: &str) -> String {
format!("{}{}{}{}{}{}", title, width, height, dpi, margin, footer)
}