     }
 
     private func createTemporaryPath() -> String {
-        return tempDirURL.URLByAppendingPathComponent(NSUUID().UUIDString).path! + ".swift"
-    }
-
-    private func ensureTemporaryDirectory() throws {
-        if fileManager.fileExistsAtPath(tempDirURL.path!) { return }
-        try fileManager.createDirectoryAtURL(tempDirURL, withIntermediateDirectories: true, attributes: nil)
+        return NSURL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
+            .URLByAppendingPathComponent("SwiftLintXcode_\(NSUUID().UUIDString).swift").path!
     }
 }

    }

    private func withTempporaryFile<T>(@noescape callback: (filePath: String) throws -> T) throws -> T {
        try ensureTemporaryDirectory()
        let filePath = createTemporaryPath()
        if fileManager.fileExistsAtPath(filePath) {
            throw NSError(domain: "net.ypresto.SwiftLintXcode", code: 0, userInfo: [

    static var sharedInstance = Formatter()
    private static let pathExtension = "SwiftLintXcode"

    private let fileManager = NSFileManager.defaultManager()

    private struct CursorPosition {
        let line: Int
        let column: Int
    }

    class func isFormattableDocument(document: NSDocument) -> Bool {
        return (document.fileURL?.pathExtension?.lowercaseString == "swift") ?? false
