Attribute Name Spacing

This rule prevents trailing spaces after attribute names, ensuring compatibility with Swift 6 where a space between an attribute name and the opening parenthesis results in a compilation error (e.g. @MyPropertyWrapper (), private (set)).

  • Identifier: attribute_name_spacing
  • Enabled by default: Yes
  • Supports autocorrection: Yes
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity error

Non Triggering Examples

private(set) var foo: Bool = false
fileprivate(set) var foo: Bool = false
@MainActor class Foo {}
func funcWithEscapingClosure(_ x: @escaping () -> Int) {}
@available(*, deprecated)
@MyPropertyWrapper(param: 2) 
nonisolated(unsafe) var _value: X?
@testable import SwiftLintCore
func func_type_attribute_with_space(x: @convention(c) () -> Int) {}
@propertyWrapper
struct MyPropertyWrapper {
    var wrappedValue: Int = 1

    init(param: Int) {}
}
let closure2 = { @MainActor
  (a: Int, b: Int) in
}

Triggering Examples

private (set) var foo: Bool = false
fileprivate (set) var foo: Bool = false
public (set) var foo: Bool = false
  public  (set) var foo: Bool = false
@ MainActor class Foo {}
func funcWithEscapingClosure(_ x: @ escaping () -> Int) {}
func funcWithEscapingClosure(_ x: @escaping() -> Int) {}
@available (*, deprecated)
@MyPropertyWrapper (param: 2) 
nonisolated (unsafe) var _value: X?
@MyProperty () class Foo {}
let closure1 = { @MainActor (a, b) in
}