Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Editor/Models/Editor.swift (Swift)

Code before:

    /// Opens a custom NSAlert for saving a draft file
    ///
    /// (A draft file is a file that has been created
    /// but is not saved anywhere outside the CodeEdit 'Application Support' folder)
    /// - Returns: A boolean that tells whether the tab can be closed
    private func openDraftSavePanel(for file: CEWorkspaceFile) -> Bool {
        guard let currentWindow = NSApp.keyWindow else { return false }

        let alert = NSAlert()
        alert.messageText = "Do you want to save the contens of the scratch file \"\(file.name)\"?"
        alert.informativeText = "Your changes will be lost if you don’t save them."
        alert.addButton(withTitle: "Save")
        alert.addButton(withTitle: "Don't save").hasDestructiveAction = true
        alert.addButton(withTitle: "Cancel")
        let response = alert.runModal()
        if response == NSApplication.ModalResponse.alertFirstButtonReturn {
            NSApp.sendAction(#selector(CodeEditWindowController.saveDocument(_:)), to: nil, from: nil)
            return true
        }
        if response == NSApplication.ModalResponse.alertSecondButtonReturn {
            let fileManager = FileManager.default

            if fileManager.fileExists(atPath: file.url.path) {
                do {
                    try fileManager.removeItem(at: file.url)
                } catch {
                    fatalError(error.localizedDescription)
                }
            }
            return true
        }
        return false
    }

    /// Receives result of `canClose` and then, set `shouldClose` to `contextInfo`'s `pointee`.
    ///
    /// - Parameters:
    ///   - document: The document may be closed.
    ///   - shouldClose: The result of user selection.
    ///      `shouldClose` becomes false if the user selects cancel, otherwise true.
    ///   - contextInfo: The additional info which will be set `shouldClose`.
    ///       `contextInfo` must be `UnsafeMutablePointer<Bool>`.
    @objc
    private func document(
        _ document: NSDocument,
        shouldClose: Bool,
        contextInfo: UnsafeMutableRawPointer
    ) {
        let opaquePtr = OpaquePointer(contextInfo)
        let mutablePointer = UnsafeMutablePointer<Bool>(opaquePtr)

Review comment (suggestion):
```suggestion
    /// - Parameters:
    ///     - file: The draft file to be saved.
    /// - Returns: A boolean that tells whether the tab can be closed
```

Code after:

            return shouldClose.pointee
        }

        if file.isScratch {
            let fileManager = FileManager.default

            if fileManager.fileExists(atPath: file.url.path) {
                do {
                    try fileManager.removeItem(at: file.url)
                } catch {
                    fatalError(error.localizedDescription)
                }
            }
        }

        return true
    }

    /// Opens a custom NSAlert for saving a draft file
    ///
    /// (A draft file is a file that has been created
    /// but is not saved anywhere outside the CodeEdit 'Application Support' folder)
    ///  - Parameters:
    ///     - file: The draft file to be sa
    /// - Returns: A boolean that tells whether the tab can be closed
    private func openDraftSavePanel(for file: CEWorkspaceFile) -> Bool {
        guard let currentWindow = NSApp.keyWindow else { return false }

        let alert = NSAlert()
        alert.messageText = "Do you want to save the contens of the scratch file \"\(file.name)\"?"
        alert.informativeText = "Your changes will be lost if you don’t save them."
        alert.addButton(withTitle: "Save")
        alert.addButton(withTitle: "Don't save").hasDestructiveAction = true
        alert.addButton(withTitle: "Cancel")
        let response = alert.runModal()
        if response == NSApplication.ModalResponse.alertFirstButtonReturn {
            NSApp.sendAction(#selector(CodeEditWindowController.saveDocument(_:)), to: nil, from: nil)
            return true
        }
        if response == NSApplication.ModalResponse.alertSecondButtonReturn {
            let fileManager = FileManager.default

            if fileManager.fileExists(atPath: file.url.path) {
                do {
                    try fileManager.removeItem(at: file.url)
                } catch {
                    fatalError(error.localizedDescription)
                }
            }
            return true