简体   繁体   中英

How to allow semicolon in Eslint?

I just install Eslint to prettify my code, but it give me error of extra semicolon in the end - how to disable this rule? I think semicolon in the end is necessary.

.eslintrc.json

{
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "plugin:react/recommended",
        "standard-with-typescript"
    ],
    "overrides": [
    ],
    "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "module",
        "project":"./tsconfig.json"
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "semi": [2, "always"],
       
        "quotes":[
        "error",
        "double",
        {
            "avoidEscape":true
        }
    ],
    "@typescript-eslint/quotes":[
        "error",
        "double",
        {
            "avoidEscape":true
        }
    ]
    }
}

Error:

错误

Add "no-extra-semi":"off" to rules:

{
   "env":{
      "browser":true,
      "es2021":true
   },
   "extends":[
      "plugin:react/recommended",
      "standard-with-typescript"
   ],
   "overrides":[
      
   ],
   "parserOptions":{
      "ecmaVersion":"latest",
      "sourceType":"module",
      "project":"./tsconfig.json"
   },
   "plugins":[
      "react"
   ],
   "rules":{
      "no-extra-semi":"off",
      "quotes":[
         "error",
         "double",
         {
            "avoidEscape":true
         }
      ],
      "@typescript-eslint/quotes":[
         "error",
         "double",
         {
            "avoidEscape":true
         }
      ]
   }
}

The error is from the @typescript-eslint/semi rule (different from just semi ). Disable the semi rule and set the options on the typescript rule instead:

{
  "semi": "off",
  "@typescript-eslint/semi": [2, "always"],
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM