How to configure a solid backend NodeJS stack (2) — Linting and code prettifying
This series consists of:
Linter & Prettifier
Every project needs to have a solid linter — I’m partial to:
To configure it, add the command line tool, the plugin import and Airbnb config to the project:
yarn add -D prettier-eslint-cli eslint-plugin-import eslint-config-airbnb-baseAdd a format and lint script to package.json:
...
"format": "prettier-eslint \"src/**/*.js\""
"lint": "eslint \"src/**/*.js\""
...The format script will auto prettify all the js files inside src, the lint script will only report issues.
And an .eslintrc file with the rules:
{
"extends": "airbnb-base",
"rules": {
"quotes": ["error", "single"],
"no-use-before-define": 0,
"no-param-reassign": 0,
"array-callback-return": 0,
"consistent-return": 0,
"no-return-assign": 0
},
"globals": {
"__root": false
}
}The rules can be tweaked a little bit since some of them are very restrictive and do not make sense in all setups — other than that the airbnb-base is an excellent starting point (see https://www.npmjs.com/package/eslint-config-airbnb for details).
Wrap up
You can find the code mentioned in this article at https://github.com/adamgiacomelli/nodejs-stack-example — branch
part-2/linting-and-prettifying
This is the second article in the series. In the next part we will focus on managing database connections.
