StrongSelfRewriter
Replace variable name of `guard let self = self` optional binding using SwiftSyntax
Install / Use
/learn @kenmaz/StrongSelfRewriterREADME
StrongSelfRewriter
StrongSelfRewriter is the tool to replace variable name for guard let self = self optional binding code using SwiftSyntax
Usage
StrongSelfRewriter Sample.swift
Result
func execute(completion: () -> Void) {
DispatchQueue.main.async { [weak self] in
- guard let strongSelf = self else {
+ guard let self = self else {
return
}
- strongSelf.output(text: "hello")
- print(strongSelf)
+ self.output(text: "hello")
+ print(self)
}
}
Options
$ StrongSelfRewriter
OVERVIEW: Replace optional self binding variable name to "self" or specified name by --rewrite option
USAGE: StrongSelfRewriter <path>
OPTIONS:
--dryrun, -d Display rewrited code simply
--dump Dump syntax tree
--rewrite Variable name for replacement. Default is self
--help Display available options
POSITIONAL ARGUMENTS:
path Path to .swift file
Build
git clone <repo>
cd <repo>
swift build
Debug run
.build/debug/StrongSelfRewriter rewrite Tests/StrongSelfRewriterTests/Sample.swift
Generate Xcode project
swift package generate-xcodeproj
Release build
swift build -c release
