Skip to content

Commit

Permalink
Avoid removing internal or changing private to fileprivate
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Sep 25, 2020
1 parent b229a52 commit af1d162
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Sources/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5044,8 +5044,10 @@ public struct _FormatRules {
else { return declaration }

let extensionWithUpdatedVisibility: Formatter.Declaration
if memberVisibility == .internal {
extensionWithUpdatedVisibility = formatter.remove(.internal, from: declaration)
if memberVisibility == extensionVisibility ||
(memberVisibility == .internal && visibilityKeyword == nil)
{
extensionWithUpdatedVisibility = declaration
} else {
extensionWithUpdatedVisibility = formatter.add(memberVisibility, to: declaration)
}
Expand Down
18 changes: 18 additions & 0 deletions Tests/RulesTests+Organization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1441,4 +1441,22 @@ extension RulesTests {
"""
testFormatting(for: input, rule: FormatRules.extensionAccessControl)
}

func testDontChangePrivateExtensionToFileprivate() {
let input = """
private extension Foo {
func bar() {}
}
"""
testFormatting(for: input, rule: FormatRules.extensionAccessControl)
}

func testDontRemoveInternalKeywordFromExtension() {
let input = """
internal extension Foo {
func bar() {}
}
"""
testFormatting(for: input, rule: FormatRules.extensionAccessControl)
}
}
2 changes: 2 additions & 0 deletions Tests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ extension RulesTests {
("testDoesntUpdateExtensionVisibilityWithInternalDeclarations", testDoesntUpdateExtensionVisibilityWithInternalDeclarations),
("testDoesntUpdateExtensionVisibilityWithMultipleBodyVisibilities", testDoesntUpdateExtensionVisibilityWithMultipleBodyVisibilities),
("testDoesntUpdatesExtensionThatHasLowerACLThanBodyDeclarations", testDoesntUpdatesExtensionThatHasLowerACLThanBodyDeclarations),
("testDontChangePrivateExtensionToFileprivate", testDontChangePrivateExtensionToFileprivate),
("testDontCorruptPartialFragment", testDontCorruptPartialFragment),
("testDontCorruptPartialFragment2", testDontCorruptPartialFragment2),
("testDontIndentCaseAfterReturn", testDontIndentCaseAfterReturn),
Expand All @@ -682,6 +683,7 @@ extension RulesTests {
("testDontRemoveInitWhenUsedOnImplicitClosureMetatype", testDontRemoveInitWhenUsedOnImplicitClosureMetatype),
("testDontRemoveInitWhenUsedOnMetatype", testDontRemoveInitWhenUsedOnMetatype),
("testDontRemoveInitWithExplicitSignature", testDontRemoveInitWithExplicitSignature),
("testDontRemoveInternalKeywordFromExtension", testDontRemoveInternalKeywordFromExtension),
("testDontRemoveSpaceBetweenOpeningBraceAndParens", testDontRemoveSpaceBetweenOpeningBraceAndParens),
("testDoubleIndentTrailingClosureBody", testDoubleIndentTrailingClosureBody),
("testDoubleIndentWhenScopesSeparatedByWrap", testDoubleIndentWhenScopesSeparatedByWrap),
Expand Down

0 comments on commit af1d162

Please sign in to comment.