0
votes

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?

1
why don't you want them to use that? - Daniel A. White
We don't want to include the whole babel-polyfill package, since we use Array.from only one time. Older browsers don't support it, but we have lodash anyway included, so we prefer to use that. To prevent future errors, eslint should help us avoiding Array.from - soerface
are you using anything that returns an iterator such as Map or Set? - Daniel A. White
Sorry, I don't understand the question. Old Androids just do not have the property from of Array. - soerface
I think this is a good question, regardless of whether OP should / shouldn't use Array.from. It definitely does not deserve downvotes. As for why I specifically like this question: I find myself in a situation where I've had to extend a third-party library (Highcharts), but the extension precludes the use of another one of the library's functions. Naturally, I want others to be avoid using that function, and if they really do need it, to fix the extension code first. - Vicky Chijwani

1 Answers

0
votes

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.