diff --git a/Sources/Formatter.swift b/Sources/Formatter.swift index 405e1f5d..54378b82 100644 --- a/Sources/Formatter.swift +++ b/Sources/Formatter.swift @@ -72,20 +72,21 @@ public class Formatter: NSObject { // Process a comment token (which may contain directives) func processCommentBody(_ comment: String, at index: Int) { var prefix = "swiftformat:" - guard comment.hasPrefix(prefix) else { + guard let range = comment.range(of: prefix) else { return } + let comment = String(comment[range.upperBound...]) guard let directive = ["disable", "enable", "options"].first(where: { - comment.hasPrefix("\(prefix)\($0)") + comment.hasPrefix($0) }) else { let parts = comment.components(separatedBy: ":") - var directive = parts[1] + var directive = parts[0] if let range = directive.rangeOfCharacter(from: .whitespacesAndNewlines) { directive = String(directive[..