使用 EditorConfig来规范代码缩进等的风格以webstorm为例

在项目开发过程中,有的人喜欢用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中指定的风格进行规范

具体查看文档解释。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值