javascripteslint

eslint rule to disallow specific variables / methods


I need an eslint rule to disallow the usage of a specific variable / method. In particular, I don't want anyone to use Array.from in our project.

I've looked into http://eslint.org/docs/rules/ and searched for custom rules, however, I'm not sure if this is even how rules work. It seems to me that rules are either turned on or off, not configured like “disallow usage of x, x.y and z()”

Is the way to go to write a custom rule?


Solution

  • Yes, if the rule doesn't exists in the core distribution, your best bet is to create a custom rule. You can also make it configurable by using context.options property inside of the rule, you can get configuration information.