Home >Web Front-end >JS Tutorial >A tool with the same code writing style——editorConfig

A tool with the same code writing style——editorConfig

巴扎黑
巴扎黑Original
2017-07-20 13:34:201531browse

Previous words

In team development, a unified code format is necessary. However, different developers have different coding styles, and the default formats of code editing tools are also different, which causes code differences. EditorConfig can help developers define and maintain consistent coding styles in different editors and IDEs. This article will introduce in detail the unified code style tool editorConfig

Overview

EditorConfig is not a software, but a custom file named .editorconfig. This file is used to define the coding specifications of the project. The editor's behavior will be consistent with that defined in the .editorconfig file, and its priority is higher than the editor's own settings. This is very useful and necessary when multiple people collaborate to develop projects

Some editors support editorConfig by default, such as webstorm; while some editors need to install the editorConfig plug-in, such as ATOM, Sublime, VS Code, etc.

When a file is opened, the EditorConfig plug-in will open The .editorconfig file is searched for in the file directory and each level of its parent directory until there is a configuration file root=true

The EditorConfig configuration file is read from top to bottom and the latest EditorConfig configuration file will be the most recent. Read first. Configuration items matching the EditorConfig configuration file will be applied in the order they are read, so the configuration items in the latest configuration file have priority

If the .editorconfig file does not have certain configurations, use Editor default settings

File syntax

The editorConfig configuration file needs to be UTF-8 character set encoded, with carriage return or line feed as the separator of a line

The slash (/) is used as a path separator, and the pound sign (#) or semicolon (;) is used as a comment. Comments need to be written on the same line as the comment symbol

[Wildcard]

*                匹配除/之外的任意字符串
**               匹配任意字符串
?                匹配任意单个字符
[name]           匹配name中的任意一个单一字符
[!name]          匹配不存在name中的任意一个单一字符{s1,s2,s3}       匹配给定的字符串中的任意一个(用逗号分隔) 
{num1..num2}    匹配num1到num2之间的任意一个整数, 这里的num1和num2可以为正整数也可以为负整数

[Attribute]

All attributes and values ​​are case-ignored. They are all lowercase when parsed

indent_style    设置缩进风格(tab是硬缩进,space为软缩进)
indent_size     用一个整数定义的列数来设置缩进的宽度,如果indent_style为tab,则此属性默认为tab_width
tab_width       用一个整数来设置tab缩进的列数。默认是indent_size
end_of_line     设置换行符,值为lf、cr和crlf
charset         设置编码,值为latin1、utf-8、utf-8-bom、utf-16be和utf-16le,不建议使用utf-8-bom
trim_trailing_whitespace  设为true表示会去除换行行首的任意空白字符。
insert_final_newline      设为true表示使文件以一个空白行结尾
root           表示是最顶层的配置文件,发现设为true时,才会停止查找.editorconfig文件

Example

The following example uses 4 spaces for indentation. It does not mean that clicking the space button will automatically create 4 spaces, nor does it mean that Press the space 4 times; when you press the tab key, the editor will automatically output the width of 4 spaces instead of the previous default tab character (\t)

# editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true


[*.md]
trim_trailing_whitespace = false

The above is the detailed content of A tool with the same code writing style——editorConfig. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn