ESLint Implementation in your Projects
Provided by Leumas Naypoka / www.apphp.com
Content
What is ESLint?
ESLing helps to find and fix problems in your JavaScript code.
Why do you need ESLint?
There are 3 important reasons, why do you need ESling in your project:
-
Finds problems in your code
ESLint statically analyzes your code to quickly find problems. ESLint is built into most text editors and you can run ESLint as part of your continuous integration pipeline. -
Automatically fixes problems in your JS code
Many problems ESLint finds can be automatically fixed. ESLint fixes are syntax-aware so you won't experience errors introduced by traditional find-and-replace algorithms. -
You may customize it according to your needs
Preprocess code, use custom parsers, and write your own rules that work alongside ESLint's built-in rules. You can customize ESLint to work exactly the way you need it for your project.
How to add ESLint to your project
Adding ESLing to your project is quite simple procedure. Generally you have to do following steps:
- Install required plugins
- Set ESLint configuration
- Test ESLint works in your IDE
Install ESlint plugins
Run following commands to install required plugins for ESLint
$ npm i --save-dev eslint
$ npm i --save-dev eslint-plugin-import
If you what to use ESLint for Vue files, install following plugin as well:
$ npm i --save-dev eslint-plugin-vue
You may also install plugin wiht aribnb configuration (if you want to use it)
$ npm i --save-dev eslint-config-airbnb-base
If there is an error while installation, something like: "Error: Failed to load plugin ...", run following commands to fix it:
rm -rf node_modules package-lock.json
npm i
To be continued...