Using Eslint in VS Code

Asked

Viewed 92 times

0

Hello! I’m a new Javascript student and am discovering the world of code standardization.

In short, well my situation, I am using the Eslinter + Prettier combo in VS Code and my question is: Every time I open a new project in Node.js I need to install the resources (npx eslinter, npm prettier, etc.) ?

How can I save my Eslinter and Prettier settings to use in all my projects and, when participating in a team project, just add the document with the team standards?

  • You need to install as a development dependency so that anyone working on the project has these dependencies. In addition, you can have your own settings with VS Code extensions but the ideal is to have everything in the Eslint and Prettier configuration files because then you share with everyone on the team without conflict of rules, and copy these files from one project to another. If applicable, you can make configuration packages like Airbnb

1 answer

0

First, we need to know which pattern you’re going to use, but come on.


Create the . eslintrc file globally

AS:
Linux: root@USERNAME > code .eslintrc.json
Windows:C:\users\USERNAME\document(o?)s ou C:\users\USERNAME echo "">.eslintrc.json

With, for example, the following very simple content:

{
  "extends": ["eslint:recommended"],
  "rules": {
     // enable additional rules
     "indent": ["error", 4],
     "linebreak-style": ["error", "unix"],
     "quotes": ["error", "double"],
     "semi": ["error", "always"],

     // override default options for rules from base configurations
     "comma-dangle": ["error", "always"],
     "no-cond-assign": ["error", "always"],

     // disable rules from base configurations
     "no-console": "off"
  }
}

Install the packages globally

npm install -g eslint-config-prettier eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-prettier eslint-plugin-promise eslint-plugin-react eslint-plugin-standard prettier

Install the editor extension, in the case of VS Code, this:

Eslint 2.1.14 (Integrates Eslint Javascript Into VS Code) Author: Dirk Baeumer

Restart the VS Code.

inserir a descrição da imagem aqui

Don’t forget to take a look at the links below. They are from the official documentation itself.

REFERENCE:
https://eslint.org/docs/user-guide/configuring#Extending-Configuration-files
https://eslint.org/docs/user-guide/command-line-interface#-resolve-plugins-relative-to https://medium.com/wearelaika/javascript-eslint-global-configuration-setup-vscode-599cbfc81eb5 https://medium.com/medvine/install-eslint-global-with-airbnb-style-guide-and-use-it-in-vscode-d752dfa40b21

Browser other questions tagged

You are not signed in. Login or sign up in order to post.