SweetPad を使った際にフォーマッタの設定を「スペース4つ」にする方法

結論

1. Homebrew で swift-format を入れる

$ brew install swift-format

2. .swift-format のひな型をプロジェクトルートに作る

$ cd /path/to/project_root 
$ swift-format dump-configuration > .swift-format

3. .swift-format のインデントの数値を 2 から 4 に変更する

  • 他の部分の設定は不要だったら削除してもいい
変更前
  "indentation": {
    "spaces": 2
  },
変更後
  "indentation": {
    "spaces": 4
  },

4. Visual Studio Code の設定に以下を書き加える

(以上省略)
  "[swift]": {
    "editor.defaultFormatter": "sweetpad.sweetpad",
    "editor.formatOnSave": true,
  },
  "sweetpad.format.path": "/opt/homebrew/bin/swift-format",
  "sweetpad.format.args": ["--in-place", "${file}"]
(以下省略)

注意点

  • "editor.tabSize": 4 は効かない

参考

sweetpad.hyzyla.dev

Powered by はてなブログ