Enforce code consistency with ESLint
Did you ever have to fix a bug in somebody else’s code — but you first had to reformat the code to even understand it? Misplaced spaces, non-standardize line breaks, wrongly sorted imports, etc.
Add linting to a project
We opted for ESLint because it’s well documented, comes with a wide set of rules, and provides good integrations with many IDEs.
To get started, install ESLint to your project:
npm install eslint--save-dev
Next, add a
.eslintrc.json file to the project (the example will enforce semicolons to be at the end of each line):
"semi": ["error", "always"]
Finally, add eslint to your build pipeline by adjusting your
"prepublish": "eslint src",
Use a shared rules set across projects
To use it, just install your shareable ESLint config as a development dependency:
npm install eslint-config-my --save-dev
And then replace the rules in your
.eslintrc.json with a reference to the shared config:
PS: Need an example? You can install our own configuration and try it out:
npm install --save-dev eslint-config-collaborne
Want to learn more about coding? Have a look to our other Medium articles.