Last active
December 25, 2024 17:43
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################################### | |
# .editorconfig Configuration File | |
#################################################### | |
# EditorConfig is awesome: https://EditorConfig.org | |
# This configuration enables consistent coding styles between various | |
# text editors and IDEs. By specifying formatting properties based | |
# on file types, it helps maintain a standard code style for teams | |
# or individual developers. The rules here act as a guide for | |
# better readability and maintainability of codebases. | |
#################################################### | |
# GENERAL SETTINGS | |
#################################################### | |
# Purpose: | |
# The root setting determines whether this is the top-level | |
# .editorconfig file in the directory hierarchy. | |
# - `root = true` specifies that this is the highest priority | |
# configuration file, and all other .editorconfig files in | |
# parent directories (if any) will be ignored. | |
root = true | |
#################################################### | |
# JAVASCRIPT, JSX, TYPESCRIPT, TSX FILES | |
#################################################### | |
# Purpose: | |
# Defines rules explicitly for JavaScript, JSX, TypeScript, | |
# and TSX files to enforce consistent formatting styles. | |
# Rules: | |
# - `charset = utf-8`: Ensures the character encoding for these | |
# files is universally UTF-8, avoiding issues with different encodings. | |
# - `indent_style = space`: Specifies that spaces, not tabs, | |
# should be used for indentation. | |
# - `indent_size = 4`: Sets the visual space equivalent to 4 spaces | |
# for each level of indentation. | |
# - `end_of_line = crlf`: Enforces the use of carriage return plus | |
# line feed (CRLF) as the newline character, commonly used in Windows. | |
# - `trim_trailing_whitespace = true`: Automatically removes all | |
# unnecessary whitespace at the end of a line. | |
# - `insert_final_newline = true`: Ensures every file ends with a | |
# single newline character, following POSIX standards. | |
# - `max_line_length = 80`: Specifies that every line should ideally | |
# not exceed 80 characters to enhance readability. | |
[*.{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 | |
#################################################### | |
# Purpose: | |
# Rules specified here are tailored specifically to handle JSON data files. | |
# Because JSON has strict styling and formatting requirements, this | |
# section ensures that JSON files comply with common conventions. | |
# Rules: | |
# - `indent_style = space`: Spaces are used for indentation, as is | |
# standard in JSON formatting. | |
# - `indent_size = 2`: Each level of indentation consists of 2 spaces | |
# (commonly used for JSON for compactness). | |
# - `insert_final_newline = true`: Ensures each file ends with a | |
# newline for better compatibility across systems when reading files. | |
[*.json] | |
indent_style = space | |
indent_size = 2 | |
insert_final_newline = true | |
#################################################### | |
# MARKDOWN FILES | |
#################################################### | |
# Purpose: | |
# Specifies formatting rules for markdown files (.md), used best | |
# for writing documentation or plain-text files. | |
# Rules: | |
# - `trim_trailing_whitespace = false`: Ensures that whitespace is | |
# preserved in Markdown files, as trailing whitespace can have | |
# semantic meaning (e.g., for line breaks in Markdown). | |
[*.md] | |
trim_trailing_whitespace = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.