コーディングスタイルを統一するため Atom エディタに、 editorconfig パッケージを導入します。
Contents
EditorConfig
EditorConfig は、異なるエディタや IDE でも統一したコーディングスタイルを設定できます。
インストール
Atom エディタのメニューから settings を開きます。
1 |
file -> settings |
settings の 左メニューから install を選択
install packages の検索ボックスを packages にして「 editorconfig 」と入力して検索します。
検索結果に表示される各種パッケージの Install ボタンをクリックします。
コマンドでインストールする場合には下記を実行
1 |
apm install editorconfig |
使い方
プロジェクトフィルツリーの root 直下に .editorconfig ファイルを設置します。
.editorconfig を初期サンプルと同じ内容で編集してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
root = true [*] indent_style = tab indent_size = 3 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.{json,yml}] indent_size = 2 [*.md] trim_trailing_whitespace = false |
設置すると Atom エディタのステータスバーにネズミマークがオレンジ色で表示されます。
ネズミマークをクリックすると警告が表示されます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
.editorconfig whitespace: It is possible that the "whitespace"-package prevents the following properties from working reliably: insert_final_newline, trim_trailing_whitespace. You may try reconfiguring or disabling the "whitespace"-package to solve regarding issues. Active Configuration Editorconfig-Property Applied Setting end_of_line \n charset utf8 indent_style tab indent_size/ tab_width 3 insert_final_newline true trim_trailing_whitespace true max_line_length auto (auto: atom-editorconfig is not influencing its behavior. A full description of all properties can be found on editorconfig.org.) C:\パス\プロジェクト.editorconfig |
Atom の「 whitespace 」パッケージによって「 insert_final_newline 」、「 trim_trailing_whitespace 」のプロパティが動作しなくなる可能性があるとのことなので、問題を解決するために、「 whitespace 」パッケージを無効にします。
「 whitespace 」パッケージは Atom のコアパッケージですが、今回の目的であるコーディングスタイル統一の為、EditorConfigを優先させます。
whitespace パッケージの無効化
1 |
file > settings |
settings の 左メニューから packages を選択して検索ボックスに「 whitespace 」と入力して検索します。表示された whitespace パッケージの Disable ボタンをクリックして無効にします。
これでステータスバーに表示されていたオレンジ色のネズミが消えました。
EditorConfigを使用したプロジェクト一覧
Projects Using EditorConfig · editorconfig/editorconfig Wiki · GitHub
まとめ
チーム開発で開発をすると、ルールを決めても沿ってないコーディングがあったりするものですが、EditorConfig を設定してコーディングスタイルを統一しておくことで、コードレビューの負担を少しでも下げてストレスを減らすことができます。
参考
公式サイト:EditorConfig
atomパッケージサイト:editorconfig