I work with EsLint and Prettier in visual code. Everything work well without singlequote and doublequote.
This is my .eslintrc file:
{
"parser": "babel-eslint",
"plugins": ["prettier"],
"rules": {
"prettier/prettier": [
"error",
{
"singleQuote": true
}
]
}
}
When I use ctr+ shift+P and type "format Document". the double quote didn't change to single quote. If I use autofix, it changes but when I save it, the single quote turn into double quote.
How can I fix that problem.
To remove double quotes just from the beginning and end of the String, we can use a more specific regular expression: String result = input. replaceAll("^\"|\"$", ""); After executing this example, occurrences of double quotes at the beginning or at end of the String will be replaced by empty strings.
As you already have singleQuote: true
set in your prettier config, I suspect that you're seeing your single quotes converted to double quotes specifically inside your JSX tags. This is because Prettier has a separate rule for JSX:
"jsxSingleQuote": true
Without this, even with "singleQuote": true
, Prettier will still convert single quotes within JSX to double.
According to Prettier, double quotes in JSX is the default because it's descended from HTML, where double quotes are more common.
Set "jsxSingleQuote": true
wherever you have your Prettier config, and that should do the trick.
This only happens if you have '
in your string e.g. ('it\'s a thing').
Prettier has this issue and there is apparently no solution to this.
My workaround is, using `` (string template syntax) for such strings and single quote for all other strings.
`it's a thing`
You don't have to escape this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With