My Eslint and Prettier Config
Updated: March 29, 2020I finally took some time to setup Eslint and Prettier with VS Code and made the eslint-config-eneax package.
If you want to know what Eslint rules I use, check them out here. If you want to install and configure the package on your projects, follow the instructions below.
Install
You can use eslint globally and/or locally per project. I prefer to install it locally per single project, so I can have project specific settings:
Create a package.json
file with npm init
and install everything needed by the config:
Create a .eslintrc
file in the root of the project's directory and copy this:
You can add two scripts to your package.json
to lint and/or fix your code:
For instance, if all your code is in a src/
folder:
Now you can manually lint your code by running npm run lint
and fix all fixable issues with npm run lint:fix
.
Settings
If you want to overwrite eslint or prettier settings, go to your .eslintrc
file and you can add rules
.
ESLint rules go directly under rules
while prettier options go under "prettier/prettier"
.
For instance:
VS Code
If you use VS Code and want it to lint all the errors for you, here are the instructions:
- Install the ESLint package
- Setup VS Code settings via
Code
→Preferences
→Settings
:
Not working?
Remove all eslint
modules that we installed previously:
Remove package-lock.json
file and delete the node_modules/
directory and repeat above instructions again!