nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.87k stars 638 forks source link

Improper removal of parenthesis #1748

Open nysander opened 3 months ago

nysander commented 3 months ago

Original code

            let fetchCompletion: (UIBackgroundFetchResult) -> Void = { fetchResult = $0 }

Fixed

            let fetchCompletion: UIBackgroundFetchResult -> Void = { fetchResult = $0 }

Xcode error: Single argument function types require parentheses

nicklockwood commented 3 months ago

Hi, thanks for reporting. I can't reproduce this issue with just that line in isolation, so it's probably dependent on the surrounding context from the file and/or your particular configuration settings.

Can you provide a standalone sample I can use to reproduce the issue? Either the whole source file, or a portion of it. It doesn't matter if it doesn't compile on its own.

nysander commented 3 months ago
protocol RemoteNotificationHandler {
    typealias FetchCompletionBlock = (UIBackgroundFetchResult) -> Void
    typealias RemoteNotification = [AnyHashable: Any]

    func handle(remoteNotification: RemoteNotification, completion: @escaping FetchCompletionBlock)
    func register(_ delegate: RemoteNotificationHandlerDelegate)
    func unregister(_ delegate: RemoteNotificationHandlerDelegate)
}

similar example just when removed parenthesis from typealias FetchCompletionBlock = (UIBackgroundFetchResult) -> Void line Xcode shows this error without compiling the code

nysander commented 3 months ago

generally its completion with parameter

nysander commented 3 months ago

my config

--exclude Package.swift

--disable wrapMultilineStatementBraces
--disable unusedArguments
--disable trailingCommas
--disable strongOutlets
--disable preferForLoop

--enable blankLineAfterImports
--enable isEmpty,
--enable wrapEnumCases,
--enable wrapSwitchCases
--enable redundantProperty
--enable blankLineAfterSwitchCase
--enable organizeDeclarations

--patternlet inline
--indentcase true
--indent 4
--emptybraces spaced
--ranges no-space
--self init-only
nicklockwood commented 2 months ago

@nysander I'm still not able to reproduce - can you verify which version of swiftformat you are running?

nysander commented 2 months ago

latest 0.54.0

nicklockwood commented 2 months ago

@nysander I'm still unable to repro this - sorry.

Perhaps you could try opening a PR with a unit test or snapshot that demonstrates the problem?

nysander commented 2 months ago

I will try to create some test project to extract this issue