about swift-clean

Post on 15-Apr-2017

2.602 Views

Category:

Mobile

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Swift-Clean

http://swiftcleanapp.com/

Swift-Clean

Swift-Cleanとは?

• Swiftのコードフォーマッター

• フォーマットルールを設定することができる

• フォーマットはビルド時に適用される

有料です

Free Trialあり

きっかけ

• 最近、Swiftのソースレビューをしている • Swiftのフォーマットのレビューの方針がない

• 個人的にはどこにスペースを入れるとか、どこで改行するとか割とどうでも良い

• でも、やっぱり統一されていた方が気持ち良い

Swift-Cleanの良いところ

• アンケートに答えていくとSwiftStyleSettings.plistが生成される

• これをもとにSwift-Clean.appが警告を出してくれたりする

あなたのフォーマットルールは?

yidev-swiftフォーマットを作ろう

1/39 (AutoFix)

クラス宣言などの : の前後のスペーシング

What should the spacing around the colon look like in a class declaration?

2/39 (AutoFix)

メソッドのreturn オペレータのスペーシングは

What should the spacing around the return operator look like in a method signature?

3/39

クラス宣言の { を始める位置は?

Where should the open curly brace be in relation to a class declaration?

4/39

メソッド宣言の { を始める位置は?

Where should the open curly brace be in relation to a method declaration?

5/39 (AutoFix)

メソッドの ( はスペースを空けるべきか?

Should there be a space before the opening parentheses in a method signature?

6/39 (AutoFix)

オペレータ宣言の ( の前にはスペースを入れるべきか?

Should there be a space before the opening parentheses in a operator function signature?

7/39 (AutoFix)

メソッド呼び出しの ( の前にはスペースを入れるべきか?

Should there be a space before the opening parentheses in a method call?

8/39 (AutoFix)

メソッドの引数の : の周りにはスペースをどう入れるか?

What should the spacing around the colon look like in a method signature?

9/39 (AutoFix)

変数宣言の : の周りにはスペースをどう入れるか?

What should the spacing around the colon look like in a variable declaration?

10/39

for文の { はどこに置くべきか?

Where should the open curly brace be in relation to a loop declaration?

11/39

if文の { はどこに置くべきか?

Where should the open curly brace be in relation to an if-statement declaration?

12/39

switch文の { はどこに置くべきか?

Where should the open curly brace be in relation to a switch statement declaration?

13/39

return文の上に空の行を入れるべきか?

Should there be an empty line above return statements?

14/39 (AutoFix)

四則演算の周りにスペースを入れるべきか?

What should the spacing around math operators look like?

15/39 (AutoFix)

{ の前にはスペースを入れるべきか?

Should there be a space before opening braces?

16/39 (AutoFix)

, のあとにスペースを入れるべきか?

Should there be a space after commas?

17/39

メソッド間にどれくらい空行を入れるべきか?

How many empty lines should there be between (main, non-nested) method bodies?

18/39 (AutoFix)

メソッドのジェネリクス宣言の周りにスペースを入れるか?

What should the spacing around generic declarations look like in a method signature?

19/39 (AutoFix)

カスタムプロパティのセッターの ( の前にスペースを入れるか?Should there be a space before the opening parentheses of a custom property setter?

20/39 (AutoFix)

型指定の前にスペースを入れるか?

Should there be a space before the type specifier?

21/39 (AutoFix)

論理演算子の周りのスペースはどうする?

What should the spacing around logical operators look like?

22/39 (AutoFix)

代入時のスペースはどうする?

What should the spacing around the assignment operator look like?

23/39

// MARK: コメントの上には空行をどれくらい入れるべきか?

How many empty lines should there be above a // MARK: declaration?

24/39

// MARK: コメントの下には空行をどれくらい入れるべきか?

How many empty lines should there be below a // MARK: declaration?

25/39

モジュールインポートの最後の行の下にどれくらい空行を入れるか?How many empty lines should there be below the last module import?

26/39

モジュールインポートの最初の行の上にどれくらい空行を入れるか?How many empty lines should there be above the first module import?

27/39 (AutoFix)

Dictionaryの : の周りにどうやってスペースを入れるか?

What should the spacing around the colon look like in a dictionary?

28/39 (AutoFix)

メソッド呼び出しの際の : の周りはどうスペーシングするか?

What should the spacing around the colon look like in a function call?

29/39

Swiftファイルの最後の行にはどれくらい空行を入れるべきか

How many empty lines should there be at the end of every Swift file?

30/39

クラス名は1文字目を大文字にすべきか?

Should class names be capitalized?

31/39

メソッド名は1文字目を大文字にすべきか?

Should function names be capitalized?

32/39

変数名は1文字目を大文字にすべきか?

Should variable names be capitalized?

33/39

enum名は1文字目を大文字にすべきか?

Should enum names be capitalized?

34/39

struct名は1文字目を大文字にすべきか?

Should struct names be capitalized?

35/39

typealias時の名前は1文字目を大文字にすべきか?

Should typealias names be capitalized?

36/39

定数名は1文字目を大文字にすべきか?

Should static variable names be capitalized?

37/39

struct宣言時の { はどうすべきか?

Where should the open curly brace be in relation to a struct declaration?

38/39

enum宣言時の { はどうすべきか?

Where should the open curly brace be in relation to an enum declaration?

39/39

コーディングルール違反時はビルドエラーにするか?ワーニングにするか?Do you want Swift-Clean to show code violations as build errors or warnings in Xcode?

設定方法

設定方法

Swift-Cleanアプリを立ち上げる

設定方法

Customでさっきのアンケート画面に

設定方法

StackoverflowアカウントSign-inしたユーザーのアンケート結果

設定方法

アンケートに回答したすべてのユーザーの平均

設定方法

除外ファイルなどの設定

設定方法

プロジェクトファイルを追加

設定方法

AutoFixでさきほどのアンケートでAutoFixと記載されていた項目を自動で修正してくれる

設定方法

Install Run Scriptをクリック

設定方法

Build PhasesにSwift-Clean Run Scriptが追加される不要だったら削除すればOK

設定方法

• 先ほど生成したSwiftStyleSettings.plistを.xcodeprojと同じ階層に保存して、あとはBuildすればOK

こんな感じ

• モジュールインポートの最後の行の下は空行1つにしましょう

• メソッド名はキャメルケースにしましょう などなど

注意

ビルドするごとに…

Free Trial版だとビルドするごとに出てくる

うざかったら

Build PhasesにSwift-Clean Run Scriptが追加される不要だったら削除すればOK

コードフォーマットとか好みでしかないし、どうでもいい、でも整ってる方が気持ち良い

→ チーム開発時はツールで自動化したい

→ Swift-Cleanは一つの手段

まとめ

• アンケート形式で答えられるので、チーム開発で多数決とって決めたい場合にちょうど良いかも

• 150ドルのSingle Site Licenseが用意されている

まとめ

• 第21回 yidevで作成したSwiftStyleSettings.plistはhttps://github.com/mnat44/yidev-21-swift-style-settings-for-swift-clean にアップロードしています

補足

おわり

top related