配置 editor config
在項(xiàng)目下創(chuàng)建文件 .editorconfig
root = true # 根目錄的配置文件,編輯器會(huì)由當(dāng)前目錄向上查找,如果找到 `roor = true` 的文件,則不再查找
[*] # 匹配所有的文件
indent_style = space # 空格縮進(jìn)
indent_size = 4 # 縮進(jìn)空格為4個(gè)
end_of_line = lf # 文件換行符是 linux 的 `\n`
charset = utf-8 # 文件編碼是 utf-8
trim_trailing_whitespace = true # 不保留行末的空格
insert_final_newline = true # 文件末尾添加一個(gè)空行
curly_bracket_next_line = false # 大括號(hào)不另起一行
spaces_around_operators = true # 運(yùn)算符兩遍都有空格
indent_brace_style = 1tbs # 條件語(yǔ)句格式是 1tbs
[*.js] # 對(duì)所有的 js 文件生效
quote_type = single # 字符串使用單引號(hào)
[*.{html,less,css,json}] # 對(duì)所有 html, less, css, json 文件生效
quote_type = double # 字符串使用雙引號(hào)
[package.json] # 對(duì) package.json 生效
indent_size = 2 # 使用2個(gè)空格縮進(jìn)
編輯器中啟用 editor config 插件
webstorm 中自帶了 editor config 插件
sublime 用戶可以去這里下載安裝