Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow backtick strings to avoid escaping single or double quotes #421
Comments
This comment has been minimized.
This comment has been minimized.
oskarhane
commented
Feb 16, 2016
|
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? |
This comment has been minimized.
This comment has been minimized.
|
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 :( |
This comment has been minimized.
This comment has been minimized.
const sql = "INSERT INTO \"user\" (\"firstName\", \"lastName\") VALUES ('Linus', 'Unnebäck')" |
dcousens
added
the
question
label
Feb 16, 2016
This comment has been minimized.
This comment has been minimized.
|
I've personally used that convention when both " and ' are needed in the string. backticks for strings are allowed by standard. |
This comment has been minimized.
This comment has been minimized.
|
@dcousens Is that really better than this though? const sql = 'INSERT INTO "user" ("firstName", "lastName") VALUES (\'Linus\', \'Unnebäck\')' |
This comment has been minimized.
This comment has been minimized.
|
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. |
feross
changed the title
Strings must use singlequote.
Allow backtick strings to avoid escaping single or double quotes
Feb 19, 2016
feross
added
blocked
enhancement
and removed
question
labels
Feb 19, 2016
This comment has been minimized.
This comment has been minimized.
|
We should be able to work around this now: eslint/eslint#5661 |
feross
removed
the
blocked
label
Apr 14, 2016
This comment has been minimized.
This comment has been minimized.
|
This rule change (always allowing template literal strings) will be included in standard v8. |
This comment has been minimized.
This comment has been minimized.
Does that rule do this ^ ? |
This comment has been minimized.
This comment has been minimized.
No, the rule just always allows template literal strings. So, it's not perfect. |
feross
closed this
in
standard/eslint-config-standard@fcdb4dd
Jul 13, 2016
This comment has been minimized.
This comment has been minimized.
|
Ah ok, reasonable enough |
LinusU commentedFeb 16, 2016
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?