【Vue.JS】Expected indentation of 0 spaces but found 2 & Missing space before function parentheses

使用 webstorm 运行 vue 项目时。报错如下:

WARNING  Compiled with 1 warnings
✘  http://eslint.org/docs/rules/indent                       Expected indentation of 0 spaces but found 2
  src\components\NewHello.vue:8:1
    export default {
✘  http://eslint.org/docs/rules/indent                       Expected indentation of 2 spaces but found 4
  src\components\NewHello.vue:10:1
      data() {
✘  http://eslint.org/docs/rules/space-before-function-paren  Missing space before function parentheses
  src\components\NewHello.vue:10:9
      data() {

✘ 3 problems (3 errors, 0 warnings)

Errors:
  2  http://eslint.org/docs/rules/indent
  1  http://eslint.org/docs/rules/space-before-function-paren

该报错是由于 Vue 项目初始化时,默认生成的验证规则(eslintrc.js)文件验证失败导致。

报错信息很清楚。
1、缩进允许 0 个空格,但是发现了 2 个;
2、缩进允许 2 个空格,但是发现了 4 个;
3、方法插入之前丢失了空格

因为在 eslint 中。默认的规则下,script 内容首行不缩进,内容依照层次一次缩进 2 个空格,方法和括号之间需要一个空格。

而编辑器的格式化可能与 eslint 的规则不太一致,所以导致了如上报错。

解决的办法也很简单。
有两种:
1、修改 IDEA 的设置,将 JS 文件的 Formatter 规则修改与 eslint 的检验规则一致。
2、修改 eslint 的检验规则,忽略对缩进、空格等并不重要的一些规则的验证。(推荐)

进入 eslintrc.js 文件。在 rules 中,加入以下三个规则,忽略对缩进、空格的检查:

'no-tabs':'off',
'indent':'off',
'space-before-function-paren':0

重新运行

npm run dev

 DONE  Compiled successfully in 5142ms
 I  Your application is running here: http://localhost:8080
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HolaSecurity

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值