Repository navigation
Add disallow_default_parameter opt-in rule - #6506
Conversation
Generated by 🚫 Danger |
SimplyDanny
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
There are a few remarks I'd like to have addressed before merging.
|
Hi @SimplyDanny, I've addressed all the review feedback in the previous push — description updated, kind changed to |
SimplyDanny
left a comment
There was a problem hiding this comment.
I'd still like to understand what the reasoning behind internal as a default is. Why not package, fileprivate and private as well?
Before you change anything, let's first discuss the "why" and "what".
|
Good point. I was being conservative with the default, but you're right — the rationale applies equally to I'd propose changing the default to |
I'd definitely support |
|
Good point — agreed. I've updated the default to |
Adds a new opt-in rule that flags default parameter values on functions with certain access levels. By default, it disallows defaults on private and internal functions, encouraging explicit parameter passing at non-public API boundaries. Configurable via `disallowed_access_levels` to target any combination of `private`, `fileprivate`, `internal`, and `package`. Closes #6488
- Change kind from .idiomatic to .lint - Use per-violation reason with access level name - Unify subscript handling via ParameterClauseSyntax - Use optional binding instead of where + force unwrap - Remove postprocessor from configuration - Default to [.internal] only (most common implicit level) - Inline examples into rule description - Add CHANGELOG entry
Per SimplyDanny's feedback: include package in the default set alongside internal, since both are module-scoped. Exclude private and fileprivate as their scope is small enough that default arguments are easy to discover.
New Rule
Adds a new opt-in rule
disallow_default_parameterthat flags default parameter values on functions with certain access levels.Motivation
As described in #6488, default parameter values on non-public functions can mask bugs when parameters aren't properly forwarded. This rule enforces explicit parameterization at internal API boundaries while allowing defaults on public APIs where consumers benefit from convenience.
Configuration
disallowed_access_levels: Array of access levels to flag. Default:["private", "internal"]private,fileprivate,internal,packageExamples
Triggering (default config):
Non-triggering:
Closes #6488