一、产生原因
在我们用 vue 脚手架创建项目时,会默认使用 ESLint 校验代码。
二、三种报错及解决方案
-
Newline required at end of file but not found eol-last
这句报错信息的含义是文件的末尾需要有空的一行。
解决方案:找到报错对应的位置,在最后加上一行空白。 -
Trailing spaces not allowed no-trailing-spaces
这句报错信息的含义是后面的空格太多了。
解决方案:
1.找到报错对应的位置,删除多余的空格。
2.找到 .eslintrc.js 文件,在 rules 字段中添加 ‘no-irregular-whitespace’: ‘off’ 关闭不规则的空格校验
rules: {
'no-irregular-whitespace': 'off'
}
- Expected indentation of 0 spaces but found 2 indent
这句报错信息的含义是此处需要0个空格的缩进,但找到2个缩进。
解决方案:
1.找到报错对应的位置,删除多余的空格。
2.找到 .eslintrc.js 文件,在 rules 字段中添加 ‘indent’: ‘off’ 不校验缩进
如:
rules: {
'indent': 'off'
}
三、总结
现实中其实还会遇到很多关于ESLint格式问题,大致解决方案有三种:
1、根据报错信息修改成正确的格式。
2、去 rules 中关闭校验规则。
3、关闭 ESLint 校验功能(比如说创建项目时不要勾选 Linter/Formatter、在 VS code 中关闭… … )