SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Ability to configure 'opening_brace'

Open bourquep opened this issue 9 years ago • 3 comments

I like having my opening braces on their own line:

if codingStyle.isOldSchool
{
    print("I relate to that!")
}
else
{
    print("I respect that!")
}

I'd love to be able to configure the opening_brace rule to enforce this style. I can look into submitting a patch, but wanted to know if this is something already on your radar...

bourquep avatar Feb 12 '16 21:02 bourquep

I don't think we're tracking this anywhere, but making OpeningBraceRule be configurable by mode (maybe newline: true or mode: same_line/mode: new_line) is fine by me! :+1:

jpsim avatar Feb 12 '16 21:02 jpsim

+1 for configurable openingBraceRule. I want to write also closures for arrays or no-argument-label functions like this:

let a1 = [
    "a",
    { "b" }()]

let a2 = [
    "a",
    {
        let b = "b"
        return b
    }()]

func f(_ x: String, _ y: () -> String) -> [String] {
    return [x, y()]
}

let a3 = f(
    "a",
    { return "b" })

let a4 = f(
    "a",
    {
        let b = "b"
        return b
    })

Currently, swiftlint autocorrect with this rule changes the above to this (the declaration of f(_: _:) is fine for me):

let a1 = [
    "a", { "b" }()]

let a2 = [
    "a", {
        let b = "b"
        return b
    }()]

func f(_ x: String, _ y: () -> String) -> [String] {
    return [x, y()]
}

let a3 = f(
    "a", { return "b" })

let a4 = f(
    "a", {
        let b = "b"
        return b
    })

mshibanami avatar Mar 11 '17 06:03 mshibanami

Any news about the rule being configurable?

kubatruhlar avatar Apr 04 '19 12:04 kubatruhlar