muenzpraeger / eslint-plugin-inclusive-language

An ESLint plugin to raise awareness for using inclusive language not only in your codebase, but in life.
MIT License
57 stars 10 forks source link

feat: Update allowedTerms to optionally match partial words #6

Closed sarayourfriend closed 4 years ago

sarayourfriend commented 4 years ago

Currently allowedTerms matches only full words by using includes on the list of words.

https://github.com/muenzpraeger/eslint-plugin-inclusive-language/blob/primary/lib/rules/use-inclusive-words.js#L37

The intended usage of this feature is to exclude certain terms that are not able to be avoided for one reason or another (like the names of credit card processors). The current behavior doesn't accomplish this. For example, in this repository:

https://github.com/Automattic/wp-calypso/blob/336f26751af6acacd9cede88145d47895f80ebb9/client/components/payment-logo/index.jsx#L23

Even if we add mastercard to the list of allowedTerms, that particular line will continue to cause a rule failure as mastercard isn't the full term. We've run into this issue here: https://github.com/Automattic/wp-calypso/pull/43866#pullrequestreview-441870336

If we could change the API of allowedTerms to be objects rather than raw strings, we could do something like the following:

{
  "allowedTerms": [
    { "term": "mastercard", "allowPartialMatches": true },
  ]
}

I'm not sure what the best option for the default value of allowPartialMatches (or what a better name could be, there might be something clearer).

It should be realtively easy to preserve backwards compatability with the current API as well.