Swiftlint: Opening Brace false positive when closure is returned without return statement (Swift 5.1)

Created on 22 Oct 2019  路  4Comments  路  Source: realm/SwiftLint

New Issue Checklist

Describe the bug

When returning a closure without a return statement, as it's possible since Swift 5.1, the opening brace rule reports a false positive.

/// hello
public var closure: () -> Void {
    {
        print("hello")
    }
}

is autocorrected to

/// hello
public var closure: () -> Void { {
        print("hello")
    }
}
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint --no-cache test.swift 
Linting Swift files at paths test.swift
Linting 'test.swift' (1/1)
/Users/tom/test.swift:3:5: warning: Opening Brace Spacing Violation: Opening braces should be preceded by a single space and on the same line as the declaration. (opening_brace)
Done linting! Found 1 violation, 0 serious in 1 file.

Environment

  • SwiftLint version (run swiftlint version to be sure)?

0.35.0

  • Installation method used (Homebrew, CocoaPods, building from source, etc)?

Homebrew

  • Which Xcode version are you using (check xcode-select -p)?

11.1

  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.

see above

wontfix

All 4 comments

Also linking adding support for implicit returns here: https://github.com/realm/SwiftLint/issues/2870

The corrected code looks fine.

could this at least be made configurable?

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

Was this page helpful?
0 / 5 - 0 ratings