简体   繁体   中英

I need remove the semicolon error ESLint + Prettier

How can I remove the semicolon rule?

I've tried to remove the semi rules, but I'm not succeeding. When I save the file once it removes the semicolons and lint complains that it's missing, and when I insert it it complains again saying to remove.

I would like to keep the semicolon

在此处输入图像描述

Thats my .prettierrc file:

{
  "printWidth": 100,
  "singleQuote": true,
  "tabWidth": 4,
  "trailingComma": "es5",
  "endOfLine":"auto",
  "semi": true
}

and thats my .eslintrc file

{
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        }
    },
    "env": {
        "browser": true, 
        "node": true,
        "es6": true
    },
    "extends": [
        "airbnb",
        "plugin:prettier/recommended", 
        "plugin:react/recommended",
        "plugin:jsx-a11y/recommended"
    ],
    "plugins": ["prettier", "react", "react-hooks"],
    "rules": {
        "prettier/prettier": [
            "error",
            {
              "endOfLine": "auto"
            }
        ],
        "react-hooks/exhaustive-deps": "warn",
        "react-hooks/rules-of-hooks": "error",
        "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
        "react/jsx-indent-props": [2, 4],
        "react/jsx-indent": [2, 4],
        "react/jsx-one-expression-per-line": [0],
        "react/prefer-stateless-function": [1],
        "react/static-property-placement": [1, "property assignment"],
        "react/prop-types": "off"
    }
}

I got rid of the same error by setting the prettier rules configuration in .eslintrc to:

"rules": {
        "prettier/prettier": [
            "error",
            {
              "endOfLine": "off"
            }
        ],

while keeping in .prettierrc:

"endOfLine": "auto"

NOTE: This is just an intent to workaround the error you (and I) got, but the effect I see is that the "endOfLine" rule will work when using the pretty formatted but not when running eslint.

You should change semi with false

{
  "printWidth": 100,
  "singleQuote": true,
  "tabWidth": 4,
  "trailingComma": "es5",
  "endOfLine":"auto",
  "semi": false
}

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