This is the 20th day of my participation in the August Text Challenge.More challenges in August

The code editor maintains its own configuration, which includes coding style Settings such as “Tab or Space for indentation,” “how many columns a Tab occupies,” “whether to display blank lines at the end of the file,” and so on.

The configuration information of the code editor is maintained independently and not shared externally. Use different editors or use the same one with different configuration information to open the same file. If the editor configuration is not unified, the display effect and input effect may be inconsistent.

In team development, a common code format is essential. However, the default format of the code editing tool will result in a different format of the code. Over time, the code will appear to be unusually cluttered and not conducive to maintenance.

role

EditorConfig helps developers unify and maintain code styles between different editors, and helps projects do Eslint and other code reviews and standardize code. EditorConfig lets the editor plug-in format the code by building a configuration file in the project. The EditorConfig configuration file is straightforward and works well with the version controller.

  • EditorConfig is not software, but a custom file named. EditorConfig.
  • The editorConfig file is used to define the coding specification of the project
  • The configuration weight in editorConfig is higher than the Settings in the editor itself. This ensures consistent editor Settings for collaborative development

EditorConfig addresses coding style consistency issues at the editor configuration level. The section on code style, however, does not

For example, whether “semicolons need to be added to the end of statements”, “strings wrapped in single or double quotation marks”, “writing specifications for multi-line objects” and so on.

These use esLint, TSLint and other Lint tools to help us complete the corresponding format verification

use

Use can be divided into two cases, you can click on the official website to see if the current IDE supports EditorConfig

  • One is built into the IDE and simply writes configuration files, such as WebStorm

  • The other is that the IDE does not support it by default, so you need to install the corresponding plug-in to support it. For example, VScode requires EditorConfig for VS Code

The configuration file

  1. When you open a file,EditorConfigThe plug-in traverses the directory of the file and looks up its parent directory at each level.editorconfigFile until there is a configuration fileroot=trueBefore they stop looking
  2. EditorConfigConfiguration files are parsed from top to bottom
  3. All attribute names and attribute values in the.EditorConfig file are case insensitive. It is always lowercase at compile time
  4. If an attribute is not explicitly specified, the editor’s default configuration is used, andEditorConfigNot deal with
  5. Recommend toEditorConfigThe configuration file is written in the root directory of the project

The file format

  • EditorConfigFiles useINI format
  • Use a slash (/) as the path separator
  • use#or;As a comment, the comment should be on its own line
  • EditorConfigFiles useUTF-8format
  • useCRLForLFAs a newline character.

The wildcard

Special characters need to be escaped through the escape character, so that special characters will not be parsed as wildcards.

The wildcard instructions
* Except for the path separator\External matches all string characters
六四风波 Any character
? All single characters
[name] Match the name character
[!name] Matches non-name characters
{s1, s2, s3} Matches any given character (separated by commas)

Attributes that

The property name instructions An optional value note
root Special property to end the search for the EditorConfig configuration file true
indent_style Set indentation style TAB is hard indent, space is soft indent
indent_size Sets the width of the indentation by defining the number of columns to be defined The integer This parameter is used when indent_style is space
tab_width Sets the number of columns to indent with TAB The integer This parameter is used when indent_style is TAB
end_of_line Set a newline character The value is LF, CR, and CRLF Lf is recommended.
charset Set encoding format The value can be LATin1, UTF-8, UTF-8-BOM, UTF-16BE, or UTF-16LE Recommend utf-8
trim_trailing_whitespace Remove extra space at the end of lines Boolean value Recommend the true
insert_final_newline The file ends with a blank line Boolean value Recommend the true

The sample

# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
Copy the code