🕊️
VS Code swiftformat で保存時に自動整形
各種インストール
VS Code へ 拡張機能 apple-swift-format をインストール
swift-format を Homebrew でインストール
brew install swift-format
VS Code apple-swift-format の設定
VS Code 拡張 apple-swift-format 設定を開き swiftformat の path を指定しておきます。
僕は M1 なので
/opt/homebrew/Cellar/swiftformat/0.49.3/bin/swiftformat
です。
設定後 VS Code を再起動すれば Swift ファイルでも整形できるようになっており、Format On Save が有効なら保存時に整形してくれるようになっていると思います。
よろしければTwitterのフォローお願いします。
Discussion
自分の場合はこの拡張機能ではうまくいかなかったのですが、Swiftの拡張を入れた上で WorkSpace の default Formatter に Swift を設定すれば、Format on Save で無事動作してくれました!