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?