0

I am using intellij and I have started a react typescript project with vite, have added eslint and prettier, as well as lint-staged. After initially having single quotes for everything I wanted to configure double quotes for jsx. I have set up the prettier config file like this:

{
  "semi": false,
  "tabWidth": 2,
  "printWidth": 100,
  "singleQuote": true,
  "trailingComma": "all",
  "bracketSpacing": true,
  "plugins": [
    "prettier-plugin-tailwindcss"
  ]
}

And the eslintrc.json file looks like this:

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:react/recommended",
    "prettier"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": [
    "react",
    "react-hooks",
    "@typescript-eslint",
    "prettier"
  ],
  "rules": {
    "react/react-in-jsx-scope": "off",
    "camelcase": "error",
    "spaced-comment": "error",
    "jsx-quotes": [
      "error",
      "prefer-double"
    ],
    "quotes": [
      "error",
      "single"
    ],
    "no-duplicate-imports": "error"
  },
  "settings": {
    "import/resolver": {
      "typescript": {}
    }
  }
}

But, whenever I save or run reformat code in intellij with double quotes it reformats it back to single quotes, like this line in my App.tsx:

<div className='p-2 bg-blue-500 text-white'>

In package.json file I have this scripts:

  "lint-staged": {
    "src/**/*.{js,jsx,ts,tsx,css,md,json}": "npm run format --",
    "*.{js,jsx,ts,tsx,json}": "npm run lint:fix --"
  },
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "lint": "eslint . --ext 'src/**/*.{js,jsx,ts,tsx,json}' --report-unused-disable-directives --max-warnings 0",
    "lint:fix": "eslint --fix 'src/**/*.{js,jsx,ts,tsx,json}'",
    "format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
    "preview": "vite preview",
    "prepare": "husky install"
  },

If I run prettier script code is correctly formatted to double quotes. It seems like Intellij has a wrong setup for some reason. I have tried to invalidated caches and restart it, but it is always the same thing if I save something in the editor it is reformatted to single quotes again. How can I fix this?

Leff
  • 1,968
  • 24
  • 97
  • 201
  • Your prettier config specifies single quotes, while your eslint config specifies double. I don't know which one IntelliJ cares about, but removing that line from the prettierrc may help. – Zac Anger Jul 23 '23 at 23:17
  • @ZacAnger https://prettier.io/docs/en/options.html says for quotes options - JSX quotes ignore this option. Besides if that option was the problem then running the package script wouldn't work either. – Leff Jul 24 '23 at 08:45

1 Answers1

0

The issue is tracked at WEB-50619, please vote for it to get notified on any progress

lena
  • 90,154
  • 11
  • 145
  • 150