Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@

### Bug Fixes

* Skip `control_statement` corrections for parenthesized conditions that contain
comments, avoiding comment loss during `swiftlint --fix`.
[theamodhshetty](https://github.com/theamodhshetty)
[#6207](https://github.com/realm/SwiftLint/issues/6207)

* Add an `ignore_attributes` option to `implicit_optional_initialization` so
wrappers/attributes that require explicit `= nil` can be excluded from
style checks for both `style: always` and `style: never`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ struct ControlStatementRule: Rule {
Example("renderGif(data)"),
Example("guard condition else {}"),
Example("while condition {}"),
Example("""
if (abc == 1/* && cdf == 2*/) {
print("Hello, world!")
}
"""),
Example("do {} while condition {}"),
Example("do { ; } while condition {}"),
Example("switch foo {}"),
Expand Down Expand Up @@ -169,8 +174,16 @@ private extension ControlStatementRule {

private extension ExprSyntax {
var unwrapped: ExprSyntax? {
if let expr = `as`(TupleExprSyntax.self)?.elements.onlyElement?.expression {
return containsTrailingClosure(Syntax(expr)) ? nil : expr
if let tuple = `as`(TupleExprSyntax.self),
let expr = tuple.elements.onlyElement?.expression {
if containsTrailingClosure(Syntax(expr)) ||
expr.leadingTrivia.containsComments ||
expr.trailingTrivia.containsComments ||
tuple.leftParen.trailingTrivia.containsComments ||
tuple.rightParen.leadingTrivia.containsComments {
return nil
}
return expr
}
return nil
}
Expand Down