0

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"
      }
    }
  ]
}
Ana Tarrisse
  • 1
  • 1
  • 3

1 Answers1

0

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"
],
Anton Bks
  • 482
  • 3
  • 10
  • Hi @anton-bks, thanks for the reply. I tried cleaning up prettier from the linter config but it didn't fix it :/ – Ana Tarrisse Aug 23 '21 at 11:58
  • I think vscode might be applying its own default linting rules. Take a look at https://stackoverflow.com/questions/50823743/disable-tslint-in-vscode/51561618 to try and disable it maybe – Anton Bks Sep 02 '21 at 11:47
  • I'm extending them and even so it still has conflicts. – SalahAdDin Jun 18 '22 at 14:48