phe*_*rin 5 javascript lint eslint vue.js vue-component
我正在尝试为我的新 Vue 项目设置一些 ESLint 规则,扩展eslint-plugin-vue和airbnb。我可以把一切都设置得很好,除了 Vue 组件中的标签。
接受的默认值类似于:
<script>
export default {
name: 'Login',
};
</script>
Run Code Online (Sandbox Code Playgroud)
但是我试图让这种代码风格被接受:
<script>
export default {
name: 'Login',
};
</script>
Run Code Online (Sandbox Code Playgroud)
使用规则vue/script-indent ( https://eslint.vuejs.org/rules/script-indent.html ) 我可以在baseIndent设置为 1 的情况下完成工作。但是,lint 规则仍在抱怨它.
我试着把它放在这个.eslintrc.json文件中:
"overrides": [
{
"files": [",*.vue"],
"rules": {
"indent": "off"
}
}
]
Run Code Online (Sandbox Code Playgroud)
还尝试使用缩进规则中的ignoreNodes ( https://eslint.org/docs/rules/indent ) 但是我认为我无法正确使用 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"
]
}
Run Code Online (Sandbox Code Playgroud)
运行 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
Run Code Online (Sandbox Code Playgroud)
Fab*_*ins -3
如果您使用 VSCode,此设置可能会帮助您:
// settings.json
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
// ...
}
Run Code Online (Sandbox Code Playgroud)
当我在此设置之前保存文件时,它包含了一些不是我定义的规则,即使我已经将它们编写在 .eslintrc.js 上。
这个设置让它工作得很好。
但还要检查 eslint-plugin-html 和 eslint-plugin-vue 之间的冲突。
| 归档时间: |
|
| 查看次数: |
1043 次 |
| 最近记录: |