Function Default Parameter at End

Prefer to locate parameters with defaults toward the end of the parameter list

  • Identifier: function_default_parameter_at_end
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning
    ignore_first_isolation_inheritance_parameter true

Non Triggering Examples

func foo(baz: String, bar: Int = 0) {}
func foo(x: String, y: Int = 0, z: CGFloat = 0) {}
func foo(bar: String, baz: Int = 0, z: () -> Void) {}
func foo(bar: String, z: () -> Void, baz: Int = 0) {}
func foo(bar: Int = 0) {}
func foo() {}
class A: B {
  override func foo(bar: Int = 0, baz: String) {}
func foo(bar: Int = 0, completion: @escaping CompletionHandler) {}
func foo(a: Int, b: CGFloat = 0) {
  let block = { (error: Error?) in }
}
func foo(a: String, b: String? = nil,
         c: String? = nil, d: @escaping AlertActionHandler = { _ in }) {}
override init?(for date: Date = Date(), coordinate: CLLocationCoordinate2D) {}
func handleNotification(_ userInfo: NSDictionary,
                        userInteraction: Bool = false,
                        completionHandler: ((UIBackgroundFetchResult) -> Void)?) {}
func write(withoutNotifying tokens: [NotificationToken] =  {}, _ block: (() throws -> Int)) {}
func foo(bar: Int, baz: Int = 0, z: () -> Void) {}
func foo(bar: Int, baz: Int = 0, z: () -> Void, x: Int = 0) {}
func foo(isolation: isolated (any Actor)? = #isolation, bar: String) {}

Triggering Examples

func foo(bar: Int = 0, baz: String) {}
private func foo(bar: Int = 0, baz: String) {}
public init?(for date: Date = Date(), coordinate: CLLocationCoordinate2D) {}
func foo(bar: Int, baz: Int = 0, z: () -> Void, x: Int) {}
//
// ignore_first_isolation_inheritance_parameter: false
//

func foo(isolation: isolated (any Actor)? = #isolation, bar: String) {}