简体   繁体   中英

Linter: "Insert `··` eslint(prettier/prettier)" on React + TS + Styled Components

I'm having trouble with conflicting rules between Eslint and Prettier on React project with TS and Styled Components. VSCode shows the following problem message:

"Insert ·· eslint(prettier/prettier)"

in a .ts file used for styling. Everytime I save the file with the intended indentation, the linter removes the ·· .

How linter is identing

  background-color: ${(props) => {
  if (props.isSideOpen || props.isOverviewOpen)
    return `rgba(${colors.white.rgba}, 1)`;
  return `rgba(${colors.white.rgba}, 0.6)`;
}};

How it should be is identing

  background-color: ${(props) => {
    if (props.isSideOpen || props.isOverviewOpen)
      return `rgba(${colors.white.rgba}, 1)`;
    return `rgba(${colors.white.rgba}, 0.6)`;
  }};

I tried going through the Eslint and Prettier rules but I couldn't find anything that made sense to my current issue.

Any tips?

.eslintrc

{
  "env": {
    "browser": true,
    "node": true,
    "es6": true
  },
  "extends": ["eslint:recommended", "plugin:react/recommended", "prettier"],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 8,
    "sourceType": "module",
    "ecmaFeatures": {
      "classes": true,
      "jsx": true
    }
  },
  "plugins": ["prettier", "react", "import"],
  "rules": {
    "arrow-body-style": "off",
    "no-console": 2,
    "no-empty": "off",
    "no-empty-function": "off",
    "prefer-arrow-callback": 2,
    "prefer-const": 2,
    "prefer-promise-reject-errors": 2,
    "strict": [2, "global"],
    "import/first": "error",
    "import/named": "warn",
    "import/newline-after-import": 1,
    "prettier/prettier": ["error", { "endOfLine": "auto" }],
    "react/prop-types": 0,
    "react/react-in-jsx-scope": 0
  },
  "settings": {
    "react": {
      "version": "16.12.0"
    },
    "import/resolver": {
      "alias": {
        "map": [["@", "./src"]],
        "extensions": [".ts", ".tsx", ".js", ".jsx", ".json"]
      }
    }
  },
  "overrides": [
    {
      "files": ["*.tsx"],
      "rules": {
        "no-undef": "off"
      }
    }
  ]
}

I dont think you need to extend prettier, you only need to put it in the plugins array and then configure the options in rules:

{
"rules": {
  "prettier/prettier": [
  "error",
    {
    "trailingComma": "es5",
    "semi": false,
    "singleQuote": false,
    "printWidth": 120
    }
  ]
},
"plugins": ["@typescript-eslint", "prettier"]
}

(I just copied the interesting bits from an eslintrc im currently using you might want to play with those options)

My extends looks like this

"extends": [
  "plugin:react/recommended",
  "plugin:@typescript-eslint/recommended",
  "prettier/@typescript-eslint"
],

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