mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Fix redundantPublic rule to handle nested types like Foo.Bar via fullyQualifiedName prefix matching
Co-authored-by: calda <1811727+calda@users.noreply.github.com>
This commit is contained in:
@@ -59,7 +59,8 @@ public extension FormatRule {
|
||||
// Inside an extension where the extended type is internal, any `public` modifier has no effect.
|
||||
// We can only handle this case if the extension and type are defined in the same file.
|
||||
if let extendedTypeName = parentType.name,
|
||||
internalTypes.contains(extendedTypeName)
|
||||
internalTypes.contains(extendedTypeName) ||
|
||||
internalTypes.contains(where: { extendedTypeName.hasPrefix($0 + ".") })
|
||||
{
|
||||
declaration.removeVisibility(.public)
|
||||
}
|
||||
|
||||
@@ -195,6 +195,29 @@ final class RedundantPublicTests: XCTestCase {
|
||||
testFormatting(for: input, [output], rules: [.redundantPublic])
|
||||
}
|
||||
|
||||
func testRemovesPublicInExtensionOfPublicNestedTypeInInternalType() {
|
||||
let input = """
|
||||
struct Foo {
|
||||
public struct Bar {}
|
||||
}
|
||||
|
||||
extension Foo.Bar {
|
||||
public func test() {}
|
||||
}
|
||||
"""
|
||||
|
||||
let output = """
|
||||
struct Foo {
|
||||
struct Bar {}
|
||||
}
|
||||
|
||||
extension Foo.Bar {
|
||||
func test() {}
|
||||
}
|
||||
"""
|
||||
testFormatting(for: input, output, rule: .redundantPublic, exclude: [.enumNamespaces])
|
||||
}
|
||||
|
||||
func testRemovesPublicInExtensionOfNestedInternalType() {
|
||||
let input = """
|
||||
enum OuterType {
|
||||
|
||||
Reference in New Issue
Block a user