In our current project we've had some recurring problems with people using 'asMutable' from seamless-immutable where it isn't actually necessary. This has resulted in 'search project for string "asMutable"' becoming part of every pull request. To speed this up we would like to add a rule warning that to our eslint. But I haven't figured out how.
What seems like the best solution to me right now, though I'm open to suggestions, is a rule that allows me to specify a function name to forbid. Does ESlint, or a plugin therefore, have that sort of functionality?
I've looked a little into writing our own, but I was intimidated by AST and the startup difficulty to writing my first rule. I may take the plunge if I can't find a better answer, yes we're getting this enough in PRs to warrant it. This seems like something someone much smarter than me has already solved though, so I'd rather follow in their footsteps then build my own.
You can do some very fancy things when you combine ESLint's no-restricted-syntax
rule with selectors
. In your case you should be able to achieve the linting you want without writing your own plugin. The rule would look something like:
{
rules: {
'no-restricted-syntax': [
'error',
{
message: "Please don't use asMutable. We don't like it!",
selector:
'MemberExpression > Identifier[name="asMutable"]'
}
]
}
}
Study the documentation page for selectors
; it is very flexible!