.editorconfig が使いたい
プロジェクト全体の .editorconfig
が用意されていないが、
ファイル末尾に改行を入れるなど .editorconfig
を利用したいケースがあります。
メンバーと相談して .editorconfig
をコミットするのが理想的ですが、
一時的に .editorconfig
ファイルを用意しコミットしないようにする方法もあります。
.editorconfig
の作成
プロジェクトルートに .editorconfig を作成します。以下はサンプル設定です。
詳細は EditorConfig公式ドキュメント を参照してください。
プロジェクトルート/.editorconfig
# EditorConfig is awesome: https://editorconfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8
# 4 space indentation
[*.py]
indent_style = space
indent_size = 4
# Tab indentation (no size specified)
[Makefile]
indent_style = tab
# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2
# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
.git/info/exclude
の設定
作成した .editorconfig
をコミットしないように、自分の環境の .git/info/exclude
を設定します。
※ リポジトリに .editorconfig
がコミットされた場合はこれを削除する必要があります
プロジェクトルート/.git/info/exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.editorconfig ← 追加
設定の確認
以下のコマンドを実行し、 .editorconfig
が表示されなければ設定完了です。
$ git status