Install ESLint in Your Project
-
Run the following command to install ESLint as a development dependency in your project:
- This installs ESLint locally in your project and adds it to your
package.jsonfile'sdevDependencies, making it easier to manage versions and ensure consistency across the team.
Set Up the ESLint Configuration File
-
Run the following command to generate the
.eslintrcconfiguration file:npx eslint --init -
This command will interactively guide you through the setup process, asking about your coding style, preferred rules, and the type of environment (e.g., Node.js, browser). It will create a
.eslintrcfile that contains the necessary configuration settings for ESLint. -
Choose to Extend the Google JavaScript Style Guide
-
During the ESLint initialization process, when prompted to choose a style guide, select Google as your base configuration.
-
Reason: The Google JavaScript Style Guide is a widely adopted, well-established style guide that promotes good practices and consistent code formatting, so extending it will help you maintain quality code.
-
Summary
-
Install ESLint with
npm install eslint --save-dev. -
Run
npx eslint --initto set up your.eslintrcconfiguration file and choose the Google JavaScript Style Guide.