我正在尝试为我的新Vue项目设置一些ESLint规则,以扩展eslint-plugin-vue和airbnb。除了Vue组件内的标记外,我可以一切都很好地设置。
可接受的默认值将是:
<script>
export default {
name: 'Login',
};
</script>
但是我正试图使这种代码样式被接受:
<script>
export default {
name: 'Login',
};
</script>
使用规则vue / script-indent(https://eslint.vuejs.org/rules/script-indent.html),我可以将baseIndent设置为1来完成工作。但是,皮棉规则仍在抱怨它。
我尝试将其放在此。eslintrc.json文件中:
"overrides": [
{
"files": [",*.vue"],
"rules": {
"indent": "off"
}
}
]
也尝试使用缩进规则(https://eslint.org/docs/rules/indent)中的ignoredNodes,但是我认为我无法正确设置AST选择器。
这是我当前的。eslintrc.json文件:
{
"extends": [
"plugin:vue/recommended",
"@vue/airbnb"
],
"rules": {
"indent": [2, 4],
"vue/html-indent": [2, 4],
"vue/script-indent": [2, 4, {
"baseIndent": 1
}],
"vue/singleline-html-element-content-newline": 0,
"vue/eqeqeq": 2
},
"plugins": [
"html"
]
}
运行lint时出现这些错误:
8:1 error Expected indentation of 0 spaces but found 4 indent
9:1 error Expected indentation of 4 spaces but found 8 indent
10:1 error Expected indentation of 0 spaces but found 4 indent
如果您使用的是VSCode,此设置可能会为您提供帮助:
// settings.json
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
// ...
}
[当我在此设置之前保存文件时,即使我已经将它们写在.eslintrc.js上,它也使用了我自己未定义的规则。
此设置使其工作正常。
还要检查eslint-plugin-html和eslint-plugin-vue之间的冲突。