Enforce the use of curly quotes
npm install eslint-plugin-curly-quotes--fix flag on the command line.
--fix flag on the command line. To ignore a specific string:
js
> String.raw{"foo": "bar"}
> `
>
> Or disable the rule for the line:
>
> `js
> const data = '{"foo": "bar"}' // eslint-disable-line curly-quotes/no-straight-quotes
> `
Installation
Install ESLint:
`sh
npm i --save-dev eslint
`
Install eslint-plugin-curly-quotes:
`sh
npm i --save-dev eslint-plugin-curly-quotes
`
Usage
Add eslint-plugin-curly-quotes to the plugins section of your eslint.config.mjs configuration file:
`js
import curlyQuotes from "eslint-plugin-curly-quotes"
export default [
{
plugins: {
"curly-quotes": curlyQuotes,
},
},
]
`
Then add the no-straight-quotes rule to the rules section:
`js
import curlyQuotes from "eslint-plugin-curly-quotes"
export default [
{
plugins: {
"curly-quotes": curlyQuotes,
},
rules: {
"curly-quotes/no-straight-quotes": "warn",
},
},
]
`
You may customize the characters used to replace straight quotes:
`js
import curlyQuotes from "eslint-plugin-curly-quotes"
export default [
{
plugins: {
"curly-quotes": curlyQuotes,
},
rules: {
"curly-quotes/no-straight-quotes": [
"warn",
{
"single-opening": "‘",
"single-closing": "’", // This character is also used to replace apostrophes.
"double-opening": "“",
"double-closing": "”",
"ignored-elements": ["script", "style"], // Straight quotes in these JSX elements are ignored.
"ignored-attributes": ["className", "id", "key", "style"], // Straight quotes in these JSX attributes are ignored.
"ignored-function-calls": [
"document.querySelector",
"document.querySelectorAll",
"Error",
"RegExp", // This also ignores regular expression literals.
], // Straight quotes passed as parameters to these functions are ignored.
"ignored-object-properties": [], // Straight quotes in these object properties are ignored.
},
],
},
},
]
`
Acknowledgements
- Plugin inspired by eslint-plugin-prefer-smart-quotes`