A quick example how to configure your coding style in ESLint.
Where?
You can choose to place your configuration either in your package.json in an eslintConfig field, or an .eslintrc.js file. For ESM, yaml, or json files read here. These files will be picked up by ESLint automatically, but you can also specify a file like so:
eslint --config my_conf.json my_javascript_code.js
How?
Using rules. There are a lot of rules in ESlint, and we want to write the ones that matter to us into the conf file.
Let’s say we want to prefer using the === operator over ==, which is considered good practice and a popular topic in Javascript development. The ESLint rule for that is eqeqeq – aimed at eliminating the type-unsafe equality operators.
{
"rules": {
"eqeqeq": "warn"
}
}
Possible values are off, warn, error – or respectively 0, 1, 2. Very easy. Now you might want to explore the long list of rules for ESLint to see what you need.
Inline Rules
Rules can also be defined inline:
/* eslint eqeqeq: "warn" */
This way you can overwrite a rule locally, or disable it where needed.
Pre-defined rules
It might look like a tedious job to go through all these available rules and decide if you want to throw an error, a warning, or disable them, and it can be a good idea to start off an existing style from a popular project. An often used style, for example, is the AirBnb style which can be extended by your own rules.
npm i eslint-config-airbnb
For more information read the npm instructions or follow this more comprehensive tutorial on Medium.