ESLint - How to restrict property of `this`

烂漫一生 提交于 2021-02-08 09:16:00

问题


To prohibit code like this.$log.

The following config doesn't work:

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

回答1:


You can achieve this by using no-restricted-syntax rule.

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"
    }
]


来源:https://stackoverflow.com/questions/65432897/eslint-how-to-restrict-property-of-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!