Skip to content

Commit 6dfad2c

Browse files
authored
Fix false positive with #Preview macro in closure_end_indentation (#6306)
1 parent 4019a6e commit 6dfad2c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
### Bug Fixes
2121

22-
* None.
22+
* Fix false positive with `#Preview` macro in `closure_end_indentation` rule.
23+
[gibachan](https://github.com/gibachan)
2324

2425
## 0.62.1: Generous Drum Volume
2526

Source/SwiftLintBuiltInRules/Rules/Style/ClosureEndIndentationRule.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ private extension ClosureEndIndentationRule {
103103
return anchor(for: ExprSyntax(functionCall))
104104
}
105105

106+
// Case: Macro expansion expression. e.g., `#Preview { ... }`
107+
if let macroExpansionExpr = parent.as(MacroExpansionExprSyntax.self) {
108+
return anchor(for: ExprSyntax(macroExpansionExpr))
109+
}
110+
106111
// Case: Closure as a labeled argument. e.g., `function(label: { ... })`
107112
if let labeledExpr = parent.as(LabeledExprSyntax.self) {
108113
// Check if this is part of a function call where the first argument is on a new line

Source/SwiftLintBuiltInRules/Rules/Style/ClosureEndIndentationRuleExamples.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ internal struct ClosureEndIndentationRuleExamples {
6161
.prop().method {
6262
}
6363
""", excludeFromDocumentation: true),
64+
Example("""
65+
#Preview("foo",
66+
traits: .landscapeLeft) {
67+
ZStack {}
68+
}
69+
"""),
6470
]
6571

6672
static let triggeringExamples = [

0 commit comments

Comments
 (0)