Skip to content

Commit

Permalink
Fix lower_acl_than_parent rule rewriter by preserving leading white…
Browse files Browse the repository at this point in the history
…space (#4861)
  • Loading branch information
SimplyDanny committed Apr 3, 2023
1 parent ee849bc commit bd444fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 15 additions & 2 deletions Source/SwiftLintFramework/Rules/Lint/LowerACLThanParentRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
""")
]
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bd444fc

Please sign in to comment.