Skip to content

Instantly share code, notes, and snippets.

@montasim
Last active July 6, 2024 14:15
Show Gist options
  • Save montasim/8290b242fab274a807e193d6517ad766 to your computer and use it in GitHub Desktop.
Save montasim/8290b242fab274a807e193d6517ad766 to your computer and use it in GitHub Desktop.
The purpose of this .editorconfig file is to ensure that all contributors to your project adhere to specified coding and styling standards automatically, minimizing the formatting discrepancies that can occur when different developers with different editing environments work on the same project. This leads to cleaner, more readable code that loo…
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Matches multiple files with brace expansion notation
[*.{js,jsx,ts,tsx}]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = crlf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80
# JSON files override
[*.json]
indent_style = space
indent_size = 2
insert_final_newline = true
# Markdown files (Markdown generally prefers no trailing spaces)
[*.md]
trim_trailing_whitespace = false
@montasim
Copy link
Author

montasim commented Jul 6, 2024

Overview

EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. The settings in the .editorconfig file are recognized by supported editors, which adjust their formatting settings accordingly. This particular .editorconfig file specifies rules for JavaScript, TypeScript, JSON, and Markdown files.

File Description

root = true: This line declares that this is the top-most EditorConfig file in the directory structure. EditorConfig will stop searching for more files in parent directories once it reaches a file with root = true.

[*.{js,jsx,ts,tsx}]: This section applies to files with extensions js, jsx, ts, and tsx. It sets several formatting rules:

charset = utf-8 ensures that the file encoding is UTF-8.
indent_style = space uses spaces for indentation.
indent_size = 4 sets the width of the indentation to four spaces.
end_of_line = crlf enforces the use of carriage return and line feed (\r\n) as the line ending, which is typical for Windows systems.
trim_trailing_whitespace = true removes any spaces that follow the last non-space character on a line.
insert_final_newline = true ensures that the file ends with a newline.
max_line_length = 80 suggests a maximum line length of 80 characters.
[*.json]: This section applies specifically to JSON files and overrides some of the previous settings:

indent_style = space and indent_size = 2 adjust the indentation to two spaces, which is a common convention for JSON files.
insert_final_newline = true remains the same as the general setting, ensuring a newline at the end of the file.
[*.md]: This section is for Markdown files:

trim_trailing_whitespace = false allows trailing whitespaces to remain, which can be significant in Markdown for indicating line breaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment