realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.46k stars 2.2k forks source link

opening_brace triggers when the brace is preceded by a comment #5578

Closed DanielRouxSA closed 1 month ago

DanielRouxSA commented 1 month ago

New Issue Checklist

Describe the bug

When an opening brace is preceded by a comment (for example a clarifying comment in an if statement, a commented out inheritance, etc.), the opening_brace rule reports a warning, even when the line is technically compliant (one space between the end of the comment and the brace).

Environment

Samples

The following three examples produce the Opening Brace Spacing Violation: Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace) warning:

// Here I added a clarifying comment since it might not be obvious that the unit here is seconds.
if timeSpent < 60.0 /* Seconds */ {
    // Do something here...
}
do {
    // Try something that may throw
} catch /*where error is CancellationError == false*/ { // The error handling logic here has changed and thus the catch condition is no longer needed, but kept here for a while for reference.
    // Error handling...
}
class SomeClass: SomeBaseClass/*, SomeProtocol*/ { // Inheritance of SomeProtocol is no longer needed.

}

I did notice that this may already be a known issue stemming from this rule's rewrite using SwiftSyntax (https://github.com/realm/SwiftLint/pull/5164#pullrequestreview-1620492516).