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 { }
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 {
    {}
}
class Rule:
  NSObject {
  var a: String {
    return ""
  }
}
self.foo(
    (
        "String parameter",
        { "Do something here" }
    )
)
let pattern = #/(\{(?<key>\w+)\})/#
if c {}
else {}

Triggering Examples

func abc(){
}
func abc()
    { }
func abc(a: A,
    b: B)
{
[].map(){ $0 }
struct OldContentView: View {
  @State private var showOptions = false

  var body: some View {
    Button(action: {
      self.showOptions.toggle()
    }){
      Image(systemName: "gear")
    }
  }
}
struct OldContentView: View {
  @State private var showOptions = false

  var body: some View {
    Button(action: {
      self.showOptions.toggle()
    })
   {
      Image(systemName: "gear")
    }
  }
}
struct OldContentView: View {
  @State private var showOptions = false

  var body: some View {
    Button {
      self.showOptions.toggle()
    } label:{
      Image(systemName: "gear")
    }
  }
}
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
    }
}
switch a{}
if
    let a = b,
    let c = d,
    a == c
{ }
while
    let a = b,
    let c = d,
    a == c
{ }
guard
    let a = b,
    let c = d,
    a == c else
{ }
class Rule{}

actor Rule{}

enum Rule{}

protocol Rule{}

extension Rule{}

class Rule {
  var a: String{
    return ""
  }
}
class Rule {
  var a: String {
    willSet{

    }
    didSet  {

    }
  }
}
precedencegroup Group{
  assignment: true
}
if
    "test".isEmpty
{
    // code here
}
func fooFun() {
    let foo: String? = "foo"
    let bar: String? = "bar"

    if
        let foooo = foo,
        let barrr = bar
    {
        print(foooo + barrr)
    }
}
if
    let a = ["A", "B"].first,
    let b = ["B"].first
{
    print(a)
}
if c  {}
else  {}