Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

How To Add ESLint and Prettier to the Project

  1. Install eslint and install-peerdeps globally. If it throws any permission error, then prepend sudo to below command.

    npm install -g eslint install-peerdeps
  2. cd into project’s directory and run eslint --init. This will generate eslint config for project. (Choose airbnb style guide during configuration)

  3. Install eslint-config-auto package

    npm install eslint-config-auto --save-dev
  4. Replace extends key in .eslintrc file with below contents

    {
        "extends": ["auto"]
    }
  5. Prepend below lines in package.json’s scripts key.

    "eslint": "eslint --color --ext .html,.js,.json,.jsx,.md,.ts,.tsx *.* src",
    "eslint:fix": "npm run eslint -- --fix",
  6. Run npm run eslint command. This may throw error and one installation command will be displayed. Copy that command and run it in terminal. It will install the required packages. Once all those packages are installed, run npm run eslint again. It should now run linter on all those files.

  7. Install prettier packages

    npm install --save-dev prettier eslint-plugin-prettier prettier-init eslint-config-prettier`
  8. Run below command to generate prettier config for the project.

    # For linux and mac
    ./node_modules/.bin/prettier-init
    
    # For Windows
    .\node_modules\.bin\prettier-init
  9. Project is ready with EsLint and Prettier Config!

  10. If any package fails due to peer dependencies, try installing that package using install-peerdeps command. For example if eslint-config-prettier fails due to peer dependencies, run command install-peerdeps -D eslint-config-prettier eslint and prettier configeslint and prettier setupeslint prettier config vscodeeslint prettier config vscode.

  11. If Using VSCode, install ESLint plugin and Prettier – Code formatter plugin. These plugins will read eslint and prettier configs and help you format the code as you write.