@elibol/eslint-config v1.2.0
@elibol/eslint-config
Prettier and ESLint configuration for JavaScript & Vue projects
Table Of Contents
- Installation
- Usage with Vue 2/3
- Usage with Vue 3 & TypeScript
- Usage with JavaScript only
- Inheriting Prettier rules
- Linting your project with NPM scripts
- Enabling autofix on save for VS Code
Installation
- Install the packages to your project with the command below:
npm install -D eslint prettier@^2.7.1 @elibol/eslint-config eslint-config-prettier eslint-plugin-prettier eslint-plugin-vue- Create
.eslintrc.jsfile in your project root if it doesn't exist - Pick the configuration you need from the list below and replace the content of the file with one of the examples below
- Create
prettier.config.jsfile in your project root if it doesn't exist and replace the content with the example below
Vue 2/3 (default config)
// .eslintrc.js
module.exports = {
root: true,
extends: ['@elibol/eslint-config'],
}NOTE: that some rules might not work perfectly with Vue version 2. For those, feel free to override rules in
.eslintrc.jsfile.
Vue 3 & TypeScript
To be able to use TypeScript configuration, make sure to install dependencies below:
npm install -D @typescript-eslint/parser vue-eslint-parser @vue/eslint-config-typescript// .eslintrc.js
module.exports = {
root: true,
extends: ['@elibol/eslint-config/vue3-typescript'],
}JavaScript only
If you would only need to import JavaScript rules but not Vue, then you can use the package as following:
module.exports = {
extends: ['@elibol/eslint-config/javascript'],
}If this is the scenario, you don't need to install eslint-plugin-vue either.
Example prettier.config.js file
This package uses prettier by default. For the config to work properly, you need to inherit prettier rules from the project.
To do that, replace content of your prettier.config.js file with the code below
module.exports = require('@elibol/eslint-config/prettier.config')NOTE: By default the package exports Vue configuration. So using
extends: ["@elibol/eslint-config"]orextends: ["@elibol"]will by default include JavaScript andeslint-plugin-vuerules. If you want to use pure JavaScript or Vue TypeScript configuration, see below.
Linting your project with npm scripts
Add the scripts below to your package.json file. Then you will be able to run
npm lintoryarn lintfor running the linter drynpm lint:fixoryarn lint:fixto run the linter and fix errors/warnings (those that are fixable)
{
"scripts": {
"lint": "eslint \"**/*.{vue,ts,js}\"",
"lint-fix": "eslint --fix \"**/*.{vue,ts,js}\""
}
}Enabling autofix on save for VS Code
Add the settings below to your VSCode settings to run linter on every save
.vscode/settings.json
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}