在项目开发过程中,有的人喜欢用tab来缩进,有的人喜欢用空格。为了保持缩进风格的一致,可以使用EditorConfig来规范缩进风格,缩进大小,tab长度以及字符集等。
Editorconfig项目由两部分组成,一个是.editorconfig 的文件格式(format),一个是editorconfig 插件(plugin)
Editorconfig使用.editorconfig文件来设置Python,JavaScript文件的行尾和缩进风格。官方提供的示例代码如下。
# EditorConfig is awesome: http://EditorConfig.org # top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file [*] end_of_line = lf insert_final_newline = true # 4 space indentation [*.py] indent_style = space indent_size = 4 # Tab indentation (no size specified) [*.js] indent_style = tab # Indentation override for all JS under lib directory [lib/**.js] indent_style = space indent_size = 2 # Matches the exact files either package.json or .travis.yml [{package.json,.travis.yml}] indent_style = space indent_size = 2
使用的时候需要把.editorconfig放在项目目录里。
当打开文件的时候,editorconfig 插件就会在当前目录及上级目录寻找.editorconfig文件。
在很多开发工具中都可找到editconfig的插件。
官方文档可以在这个网站查看
http://editorconfig.org/
现在举例在webstorm中安装Editconfig的安装和使用
一.安装
1首先打开Webstorm然后选择Configure

2选择plugins

3选择browser repositories

4找到Editorconfig后右击选择Download and install,安装完成后重启webstorm

http://editorconfig.org/
二使用
在windows下使用时,在要使用editorconfig的项目目录里创建 .editorconfig. 的文件,这样系统会自动命名为.editorconfig
编码就会根据.editorconfig中指定的风格进行规范
具体查看文档解释。
