Skip to content

Commit

Permalink
Fix issue where markTypes would mistake an import declaration as a type
Browse files Browse the repository at this point in the history
  • Loading branch information
calda committed Nov 13, 2020
1 parent 70f5cf5 commit 7e167a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5126,7 +5126,7 @@ public struct _FormatRules {
// extension String { } // This extension is standalone (not grouped with any type)
//
let isGroupedWithExtendingType = declarations[..<index].contains(where: {
$0.name == typeName && $0.keyword != "extension"
$0.name == typeName && ["class", "enum", "protocol", "struct", "typealias"].contains($0.keyword)
})

if isGroupedWithExtendingType {
Expand Down
16 changes: 16 additions & 0 deletions Tests/RulesTests+Organization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2175,4 +2175,20 @@ extension RulesTests {

testFormatting(for: input, output, rule: FormatRules.markTypes)
}

func testExtensionMarkWithImportOfSameName() {
let input = """
import MagazineLayout
// MARK: - MagazineLayout + FooProtocol
extension MagazineLayout: FooProtocol {}
// MARK: - MagazineLayout + BarProtocol
extension MagazineLayout: BarProtocol {}
"""

testFormatting(for: input, rule: FormatRules.markTypes)
}
}
1 change: 1 addition & 0 deletions Tests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ extension RulesTests {
("testExponentialGrouping", testExponentialGrouping),
("testExpressionCountEqualsZero", testExpressionCountEqualsZero),
("testExpressionCountNotEqualToZero", testExpressionCountNotEqualToZero),
("testExtensionMarkWithImportOfSameName", testExtensionMarkWithImportOfSameName),
("testFileHeaderCreationDateReplacement", testFileHeaderCreationDateReplacement),
("testFileHeaderCreationYearReplacement", testFileHeaderCreationYearReplacement),
("testFileHeaderFileReplacement", testFileHeaderFileReplacement),
Expand Down

0 comments on commit 7e167a4

Please sign in to comment.