SwiftRewriter: Collection of reusable & composable SyntaxRewriters
swift-rewriter: Simple command-line executable
How to use
$ swift build
$ swift run swift-rewriter help
Available commands:
help Display general or command-specific help
print-ast print AST from file or string
run Auto-correct code in the file or directory
# Auto-correct code in the directory
$ swift run swift-rewriter run --path /path/to/file-or-directory
Configuration
In swift-rewriter CLI tool, rewriting rules are configured in rewriter.swift (configuration file e.g. yaml or json is not supported yet).
📝 SwiftRewriter
Swift code formatter using SwiftSyntax.
Requirements: Swift 5.1 (Xcode 11.0) + SwiftSyntax 0.50100.0
See also my iOSConf SG 2019 talk for more detail:
Overview
SwiftRewriter: Collection of reusable & composableSyntaxRewritersswift-rewriter: Simple command-line executableHow to use
Configuration
In
swift-rewriterCLI tool, rewriting rules are configured in rewriter.swift (configuration file e.g. yaml or json is not supported yet).Please change the configuration as you like (you can make your own rewriter and combine!), and
swift build & run.RewriterexamplesIndenterBetter right-brace position
P.S. This is the primary goal of making
SwiftRewriter.First-item-aware indent
will be:
HeaderCopyrightTrimmerImportSorterwill be:
ExtensionIniterThis rewriter moves the code to enable
struct‘s memberwise initializer.ExtraNewliner(Work in Progress)This rewriter adds a newline when code is too dense.
will be:
Roadmap / TODO
extensionscope (for “states” readability)=assignmentsAcknowledgement
License
MIT