繁体   English   中英

eslint - vue / script-indent忽略对象字段

[英]eslint - vue/script-indent to ignore object fields

我有以下ESLint规则设置:

"vue/script-indent": [
    "error",
    4,
    {
        "baseIndent": 1,
        "switchCase": 1,
        "ignores":
        [
            "[init.type=\"ObjectExpression\"]",
            "[init.type=\"ArrayExpression\"]"
        ]
    }
]

但是,我希望在以下情况下忽略缩进(其中对象键的值是另一个对象)。

这是linter的输出:

let example =
    {
        example:
            {
                test: 
                    "test"
            }
    }

但我希望嵌套对象不受影响,所以它看起来像这样:

let example =
    {
        example:
        {
            test: 
                "test"
        }
    }

所以它应该是一个应该被忽略的Object内部的Object。 我也希望在Object中包含Arrays也被忽略(因此我忽略了Object和Array)

以下规则将vue/script-indent配置为忽略.vue嵌套对象/数组:

"vue/script-indent": [
    "error",
    4,
    {
        "baseIndent": 1,
        "switchCase": 1,
        "ignores": [
            // nested objects, excluding top level of exported object (data, methods, computed, etc.)
            "[value.type='ObjectExpression']:not(:matches(ExportDefaultDeclaration, [left.property.name='exports']) > * > [value.type='ObjectExpression'])",

            // nested arrays
            "[value.type='ArrayExpression']"
        ]
    }
],

注意事项

  • 在TypeScript中,类属性的装饰器(例如@Prop private msg!: string )会导致@Prop private msg!: string错误,其后的每一行都被@Prop private msg!: string忽略。 vuejs/eslint-plugin-vue#834解决方法:插入一个空方法(即_unused() {} )作为类的第一个元素。

  • 对象字段的顺序可能导致vuejs/eslint-plugin-vue#833忽略整个对象( vuejs/eslint-plugin-vue#833 )。 解决方法:确保对象具有文字作为其第一个字段。

暂无
暂无

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

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