ESLint-如何限制`this`的属性 [英] ESLint - How to restrict property of `this`

查看:74
本文介绍了ESLint-如何限制`this`的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

禁止使用类似 this.$ log 的代码.

以下配置无效:

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

推荐答案

您可以使用因此,在您的 .eslintrc 文件中添加此规则.

So in your .eslintrc file add this rule.

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

这篇关于ESLint-如何限制`this`的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆