An opinionated ESLint configuration
Across multiple Node.js projects, I use the same linter
- ESLint with node reccomended defaults
- A few plugins (node, security, sonarjs and jest)
- A very strict and opinionated rule set
I was tired to copy-paste config and deps across projects, so I created a shareable eslint config for myself. Eventually could be interesting for somebody else as well.
Basic usage
Install all the dependencies:
yarn add -D eslint eslint-config-node-opinionated eslint-plugin-node eslint-plugin-security eslint-plugin-sonarjs
A one-liner eslint config file is all you need now:
echo "extends: ['node-opinionated']" > .eslintrc.yml
or create your own .eslintrc.js
like this:
module.exports = {
extends: [
'node-opinionated',
],
}
In combo with Jest
I often use ESLint in combination with Jest, with some specific overrides for the tests
folder:
module.exports = {
extends: [
'node-opinionated',
'plugin:jest/recommended'
],
plugins: ['jest'],
overrides: [
{
files: ['**/*test*/**'],
rules: {
'node/no-unpublished-require': 'off',
'node/no-unpublished-import': 'off',
'max-nested-callbacks': ['warn', 3],
'security/detect-child-process': 'off',
'security/detect-non-literal-fs-filename': 'off',
}
},
]
}