Swiftformat: backquote will be removed (using `init`)

Created on 31 Jul 2020  路  3Comments  路  Source: nicklockwood/SwiftFormat

Problems

enum Flag: String, Codable {
   case `init`
}

let flags: [Flag] = [.`init`]

Execute swiftformat to this code will remove the back quotes.
Backquote must not be deleted because init is reserved.

Environments

$ swiftformat --version
0.45.0
$ cat .swiftformat 
# format options

 # file options
--exclude */modules, Pods, Carthage, fastlane, GeneratedMocks.swift

 # rules
--disable trailingClosures, wrapMultilineStatementBraces
--stripunusedargs closure-only

 # version
--swiftversion 5
bug fixed in develop

All 3 comments

@soranoba thanks for reporting this, I'll fix it in the next release. In the meantime, you can work around it by adding the following comment in the line above:

// swiftformat:disable:next redundantBackticks
let flags: [Flag] = [.`init`]

Or just disable the redundantBackticks rule globally in your SwiftFormat configuration.

Thank you for the quick response.

@soranoba fixed in 0.45.2.

Was this page helpful?
0 / 5 - 0 ratings