mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Fix conditional import parsing with access modifiers (#2494)
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
committed by
Cal Stephens
parent
78836b9959
commit
4ace97e09d
@@ -2496,8 +2496,10 @@ extension Formatter {
|
||||
}
|
||||
let nextToken = tokens[nextTokenIndex]
|
||||
let isImportKeyword = nextToken == .keyword("import")
|
||||
// Access modifier (e.g. "public") can precede "import" on the same line (Swift 6)
|
||||
let isAccessModifierBeforeImport = nextToken.isKeyword && _FormatRules.aclModifiers.contains(nextToken.string)
|
||||
// Access modifiers only continue the import block when they are immediately followed by import.
|
||||
let isAccessModifierBeforeImport = nextToken.isKeyword &&
|
||||
_FormatRules.aclModifiers.contains(nextToken.string) &&
|
||||
next(.nonSpaceOrComment, after: nextTokenIndex) == .keyword("import")
|
||||
if !isImportKeyword, !isAccessModifierBeforeImport {
|
||||
// End of imports
|
||||
pushStack()
|
||||
|
||||
Reference in New Issue
Block a user