Swiftpack.co - kenmaz/StrongSelfRewriter as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by kenmaz.
kenmaz/StrongSelfRewriter v0.0.1
Replace variable name of `guard let self = self` optional binding using SwiftSyntax
⭐️ 13
🕓 5 years ago
.package(url: "https://github.com/kenmaz/StrongSelfRewriter.git", from: "v0.0.1")

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

Thanks

GitHub

link
Stars: 13
Last commit: 5 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

First release
5 years ago

First release

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics