- Building Enterprise JavaScript Applications
- Daniel Li
- 222字
- 2021-07-23 16:31:14
Installing ESLint
Let's install ESLint and run its initiation wizard:
$ yarn add eslint --dev
$ npx eslint --init
? How would you like to configure ESLint?
Use a popular style guide
Answer questions about your style
Inspect your JavaScript file(s)
For this project, we are going to be using Airbnb's JavaScript style guide, which you can find at https://github.com/airbnb/javascript. Therefore, use your arrow keys to select the Use a popular style guide option, and press the Return key. On the next question, select the Airbnb option:
? Which style guide do you want to follow? (Use arrow keys)
Airbnb (https://github.com/airbnb/javascript)
Standard (https://github.com/standard/standard)
Google (https://github.com/google/eslint-config-google)
Next, it'll ask questions about React and the configuration format; select the No and JSON options, respectively:
? Do you use React? No
? What format do you want your config file to be in? JSON
Lastly, it will check whether we have the required dependencies installed, and if not, prompt us to install them. Select the Yes option here:
Checking peerDependencies of eslint-config-airbnb-base@latest
The config that you've selected requires the following dependencies:
eslint-config-airbnb-base@latest eslint@^4.19.1 || ^5.3.0 eslint-plugin-import@^2.14.0
? Would you like to install them now with npm? Yes
This completes the wizard, and you should now see an .eslintrc.json file at the root of your repository, which simply reads as follows:
{
"extends": "airbnb-base"
}