question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

enhance "quotes" fixer to take "avoidEscape" into consideration

See original GitHub issue

What 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

closes https://github.com/standard/standard/issues/1380

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ferosscommented, Aug 22, 2019

Makes sense, but the proposed change in #10627 is no error reported

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.

1reaction
ferosscommented, Aug 22, 2019

@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 code

console.log(`'a.txt' exists`)

to this

console.log("'a.txt' exists")

rather than to this

console.log('\'a.txt\' exists')

Does that make sense?

Read more comments on GitHub >

github_iconTop Results From Across the Web

25 Inspirational Business Process Improvement Quotes
“Without continual growth and progress, such words as improvement, achievement, and success have no meaning. “ ​–​ Benjamin Franklin. “Most ...
Read more >
How to tell eslint that you prefer single quotes around your ...
I'm new to eslint and it's spewing out a ton of errors telling me to use doublequotes:
Read more >
Top 20+ Safety Quotes To Improve Your Safety Culture
Develop a strong safety culture in your organization today. Start by encouraging employees and managers with these quotable safety quotes.
Read more >
117 Leadership Quotes for Inspiration - Brian Tracy
True leadership is about striving to become better in all areas of life and empowering everyone around you to become the best versions...
Read more >
quotes - ESLint - Pluggable JavaScript Linter
Each of these lines creates a string and, in some cases, ... "avoidEscape": true allows strings to use single-quotes or double-quotes so long...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found