EditorConfig Generator

Generate .editorconfig files for consistent coding styles across editors.

# 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

Часто задаваемые вопросы

Реализация кода

# 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.