Reputation: 213
I need to use only signleQuote and backTick in the eslint .
These are my codes in the json file :
"rulse":{
"quotes": "error",
"jsx-quotes": [2, "prefer-single"]
}
Upvotes: 1
Views: 2028
Reputation: 11972
As of 2025, the accepted answer does not work anymore.
It should be instead
// eslint: ^9.17.0
"rules": {
"quotes": ["error", "single", {
// Allow "a 'string' with single quotes" corner case:
"avoidEscape": true,
// Allow `backticks for template ${strings}` only:
"allowTemplateLiterals": true
}]
}
Or, better yet, use @stylistic/eslint-plugin-js
, since eslint formatting rules are deprecated now:
// @stylistic/eslint-plugin-js: ^2.12.1
"rules": {
"@stylistic/js/quotes": ["error", "single", {
"avoidEscape": true,
"allowTemplateLiterals": true
}]
}
Edit: by the way, with @stylistic
you don't need separate rules for pure-js vs JSX (like the OP did). The same set of rules may apply to javascript, typescript and React JSX. But you can also keep them separated, if you really want to. More information in @stylistic
's migration guide.
Upvotes: 1
Reputation: 10391
There is a misspelling and you must tell eslint what quotes to use:
"rules": {
"quotes": ["error", "single", "avoid-escape"]
}
Upvotes: 3