Discouraged Default Parameter
Default parameter values should not be used in functions with certain access levels.
- Identifier:
discouraged_default_parameter - Enabled by default: No
- Supports autocorrection: No
- Kind: lint
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning disallowed_access_levels [internal, package]
Rationale
By discouraging default parameter values in functions, that are exposed to other source files in the module or package and their consumers, we can promote call sites and reduce the likelihood of bugs caused by unexpected (or changed) default values being used.
Non Triggering Examples
public func foo(bar: Int = 0) {}
open func foo(bar: Int = 0) {}
func foo(bar: Int) {}
private func foo(bar: Int = 0) {}
fileprivate func foo(bar: Int = 0) {}
public init(value: Int = 42) {}
//
// disallowed_access_levels: [private]
//
func foo(bar: Int = 0) {}
Triggering Examples
func foo(bar: Int ↓= 0) {}
internal func foo(bar: Int ↓= 0) {}
package func foo(bar: Int ↓= 0) {}
func foo(bar: Int ↓= 0, baz: String ↓= "") {}
init(value: Int ↓= 42) {}
//
// disallowed_access_levels: [private]
//
private func foo(bar: Int ↓= 0) {}
//
// disallowed_access_levels: [fileprivate]
//
fileprivate func foo(bar: Int ↓= 0) {}
View on GitHub
Install in Dash