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:
copilot-swe-agent[bot]
2026-03-17 03:56:32 +00:00
parent 1cb8771932
commit 5ce59c4e82
2 changed files with 25 additions and 1 deletions
+2 -1
View File
@@ -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)
}
+23
View File
@@ -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 {