DEV Community

Cover image for Why you should write your own ESLint configuration library
Amin
Amin

Posted on

Why you should write your own ESLint configuration library

If you don't know ESLint, it is basically an NPM module that helps you keep a consistent code style. For instance, having your indentation always set to 4 spaces, using double quotes instead of single quotes, etc...

In this article, we will see who this article is aimed for, why and how to create his own ESLint configuration and some external references to work from.

Who

If you ever worked on a project with multiple people, you know that we all have our own code style when it comes to programming. Using an ESLint preset configuration like the one from AirBnB or Google can help you set some standards that any contributors should stick to in order to contribute to your project.

Why

There are hundreds of rules! We can't remember them all. That is why ESLint becomes interesting in the way that you can automate your linting once you are done setting them.

So, if you like having a consistent code style in your JavaScript applications, then this article is for you!

How

If you want to start working your way from scratch as I did, you can follow this guide on the official ESLint documentation.

ESLint consists of a set of rules that you can change to your liking. I spent two days (working on this project after diner) so this can take you quite some time.

Another alternative is to fork the project of someone who has already done that and you can change only the part that you are interested in. That is why I made my repository open-source so that you don't waste time on rules that you agree on.

GitHub logo aminnairi / eslint-config

ESLint configuration presets

🔧 eslint-config

đź“Ś Requirements

🏗️ Installation

$ npm install aminnairi/eslint-config
Enter fullscreen mode Exit fullscreen mode

🤔 Usage

$ touch .eslintrc.js
Enter fullscreen mode Exit fullscreen mode
"use strict";
module.exports = {
    "extends": [
        "@aminnairi"
    ]
};
Enter fullscreen mode Exit fullscreen mode

đź‘· Development

đź“Ś Requirements

🏗️ Installation

$ git clone https://github.com/aminnairi/eslint-config.git
$ cd eslint-config
Enter fullscreen mode Exit fullscreen mode

🤔 Usage

$ make install      # install the dependencies
$ make build        # build the configuration into the "lib" folder
$ make uninstall    # remove the "node_modules" folder
Enter fullscreen mode Exit fullscreen mode

🙏 Contributing

So, you tried it and you like it! Except for some rules that could be better based on your personnal preference. If that is your case, instead of proposing a pull request, you should rather fork the project and make modifications based on your own usage of this module. Why? Simply because you and I may not be in agreement for the thing you may want to update in this…

My advice would be to fork this repository, install it on an existing project (or a new) using the ESLint module and see how it operates and if you are okay with the rules.

If you don't agree on some of the presets used, you can update your repository and install it again to see the changes in real-time.

$ npm install username/eslint-config
Enter fullscreen mode Exit fullscreen mode

That easy! And you don't have to publish anything on any registry, whether it is the NPM registry or the newest GitHub registry. It is totally possible to install an NPM-like module directly from GitHub. Pretty cool, huh?

I'm a new developer and I just want to use one

And that is totally okay! I started to use popular ESLint configuration presets before. That's the power of the open-source. Maybe one day you'll get more experience and have more a more opinionated mind about your code style. You can check this awesome repository for a list of popular configurations to pick from.

GitHub logo dustinspecker / awesome-eslint

A list of awesome ESLint plugins, configs, etc.

Awesome ESLint Awesome

eslint

A list of awesome ESLint configs, plugins, etc.

If you want to contribute, please read the contribution guidelines.

Contents

Configs

Configs by Well-Known Companies/Organizations

  • Airbnb - Shareable config for Airbnb's style guide.
  • Airbnb-babel - Airbnb's ESLint config with Babel Support.
  • Airbnb-typescript - Airbnb's ESLint config with TypeScript support.
  • Alloy - Progressive ESLint config for your React/Vue/TypeScript projects.
  • ESLint - Contains the ESLint configuration used for projects maintained by the ESLint team.
  • Facebook - Sharable config for Facebook's style guide.
  • Feedzai - Feedzai's shareable config for JavaScript/React projects.
  • Google - Shareable…

And if you don't want to fork mine, you can still fork one of them that you'll find the nearest to your own coding style.

Happy hacking!

Top comments (0)