Fix `lower_acl_than_parent` rule rewriter by preserving leading whitespace (#4861)

This commit is contained in:
Danny Mösch 2023-04-03 22:26:46 +02:00 committed by GitHub
parent ee849bcb10
commit bd444fcd77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -25,7 +25,9 @@
#### Bug Fixes
* None.
* Fix `lower_acl_than_parent` rule rewriter by preserving leading whitespace.
[SimplyDanny](https://github.com/SimplyDanny)
[#4860](https://github.com/realm/SwiftLint/issues/4860)
## 0.51.0: bzllint

View File

@ -68,7 +68,17 @@ struct LowerACLThanParentRule: OptInRule, ConfigurationProviderRule, SwiftSyntax
Example("class Foo { ↓public func bar() {} }"):
Example("class Foo { func bar() {} }"),
Example("actor Foo { ↓public func bar() {} }"):
Example("actor Foo { func bar() {} }")
Example("actor Foo { func bar() {} }"),
Example("""
struct Foo {
public func bar() {}
}
"""):
Example("""
struct Foo {
func bar() {}
}
""")
]
)
@ -120,7 +130,10 @@ private extension LowerACLThanParentRule {
trailingTrivia: .space
)
} else {
newNode = DeclModifierSyntax(name: .keyword(.internal, presence: .missing))
newNode = DeclModifierSyntax(
leadingTrivia: node.leadingTrivia ?? .zero,
name: .identifier("")
)
}
return super.visit(newNode)