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 upDisable backtick quotes if it is not a template #838
Comments
This comment has been minimized.
This comment has been minimized.
|
NACK, only because it means if I am intermittently using templates, I have more rules to remember or otherwise have |
This comment has been minimized.
This comment has been minimized.
|
I don't mind this, it'd warn for weird mixing stuff like: var a = `hello` + ' my ' + `brethren`Standard would tell you that you probably meant to either use single quotes or interpolate, but definitely not the weird thing right there above. I feel that this would indeed be in the spirit of our current approach to #791. There's a default way to do things, and we warn if people are deviating from it without there being a need to. note: I don't really mind whatever way it goes, just like - feel it's consistent with the ruleset we've been applying so far. edit: Also consider this: var foo = 'hello people' // ✓
var bar = `nope, or dope? who knows` // ✓
var baz = "vinegar sauce" // 𝗑 - not sure why |
yoshuawuyts
added
the
enhancement
label
Apr 5, 2017
This comment has been minimized.
This comment has been minimized.
|
it'd be simpler to just disable non-backtick quotes entirely |
This comment has been minimized.
This comment has been minimized.
|
@dcousens In this case it would be necessary to update README.md and consequently the front page of https://standardjs.com , as they both mandate to use
|
This comment has been minimized.
This comment has been minimized.
skbolton
commented
Apr 6, 2017
|
Yeah personally I use back ticks all the time that way I am always ready to interpolate |
This comment has been minimized.
This comment has been minimized.
I like having two types of quotes to indicate intent. Interpolating is rare enough that I appreciating having it explicitly called out by the |
This comment has been minimized.
This comment has been minimized.
skbolton
commented
Apr 7, 2017
•
|
Well really there is no harm leaving a template string as an un-interpolated string. Yeah normally it means that you are going to interpolate but I think it would be weird to have that as a rule |
This comment has been minimized.
This comment has been minimized.
|
There are also a couple of other arguments against making backtick quotes preferred for all strings:
|
This comment has been minimized.
This comment has been minimized.
blgm
commented
Oct 12, 2017
|
I can see how disabling backticks would fit with Standard's existing philosophy
|
This comment has been minimized.
This comment has been minimized.
romanzoller
commented
Oct 12, 2017
|
I also think this would make sense, such that
is enforced. Note that the implementation is very simple: Remove the |
This comment has been minimized.
This comment has been minimized.
feross
added this to the standard v14 milestone
Jul 27, 2019
This comment has been minimized.
This comment has been minimized.
|
Thanks for the input everyone! I think that we should disallow template literals when placeholders or tagged template features are not used. console.log('hello there') // ✓ ok
console.log("hello there") // ✗ avoid
console.log(`hello there`) // ✗ avoid
$("<div class='box'>") // ✓ ok
console.log(`hello ${name}`) // ✓ okOnly 1 ecosystem package ( I'm going to ship this in v14. |
feross
closed this
in
c003b84
Jul 27, 2019
This comment has been minimized.
This comment has been minimized.
|
Lovely! |
a-rodin commentedApr 5, 2017
•
edited
Now you could write either
or
And it would pass
standardlinter for both cases, even if in the second case the template doesn't have any interpolated variables and in fact is just a different form of a string. So you could mix both forms, something conceptually similar to mixing"and'quotes.ESLint allows us to prevent this behavior by adding a rule
This rule makes ESLint to throw an error for this
but don't throw any errors for this
Also see this issue in ESLint.