【问题标题】:ESLint - How to restrict property of `this`ESLint - 如何限制 `this` 的属性
【发布时间】:2020-12-24 12:03:32
【问题描述】:

禁止this.$log之类的代码。

以下配置不起作用:

{
  'no-restricted-properties': [
    2,
    {
      object: 'this',
      property: '$log',
    },
  ],
}

【问题讨论】:

    标签: javascript eslint


    【解决方案1】:

    您可以使用no-restricted-syntax 规则实现此目的。

    所以在您的.eslintrc 文件中添加此规则。

    "no-restricted-syntax": [
        "error",
        {
            "selector": "MemberExpression[object.type='ThisExpression'][property.name='$log']",
            "message": "this.$log is prohibited"
        }
    ]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-05
    相关资源
    最近更新 更多