Codiga has joined Datadog!

Read the Blog·

Interested in our Static Analysis?

Sign up
← All posts
Julien Delange Wednesday, January 4, 2023

How to write inclusive JavaScript code?

Share

AUTHOR

Julien Delange, Founder and CEO

Julien is the CEO of Codiga. Before starting Codiga, Julien was a software engineer at Twitter and Amazon Web Services.

Julien has a PhD in computer science from Universite Pierre et Marie Curie in Paris, France.

See all articles

What inclusive JavaScript code means?

It is generally recommended to avoid using some words in your code to avoid being considered offensive or inappropriate by some developers.

For example, words like "blacklist" and "whitelist" in your code, as they can be considered offensive or inappropriate by some people. The use of these terms is associated by some people with discrimination, and using them may be seen as insensitive or offensive to some readers. For this reason, and especially if your developers come from diverse backgrounds, it is recommended to avoid such wording.

Instead of using these terms, you can use more neutral language such as "blocklist" or "allowlist" to describe lists of items that should be blocked or allowed, respectively. Using neutral language can help to make your code more inclusive and welcoming to a wider range of users.

What words to watch to ensure inclusive JavaScript code?

Here are a few examples of words and phrases that you might want to avoid to make your code more inclusive:

  • Blacklist/whitelist: These terms have a history of association with racism and discrimination, and may be seen as offensive or inappropriate by some readers.
  • Master/slave: These terms are often used to refer to the primary and secondary copies of data in a database, but they have a history of association with slavery and may be seen as offensive by some readers.
  • Dummy/stub: These terms are often used to refer to placeholder objects in code, but they can be seen as condescending or belittling by some readers.

It is important to be mindful of the language you use in your code and to choose words that are neutral and inclusive. Using inclusive language can help to make your code more welcoming and accessible to a wider range of users.

How to ensure developers enforce inclusive guidelines for their JavaScript code?

Codiga provides a static code analyzer that works at every step of your development process. With the Codiga IDE plugins, you can ensure that non-inclusive words are being detected and replacements are suggested, as shown below. You can also check the same rules in your CI/CD pipeline at every pull request.

Enforce inclusive JavaScript code in VS Code

To use Codiga in your IDE:

  1. Download Codiga for your IDE
  2. Add a codiga.yml file at the root of your project with the content below (you will be using the javascript-inclusive ruleset)

codiga.yml configure for inclusive JavaScript code

If you also want to check your code at each pull and push request, install Codiga on your repository as well:

The rule checks for function names as well as variable names. You can explore the rules and test them yourself by visiting the ruleset on the Codiga Hub.

Explore rules for inclusive JavaScript code

Make your Python code more inclusive as well!

If you are also using Python, consider using the python-inclusive ruleset that ensures that your Python code follows inclusive coding guidelines.

Are you interested in Datadog Static Analysis?

Sign up