about swift-clean

67

Upload: motoki-narita

Post on 15-Apr-2017

2.602 views

Category:

Mobile


1 download

TRANSCRIPT

Page 1: About Swift-Clean
Page 2: About Swift-Clean

Swift-Clean

Page 3: About Swift-Clean

http://swiftcleanapp.com/

Swift-Clean

Page 4: About Swift-Clean

Swift-Cleanとは?

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

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

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

Page 5: About Swift-Clean

有料です

Free Trialあり

Page 6: About Swift-Clean

きっかけ

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

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

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

Page 7: About Swift-Clean

Swift-Cleanの良いところ

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

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

Page 8: About Swift-Clean

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

Page 9: About Swift-Clean

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

Page 10: About Swift-Clean

1/39 (AutoFix)

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

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

Page 11: About Swift-Clean

2/39 (AutoFix)

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

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

Page 12: About Swift-Clean

3/39

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

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

Page 13: About Swift-Clean

4/39

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

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

Page 14: About Swift-Clean

5/39 (AutoFix)

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

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

Page 15: About Swift-Clean

6/39 (AutoFix)

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

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

Page 16: About Swift-Clean

7/39 (AutoFix)

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

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

Page 17: About Swift-Clean

8/39 (AutoFix)

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

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

Page 18: About Swift-Clean

9/39 (AutoFix)

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

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

Page 19: About Swift-Clean

10/39

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

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

Page 20: About Swift-Clean

11/39

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

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

Page 21: About Swift-Clean

12/39

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

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

Page 22: About Swift-Clean

13/39

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

Should there be an empty line above return statements?

Page 23: About Swift-Clean

14/39 (AutoFix)

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

What should the spacing around math operators look like?

Page 24: About Swift-Clean

15/39 (AutoFix)

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

Should there be a space before opening braces?

Page 25: About Swift-Clean

16/39 (AutoFix)

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

Should there be a space after commas?

Page 26: About Swift-Clean

17/39

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

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

Page 27: About Swift-Clean

18/39 (AutoFix)

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

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

Page 28: About Swift-Clean

19/39 (AutoFix)

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

Page 29: About Swift-Clean

20/39 (AutoFix)

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

Should there be a space before the type specifier?

Page 30: About Swift-Clean

21/39 (AutoFix)

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

What should the spacing around logical operators look like?

Page 31: About Swift-Clean

22/39 (AutoFix)

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

What should the spacing around the assignment operator look like?

Page 32: About Swift-Clean

23/39

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

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

Page 33: About Swift-Clean

24/39

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

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

Page 34: About Swift-Clean

25/39

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

Page 35: About Swift-Clean

26/39

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

Page 36: About Swift-Clean

27/39 (AutoFix)

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

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

Page 37: About Swift-Clean

28/39 (AutoFix)

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

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

Page 38: About Swift-Clean

29/39

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

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

Page 39: About Swift-Clean

30/39

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

Should class names be capitalized?

Page 40: About Swift-Clean

31/39

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

Should function names be capitalized?

Page 41: About Swift-Clean

32/39

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

Should variable names be capitalized?

Page 42: About Swift-Clean

33/39

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

Should enum names be capitalized?

Page 43: About Swift-Clean

34/39

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

Should struct names be capitalized?

Page 44: About Swift-Clean

35/39

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

Should typealias names be capitalized?

Page 45: About Swift-Clean

36/39

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

Should static variable names be capitalized?

Page 46: About Swift-Clean

37/39

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

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

Page 47: About Swift-Clean

38/39

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

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

Page 48: About Swift-Clean

39/39

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

Page 49: About Swift-Clean

設定方法

Page 50: About Swift-Clean

設定方法

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

Page 51: About Swift-Clean

設定方法

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

Page 52: About Swift-Clean

設定方法

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

Page 53: About Swift-Clean

設定方法

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

Page 54: About Swift-Clean

設定方法

除外ファイルなどの設定

Page 55: About Swift-Clean

設定方法

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

Page 56: About Swift-Clean

設定方法

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

Page 57: About Swift-Clean

設定方法

Install Run Scriptをクリック

Page 58: About Swift-Clean

設定方法

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

Page 59: About Swift-Clean

設定方法

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

Page 60: About Swift-Clean

こんな感じ

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

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

Page 61: About Swift-Clean

注意

Page 62: About Swift-Clean

ビルドするごとに…

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

Page 63: About Swift-Clean

うざかったら

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

Page 64: About Swift-Clean

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

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

→ Swift-Cleanは一つの手段

まとめ

Page 65: About Swift-Clean

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

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

まとめ

Page 66: About Swift-Clean

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

補足

Page 67: About Swift-Clean

おわり