Skip to content

Commit d5d58e9

Browse files
committed
Disable markTypes in fragments
1 parent e275934 commit d5d58e9

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

Sources/Rules/MarkTypes.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ public extension FormatRule {
1818
) { formatter in
1919
var declarations = formatter.parseDeclarations()
2020

21-
// Do nothing if there is only one top-level declaration in the file (excluding imports)
21+
// Do nothing if there is only one top-level declaration in the file (excluding imports),
22+
// or if this is a fragment.
2223
let declarationsWithoutImports = declarations.filter { $0.keyword != "import" }
23-
guard declarationsWithoutImports.count > 1 else {
24+
guard declarationsWithoutImports.count > 1, !formatter.options.fragment else {
2425
return
2526
}
2627

Tests/Rules/MarkTypesTests.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,14 @@ class MarkTypesTests: XCTestCase {
110110
testFormatting(for: input, output, rule: .markTypes, exclude: [.emptyExtensions])
111111
}
112112

113-
func testCustomTypeMark() {
113+
func testFragment() {
114114
let input = """
115115
struct Foo {}
116116
extension Foo {}
117117
"""
118118

119-
let output = """
120-
// TYPE DEFINITION: Foo
121-
122-
struct Foo {}
123-
extension Foo {}
124-
"""
125-
126119
testFormatting(
127-
for: input, output, rule: .markTypes,
120+
for: input, rule: .markTypes,
128121
options: FormatOptions(typeMarkComment: "TYPE DEFINITION: %t", fragment: true),
129122
exclude: [.emptyExtensions]
130123
)

0 commit comments

Comments
 (0)