1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

リポジトリにコミットされていない .editorconfig を使いたい

Posted at

.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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?