在項目開發過程中,有的人喜歡用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中指定的風格進行規范
具體查看文檔解釋。