繁体   English   中英

Vue 组件脚本缩进规则冲突

[英]Vue component script indent rules conflicting

我正在尝试为我的新 Vue 项目设置一些 ESLint 规则,扩展eslint-plugin-vueairbnb 我可以把一切都设置得很好,除了 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 的情况下完成工作。但是,lint 规则仍在抱怨它.

我试着把它放在这个.eslintrc.json文件中:

"overrides": [
    {
        "files": [",*.vue"],
        "rules": {
            "indent": "off"
        }
    }
]

还尝试使用缩进规则中的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"
    ]
}

运行 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 之间的冲突。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM