ESLint - How to restrict property of `this`

Viewed 239

To prohibit code like this.$log.

The following config doesn't work:

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

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