🙆

vscode setting と editorconfig の併用

2024/07/20に公開

EditorConfig とは?

EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs. The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles. EditorConfig files are easily readable and they work nicely with version control systems.

要約すると、IDE 横断で使用できるコードフォーマッター 。

https://editorconfig.org/

EditorConfig を使用するメリット

上記で説明されているように、さまざまな IDE を横断して利用できること。

1人称の開発であれば、 各 IDE 独自の設定ファイル(筆者の場合は、 vscode を使用しているので、.vscode/settings.json)を使用すれば問題ないですが、
チーム開発をするとなると、使用する IDE が異なる場合が考えられるので、フォーマット系に関してEditorConfigを使用する方がいいと考える。

EditorConfig の設定例

プロジェクト直下に.editorconfigを作成し、下記コードを貼り付ける。

.editorconfig
root = true // プロジェクトのルートであることを記載。この記述は必須。

[*]
indent_style = space // "space" or "tab" が設定できる。個人的にタブを消すときのことを考えると "space" の方が好み。
indent_size = 2 // インデントの数
insert_final_newline = true // ファイル最後に新しい行(改行文字)を挿入する。

以上!

GitHubで編集を提案

Discussion