How to promote gender equality in your codebase using ESLint

Alon Kollmann
2 min readMar 9, 2021

If you are writing clean code, then you’re probably familiar with Lint — a static code analysis tool that can help you make sure that your source code is truly great. And if you’re using either JavaScript or TypeScript, then you’re probably familiar with ESLint — the popular JavaScript linter.

But unfortunately, there is one thing that ESLint does not validate by default, and that is the usage of gender-specific terms, such as “he”, “him” or “his” — which developers often tend to use in their code. They might use these terms unintentionally when naming variables, methods, and files - but most commonly, when documenting their code.

How common is this phenomenon? Try looking for “reset his password” on GitHub. Spoiler alert — you’re about to find over 13K code results, only for this specific example.

So what can we do to prevent this? Well, it all boils down to one simple Lint rule that will make sure no gender-specific comments are going to reach your codebase. It is as simple as that:

“no-warning-comments”: [
“error”,
{
“terms”: [“he”, “she”, “him”, “her”, “his”, “hers”],
“location”: “anywhere”
}
]

This rule will fail your Lint check in case it can find a comment that contains any of the terms that were provided to it, anywhere in the comment itself.

Let’s break down its configuration quickly. As you can see in the first line of the configuration, the name of this ESLint rule is no-warning-comments. It was initially created to avoid having random “TODO”/”FIXME” comments in your code, but can be used to filter out any terms that you don’t want to find in your codebase comments. In our case — gender-specific terms.

As with any Lint rule, you can choose the severity level of the rule — in our case, we chose the “error” level, so only code changes that align with this rule could be submitted into our codebase.

In addition, we chose to block the usage of these terms anywhere in the comment, rather than just at the start.

--

--