Make your own code formatter in Swift
summary
Team inconsistency motivates building a real formatter that actually rewrites code, not just enforces rules. It uses SwiftSyntax to parse a lossless AST and implements concrete edits like semicolon trimming, inserting numeric underscores, and turning nested if into guard. The proof is an open source formatter called swiftlylighter that applies these edits and runs on real code; it combines AST editing with lenses and prisms (optics) for deep traversal and notes some performance limits now but improvements land with newer Swift.
AI-written summary · about
chapters (6)
- 0:00Introduction
- 1:21Coding Styles
- 6:16Swift ASP Explore
- 11:10Swift Formal Grammar
- 20:28Optics
- 26:46Composite optics
related talks
22mImproving Swift Tools with libSyntax
33mMaking Your Own Tools Using SwiftSyntax
28mSwiftly Swift manipulation... with Swift
27mAST Meta-programming
01h 03mFormatting F# Code, There and Back Again
11mIntroducing Standard Clojure Style: no fuss code formatting
06mFundamentals for Building Convenience with SwiftSyntax
41mFormat Your Elixir Code Now
