eslint-config-mikebruns v1.1.1
eslint-setup
Just a repository to hold my likings for eslint & editorconfig and how to setup vscode with eslint
Tools Used
- VsCode
- editorconfig
- eslint
- eslint plugin
Setup
Local / Per Project Install
If you don't already have a
package.json
file, create one withnpm init
.Then we need to install everything needed by the config:
npx install-peerdeps --dev eslint-config-mikebruns
You can see in your package.json there are now a big list of devDependencies.
Create a
.eslintrc
file in the root of your project's directory (it should live where package.json does). Your.eslintrc
file should look like this:
{
"extends": [
"mikebruns"
]
}
Tip: You can alternatively put this object in your package.json
under the property "eslintConfig":
. This makes one less file in your project.
- You can add two scripts to your package.json to lint and/or fix:
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
Now you can manually lint your code by running
npm run lint
and fix all fixable issues withnpm run lint:fix
. You probably want your editor to do this though.Add the eslint plugin to vscode. Then add to vscode's JSON settings
"editor.formatOnSave": true,
// turn it off for JS and JSX, we will do this via eslint
"[javascript]": {
"editor.formatOnSave": false
},
"[javascriptreact]": {
"editor.formatOnSave": false
},
// tell the ESLint plugin to run on save
"eslint.autoFixOnSave": true,
This will automatically update files upon save based on eslint rules defined.