Solve the problem of errors and 0 warnings potentially fixable with the `--fix` option.

When creating a new vue-cli, I chose eslint syntax, which
is very
insert image description here
annoying

  • ESLint has many specifications, and the most used ones are标准规范

  • Features:

    • No semicolon at the end of the code
    • Strings in js must use single quotes
    • Can't have too many newlines
    • Can not have more than one space
    • There must be one and only one space around the parentheses of the function name
  • By default, vscode does not have the ability to report irregular codes, so you can install a vscode plug-in calledESLint

    image-20230110120326759

  • Install a formatting plug- Prettier-Standard in, function: when you can right-click to format, help us automatically repair the non-standard code and turn it into a standardized code

    image-20230110120344823

  • The following settings are to allow you to automatically fix non-standard code when you save the code

image-20230110115945939

image-20230110120004801

  • Then add the following configuration to the settings

     	 // 默认使用prittier作为格式化工具
         "editor.defaultFormatter": "numso.prettier-standard-vscode",
         // 保存时自动格式化 - 按照eslint的规则格式化
         "editor.codeActionsOnSave": {
          
          
             "source.fixAll": true
         },
         "[javascript]": {
          
          
             "editor.defaultFormatter": "numso.prettier-standard-vscode"
         },
         "[html]": {
          
          
             "editor.defaultFormatter": "numso.prettier-standard-vscode"
         },
         "[vue]": {
          
          
             "editor.defaultFormatter": "numso.prettier-standard-vscode"
        },
    

At that time, the new project chose eslint syntax. If there is no way,
delete this place in package.json
"@vue/cli-plugin-eslint": "~4.5.0",

Guess you like

Origin blog.csdn.net/weixin_45090657/article/details/129594201