skip to Main Content

I have the following eslint configuration:

{
  "env": {
    "es2020": true,
    "jest": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:import/recommended",
    "plugin:import/typescript",
    "plugin:prettier/recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint", "prettier"],
  "settings": {
    "import/resolver": {
      "typescript": true,
      "node": true
    }
  },
  "overrides": [
    {
      "files": ["*.ts", "*.tsx"],
      "parserOptions": {
        "project": ["./tsconfig.json"]
      },
      "rules": {
        "@typescript-eslint/consistent-type-imports": [
          "error",
          {
            "fixStyle": "inline-type-imports"
          }
        ],
        "@typescript-eslint/member-ordering": "error",
        "@typescript-eslint/consistent-type-exports": "error",
        "@typescript-eslint/method-signature-style": "error",
        "@typescript-eslint/prefer-ts-expect-error": "error",
        "@typescript-eslint/consistent-generic-constructors": ["error", "constructor"],
        "@typescript-eslint/consistent-type-definitions": ["error", "type"],
        "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
      }
    }
  ],
  "rules": {
    "indent": "off",
    "max-len": [
      "error",
      {
        "code": 88,
        "ignoreRegExpLiterals": true
      }
    ],
    "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
    "semi": ["error", "always"],
    "arrow-parens": ["error", "as-needed"],
    "prefer-const": ["error"],
    "react/require-default-props": "off",
    "import/order": [
      "error",
      {
        "newlines-between": "always",
        "groups": ["builtin", "external", "parent", "sibling", "index", "type"]
      }
    ]
  }
}

Here is my prettier configuration:

{
  "semi": true,
  "tabWidth": 2,
  "printWidth": 88,
  "singleQuote": true,
  "trailingComma": "none",
  "jsxBracketSameLine": true,
  "endOfLine": "auto",
  "arrowParens": "avoid"
}

I have a file with the following typescript code:

import { createRoot } from 'react-dom/client';

export const mount = (el: HTMLElement) => {
    const root = createRoot(el);
};

I get the following eslint error: Delete ".." eslint(prettier/prettier). I try to delete 2 spaces and the error goes away, but when I format the file spaces are added again and I get the same error.

It looks like there might be conflicting eslint rules somewhere, I’m surprised to see that the error comes from prettier, considering that I configured tabWidth to have a value of 2.

What might be the issue here? Thank you!

2

Answers


  1. It looks like you have a conflict between ESLint and prettier. Probably using the eslint-config-prettier will turn off those Linter rules conflicting with prettier.

    Login or Signup to reply.
  2. I guess you are using incorrect formatter (the builtin Typescript one)

    CtrlShiftP – format document with… – set default formatter – ESLint (or Prettier).
    You should have ESLing formatter enabled in settings, I don’t remember if it’s off by default.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search