enhance "quotes" fixer to take "avoidEscape" into consideration
See original GitHub issueWhat rule do you want to change?
eslint --fix
rewrote my template strings (containing single quotes) into single quote strings (containing escaped single quotes) despite the fact that the avoidEscape
setting was true.
I’d like to enhance the fixer function for https://eslint.org/docs/rules/quotes to take the avoidEscape
setting into account when converting quotes from backtick to single quotes.
Does this change cause the rule to produce more or fewer warnings? exactly the same
How will the change be implemented? (New option, new default behavior, etc.)?
I would modify this function to have a second argument, avoidEscape
:
https://github.com/eslint/eslint/blob/4aeeeedb656ee3519ea82ebf0cb41ca801215046/lib/rules/quotes.js#L48-L69
Please provide some example code that this change will affect:
e.g. with these rules:
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": false }],
and this code
console.log(`'a.txt' exists`)
running eslint --fix
would generate the following:
console.log("'a.txt' exists")
What does the rule currently do for this code? currently the fixer generates this:
console.log('\'a.txt\' exists')
which is technically correct but not as nice
What will the rule do after it’s changed? rule is same, only fixer changes
Are you willing to submit a pull request to implement this change? yup
Note: kinda related to https://github.com/eslint/eslint/issues/10627
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (5 by maintainers)
I see. The reason I though this was unrelated is that we specify
"allowTemplateLiterals": false
and also"avoidEscape": true
so there’s no ambiguity about what type of quotes we prefer to be used to avoid escaping.@mdjermanovic I don’t see how the proposed change in this issue is incompatible with #10627.
If I understand correctly, this issue is proposing that when the rule
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": false }]
is in effect, ESLint should prefer correcting this invalid codeto this
rather than to this
Does that make sense?