Opening Brace Spacing

Opening braces should be preceded by a single space and on the same line as the declaration

  • Identifier: opening_brace
  • Enabled by default: Yes
  • Supports autocorrection: Yes
  • Kind: style
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning
    allow_multiline_func false

Non Triggering Examples

func abc() {
}
[].map() { $0 }
[].map({ })
if let a = b { }
while a == b { }
guard let a = b else { }
if
    let a = b,
    let c = d
    where a == c
{ }
while
    let a = b,
    let c = d
    where a == c
{ }
guard
    let a = b,
    let c = d
    where a == c else
{ }
struct Rule {}
struct Parent {
    struct Child {
        let foo: Int
    }
}
func f(rect: CGRect) {
    {
        let centre = CGPoint(x: rect.midX, y: rect.midY)
        print(centre)
    }()
}
func f(rect: CGRect) -> () -> Void {
    {
        let centre = CGPoint(x: rect.midX, y: rect.midY)
        print(centre)
    }
}
func f() -> () -> Void {
    {}
}

Triggering Examples

func abc(){
}
func abc()
    { }
func abc(a: A
    b: B)
{
[].map(){ $0 }
[].map( { } )
if let a = b{ }
while a == b{ }
guard let a = b else{ }
if
    let a = b,
    let c = d
    where a == c{ }
while
    let a = b,
    let c = d
    where a == c{ }
guard
    let a = b,
    let c = d
    where a == c else{ }
struct Rule{}
struct Rule
{
}
struct Rule

    {
}
struct Parent {
    struct Child
    {
        let foo: Int
    }
}
// Get the current thread's TLS pointer. On first call for a given thread,
// creates and initializes a new one.
internal static func getPointer()
  -> UnsafeMutablePointer<_ThreadLocalStorage>
{ // <- here
  return _swift_stdlib_threadLocalStorageGet().assumingMemoryBound(
    to: _ThreadLocalStorage.self)
}
func run_Array_method1x(_ N: Int) {
  let existentialArray = array!
  for _ in 0 ..< N * 100 {
    for elt in existentialArray {
      if !elt.doIt()  {
        fatalError("expected true")
      }
    }
  }
}

func run_Array_method2x(_ N: Int) {

}
   class TestFile {
       func problemFunction() {
           #if DEBUG
           #endif
       }

       func openingBraceViolation()
      {
           print("Brackets")
       }
   }