seanhenry / SwiftMockGeneratorForXcode

An Xcode extension (plugin) to generate Swift test doubles automatically.
MIT License
748 stars 47 forks source link

Indentation follows Xcode ctrl-i #52

Open justinvallely opened 3 years ago

justinvallely commented 3 years ago

Hello!

When generating mocks for functions with input parameters on different lines, would it be possible to have them auto-indent based on Xcode's default ctrl-i shortcut? The end result would be input parameters aligned at their first character. Examples below.

Current:

    var invokedFetchRetailer = false
    var invokedFetchRetailerCount = 0
    var invokedFetchRetailerParameters: (identifier: Int, Void)?
    var invokedFetchRetailerParametersList = [(identifier: Int, Void)]()
    var stubbedFetchRetailerCompletionResult: (Result<Retailer, Error>, Void)?

    func fetchRetailer(for identifier: Int,
        completion: @escaping ((Result<Retailer, Error>) -> Void)) {
        invokedFetchRetailer = true
        invokedFetchRetailerCount += 1
        invokedFetchRetailerParameters = (identifier, ())
        invokedFetchRetailerParametersList.append((identifier, ()))
        if let result = stubbedFetchRetailerCompletionResult {
            completion(result.0)
        }
    }

Desired:

    var invokedFetchRetailer = false
    var invokedFetchRetailerCount = 0
    var invokedFetchRetailerParameters: (identifier: Int, Void)?
    var invokedFetchRetailerParametersList = [(identifier: Int, Void)]()
    var stubbedFetchRetailerCompletionResult: (Result<Retailer, Error>, Void)?

    func fetchRetailer(for identifier: Int,
                       completion: @escaping ((Result<Retailer, Error>) -> Void)) { // <------- NOTE "completion" aligns with "for".
        invokedFetchRetailer = true
        invokedFetchRetailerCount += 1
        invokedFetchRetailerParameters = (identifier, ())
        invokedFetchRetailerParametersList.append((identifier, ()))
        if let result = stubbedFetchRetailerCompletionResult {
            completion(result.0)
        }
    }