File tree 2 files changed +39
-3
lines changed
Sources/SwiftFormat/Rules
Tests/SwiftFormatTests/Rules
2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,11 @@ public final class OrderedImports: SyntaxFormatRule {
86
86
if atStartOfFile {
87
87
switch line. type {
88
88
case . comment:
89
- commentBuffer. append ( line)
89
+ if line. description. contains ( " swift-format-ignore-file " ) {
90
+ fileHeader. append ( line)
91
+ } else {
92
+ commentBuffer. append ( line)
93
+ }
90
94
continue
91
95
92
96
case . blankLine:
@@ -520,8 +524,8 @@ fileprivate class Line {
520
524
}
521
525
}
522
526
523
- extension Line : CustomDebugStringConvertible {
524
- var debugDescription : String {
527
+ extension Line : CustomStringConvertible {
528
+ var description : String {
525
529
var description = " "
526
530
if !leadingTrivia. isEmpty {
527
531
var newlinesCount = 0
Original file line number Diff line number Diff line change @@ -651,4 +651,36 @@ final class OrderedImportsTests: LintOrFormatRuleTestCase {
651
651
]
652
652
)
653
653
}
654
+
655
+ func testImportsOrderWithFileIgnoreDirective( ) {
656
+ assertFormatting (
657
+ OrderedImports . self,
658
+ input: """
659
+ // swift-format-ignore-file: DoNotUseSemicolons, FullyIndirectEnum
660
+ // Line comment for Zoo
661
+ import Zoo
662
+ // Line comment for Array
663
+ 1️⃣import Arrays
664
+
665
+ struct Foo {
666
+ func foo() { bar();baz(); }
667
+ }
668
+ """ ,
669
+ expected: """
670
+ // swift-format-ignore-file: DoNotUseSemicolons, FullyIndirectEnum
671
+
672
+ // Line comment for Array
673
+ import Arrays
674
+ // Line comment for Zoo
675
+ import Zoo
676
+
677
+ struct Foo {
678
+ func foo() { bar();baz(); }
679
+ }
680
+ """ ,
681
+ findings: [
682
+ FindingSpec ( " 1️⃣ " , message: " sort import statements lexicographically " )
683
+ ]
684
+ )
685
+ }
654
686
}
You can’t perform that action at this time.
0 commit comments