【问题标题】:eslint indent rule indents decorated memberseslint 缩进规则缩进装饰成员
【发布时间】:2022-01-13 20:57:27
【问题描述】:

为了启用链式方法的缩进:

await PostModel
  .findOne({
    author: user.user,
    _id: id,
  })
  .populate('tickets', 'title status');

根据eslint docs,我已将以下MemberExpression 添加到我的eslintrc 中

indent": ["error", "tab", { "MemberExpression": 1 }],

但现在我遇到了装饰器的问题,尽管我更喜欢让它们与成员对齐,但它会缩进。

@prop({ type: String, required: true })
  password: string;

有没有办法在不发生冲突的情况下解决这两种情况?

【问题讨论】:

    标签: eslintrc typescript-eslint


    【解决方案1】:

    根据this issue,您可以部分禁用装饰器的缩进规则:

    indent: [
            'error',
            'tab',
            {
                MemberExpression: 1,
                ignoredNodes: [
                    'FunctionExpression > .params[decorators.length > 0]',
                    'FunctionExpression > .params > :matches(Decorator, :not(:first-child))',
                    'ClassBody.body > PropertyDefinition[decorators.length > 0] > .key',
                ],
            },
        ],
    

    这对我有用。

    【讨论】:

    • 谢谢,但这对我根本不起作用。似乎缩进规则存在一个未解决的问题,导致许多其他票被关闭。
    猜你喜欢
    • 2019-04-06
    • 2020-08-15
    • 2021-12-10
    • 1970-01-01
    • 2019-02-10
    • 2021-06-12
    • 2023-03-26
    • 2020-11-01
    • 2022-08-09
    相关资源
    最近更新 更多