-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow backtick strings to avoid escaping single or double quotes #421
Comments
I would use back-ticks in the query instead: const sql = 'INSERT INTO `user` (`firstName`, `lastName`) VALUES("Linus", "Unnebäck")' Would that be an option? |
Postgres wants me to use double-quotes for identifier escaping. Also, there could be other occurrences when I want to use both single- and double-quotes in the same string.
Than I'm not following the rules, and also it looks ugly :( |
const sql = "INSERT INTO \"user\" (\"firstName\", \"lastName\") VALUES ('Linus', 'Unnebäck')" |
I've personally used that convention when both " and ' are needed in the string. backticks for strings are allowed by standard. |
@dcousens Is that really better than this though? const sql = 'INSERT INTO "user" ("firstName", "lastName") VALUES (\'Linus\', \'Unnebäck\')' |
Yeah, I think this rule is being overly restrictive. I opened an eslint issue for this before releasing v6: eslint/eslint#5147 Ideally we could enforce this:
There's an ongoing discussion about this and related issues here: eslint/eslint#5234 Weigh in there if you have opinions. |
We should be able to work around this now: eslint/eslint#5661 |
This rule change (always allowing template literal strings) will be included in standard v8. |
Does that rule do this ^ ? |
No, the rule just always allows template literal strings. So, it's not perfect. |
Ah ok, reasonable enough |
I just encountered an interesting situation in which I have to use both single quotes
'
and double-quotes"
in the same string. I decided that the easiest would be to wrap them in back-ticks ```.This is however not acceptable by standard since "Strings must use singlequote.". But the rules on the front page clearly states that it okay when it is to avoid escaping:
Therefor I would consider this a bug, any thoughts?
The text was updated successfully, but these errors were encountered: