EditorConfig ジェネレーター
エディタ間で一貫したコーディングスタイルのための.editorconfigファイルを生成します。
# EditorConfig — https://editorconfig.org root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true max_line_length = 120 [*.json] indent_size = 2 [*.md] trim_trailing_whitespace = false
このツールについて
EditorConfigは、開発チームがさまざまなエディタやIDEで一貫したコード形式を保つための設定ファイル形式です。チームメンバーがVisual Studio Code、JetBrains IDE、Sublime Text、Vimなどの異なるエディタを使用する場合、.editorconfigファイルはインデント、行末、文字セット、その他の形式ルールを統一し、個人が好むツールに関わらず一貫性を保証します。これはバージョン管理システムでのフォーマット競合を排除し、スタイル議論に費やす時間を削減します。
このジェネレータを使用するには、インデントタイプ(タブまたはスペース)、インデントサイズ、行末スタイル(LF、CRLF、または自動検出)、文字セットの設定を選択するだけです。また、Python、JavaScript、JSON、その他の言語など、特定のファイルタイプのルールも設定できます。すべての設定をカスタマイズしたら、生成されたファイルをダウンロードし、プロジェクトルートディレクトリに配置します。チームメンバーのエディタは、そのプロジェクトでファイルを開くときにこれらのルールを自動的に適用します。
EditorConfigはほとんどの最新エディタにネイティブサポートまたは軽量プラグインで統合され、追加のビルドツールやリンターを必要とさせない最も簡単なコードスタイル一貫性の実装方法の一つです。オープンソースプロジェクト、企業コードベース、または協調作業環境で作業するチームが最も恩恵を受けます。このツールは複数のプログラミング言語が共存するポリグロットプロジェクトに特に有用です。これは.editorconfigルールをファイル拡張子ごとにカスタマイズできるためです。
よくある質問
コード実装
# Generate a .editorconfig file programmatically
def generate_editorconfig(indent_style="space", indent_size=2, end_of_line="lf",
charset="utf-8", trim_trailing_whitespace=True,
insert_final_newline=True) -> str:
lines = [
"# EditorConfig is awesome: https://editorconfig.org",
"",
"# top-most EditorConfig file",
"root = true",
"",
"[*]",
f"indent_style = {indent_style}",
f"indent_size = {indent_size}",
f"end_of_line = {end_of_line}",
f"charset = {charset}",
f"trim_trailing_whitespace = {str(trim_trailing_whitespace).lower()}",
f"insert_final_newline = {str(insert_final_newline).lower()}",
"",
"[*.md]",
"trim_trailing_whitespace = false",
"",
"[Makefile]",
"indent_style = tab",
"",
"[*.{json,yml,yaml}]",
"indent_size = 2",
]
return "\n".join(lines)
config = generate_editorconfig(indent_style="space", indent_size=4)
print(config)
# Write to file
with open(".editorconfig", "w") as f:
f.write(config)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.