preface

A thousand people write code in a thousand styles, and every time they merge their colleagues’ code, they crash. To summarize, how to configure ESLint in old projects

steps

  1. npm i eslint typescript -D

  1. In the project root directory, run NPX eslint –init

    1. Install plug-ins as prompted
    2. It automatically generates esLint configuration files
  2. Set up automatic save formatting for vscode

  • Click on vscode Settings

  • Enable the ESLint installation package

  • In the project root directory, add the configuration file:.vscode\settings.json, which reads as follows:
{
    "eslint.run": "onType"."eslint.options": {
      "extensions": [".js".".vue".".jsx".".tsx"]},"editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
    },
    // Editor Settings - do formatting when saving
  "editor.formatOnSave": true.// Editor Settings - default prettier-now for formatting
  // If prettier is used, esbenp.prettier-vscode
  "editor.defaultFormatter":"remimarsal.prettier-now".// Control indentation
  "prettier.useTabs": false.// Indent instead of TAB, use Spaces
  "prettier.tabWidth": 2.// Indent the number of bytes
  
  Function declarations are preceded by Spaces before and after parentheses
  Prettier is optional if you use Prettier, which conflicts with the default configuration of ESLint
  // You can find many records in Baidu: https://www.baidu.com/s?wd=prettier%20%E5%87%BD%E6%95%B0%E7%A9%BA%E6%A0%BC
  "prettier.spaceBeforeFunctionParen": true.// React JSX makes > go with the end tag
  "prettier.jsxBracketSameLine": true."prettier.bracketSpacing": false.// Remove the array header and tail whitespace
  "prettier.semi": false.// Do not add;
  "prettier.singleQuote": true.// Use single quotes
  "prettier.trailingComma": "none".// Do not follow the comma,
  "prettier.printWidth": 80.// Wrap each row over 80 columns

  // In.js, when writing div, press TAB to complete it automatically, instead of writing 
  "emmet.includeLanguages": {
    "javascript": "javascriptreact"}}Copy the code

ps:

If the content has the wrong place welcome to point out (feel looking do not understand uncomfortable want to make fun of completely no problem); If there is help, welcome to like and collect, please reprint the source, if there is a problem also welcome private communication