How to configure .eslintrc config file with example in NodeJS

In this article, you are going to learn about how to configure the .eslintrc config file with an example in NodeJS. Eslint is basically a…


This content originally appeared on CodeSource.io and was authored by Deven

In this article, you are going to learn about how to configure the .eslintrc config file with an example in NodeJS.

Eslint is basically a program that constantly scans code and finds out potential coding errors or bad coding practices. It is very easy to configure and also used for formatting code. To configure eslint, you need to follow a few steps. First, you need to install the eslint extension from VSCode. All you need to do is to go to the extension option and search for eslint and you will get the extension like the following:

After installing it. you need to download some dev dependencies to make things workable. To do so you need to open your terminal and set the project path where you want to configure eslint and give the following command in the terminal.

We have installed these dev dependencies and you need to download these locally for every project if you want to enable eslint. If you download these globally then things will not work.

Finally, you need to configure your eslint and set up coding rules into .eslintrc.json file. Here, in our case, we have set some common rules in our .eslintrc.json file. See the below:

{
  "extends": ["airbnb", "prettier", "plugin:node/recommended"],
  "plugins": ["prettier"],
  "rules": {
    "prettier/prettier": "off",
    "spaced-comment": "off",
    "no-console": "warn",
    "consistent-return": "off",
    "func-names": "off",
    "object-shorthand": "off",
    "no-process-exit": "off",
    "no-param-reassign": "off",
    "no-return-await": "off",
    "no-underscore-dangle": "off",
    "class-methods-use-this": "off",
    "prefer-destructuring": ["error", { "object": true, "array": false }],
    "no-unused-vars": ["error"]
  }
}

Now let’s see a few examples that our eslint shows error or not. In your case, if it is not working, all you need to do is to close the vs code project and open it again.

You can see that we are getting an error from eslint where we have declared a variable but never used it. Let’s see another example if we try to reassign a constant value.

You can see that in this time we are getting 2 errors from eslint where it is being said that we can not reassign constant variable. These rules are being set by us in .eslintrc.json file.

This is how you may configure .eslintrc config file in NodeJS. Moreover, you may visit the official eslint site and configure your file with the rules that you want to apply.


This content originally appeared on CodeSource.io and was authored by Deven


Print Share Comment Cite Upload Translate Updates
APA

Deven | Sciencx (2022-01-08T12:00:07+00:00) How to configure .eslintrc config file with example in NodeJS. Retrieved from https://www.scien.cx/2022/01/08/how-to-configure-eslintrc-config-file-with-example-in-nodejs/

MLA
" » How to configure .eslintrc config file with example in NodeJS." Deven | Sciencx - Saturday January 8, 2022, https://www.scien.cx/2022/01/08/how-to-configure-eslintrc-config-file-with-example-in-nodejs/
HARVARD
Deven | Sciencx Saturday January 8, 2022 » How to configure .eslintrc config file with example in NodeJS., viewed ,<https://www.scien.cx/2022/01/08/how-to-configure-eslintrc-config-file-with-example-in-nodejs/>
VANCOUVER
Deven | Sciencx - » How to configure .eslintrc config file with example in NodeJS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/08/how-to-configure-eslintrc-config-file-with-example-in-nodejs/
CHICAGO
" » How to configure .eslintrc config file with example in NodeJS." Deven | Sciencx - Accessed . https://www.scien.cx/2022/01/08/how-to-configure-eslintrc-config-file-with-example-in-nodejs/
IEEE
" » How to configure .eslintrc config file with example in NodeJS." Deven | Sciencx [Online]. Available: https://www.scien.cx/2022/01/08/how-to-configure-eslintrc-config-file-with-example-in-nodejs/. [Accessed: ]
rf:citation
» How to configure .eslintrc config file with example in NodeJS | Deven | Sciencx | https://www.scien.cx/2022/01/08/how-to-configure-eslintrc-config-file-with-example-in-nodejs/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.