Source: https://dev.to/matthias/sharing-prettier-configuration-files-gba
This package helps us configure ESlint and Prettier to work together nicely. When the steps below are completed, then our node project will have ESLint and Prettier interact correctly. This configuration ensures that a VSCode with ESLint & Prettier plugins (without custom settings) will work.
npm install --save-dev eslint-plugin-prettier eslint-config-prettier prettier @boolean-uk/boolean-prettier-config
If you want to use your shared Prettier configuration in other projects, you need to reference it in your project's package.json
manifest by adding the prettier
property:
{
"name": "my-cool-library",
// ...
"prettier": "@boolean-uk/boolean-prettier-config",
// ...
}
ESLint configuration: ensure we extend prettier, use the prettier plugin and have the prettier error rule setup.
module.exports = {
env: {
commonjs: true,
es2021: true,
node: true
},
extends: ['standard', 'prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': ['error']
},
parserOptions: {
ecmaVersion: 12
},
}
After cloning and running npm install
we must restart VSCode in order for the ESLint and Prettier plugins to pick up the updated configuration.