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
Disable backtick quotes if it is not a template #838
Comments
NACK, only because it means if I am intermittently using templates, I have more rules to remember or otherwise have |
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 |
it'd be simpler to just disable non-backtick quotes entirely |
@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
|
Yeah personally I use back ticks all the time that way I am always ready to interpolate |
I like having two types of quotes to indicate intent. Interpolating is rare enough that I appreciating having it explicitly called out by the |
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 |
There are also a couple of other arguments against making backtick quotes preferred for all strings:
|
I can see how disabling backticks would fit with Standard's existing philosophy
|
I also think this would make sense, such that
is enforced. Note that the implementation is very simple: Remove the |
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}`) // ✓ ok Only 1 ecosystem package ( I'm going to ship this in v14. |
Lovely! |
And what about this case? console.log(`I'd like to quote someone: "That will force manual escaping on me"`) It seems to be legit, but it's forbidden by the rule. |
@ArmorDarks as you know, Standard's preferred quotes are single quotes. Allowing double quotes when the string contains single quotes is one thing. Because single and double quotes are equal in all ways, as far as I know. Since backticks are a different language feature (inline expression and tags), allowing them in order to avoid escape characters is a different consideration. |
I\'m not sure how I\'m supposed to feel about maintaining sentences like these and being forced to escape manually myself. This rule is quite problematic, because using backticks without any tags or expressions clearly conveys the intent: this is language being displayed to humans. |
@langsri-sha, could you please expand on "this is language being displayed to humans"? I don't quite understand what "language" means here. The string? |
@mightyiam here are a few instances where I use backticks because the string is something that's communicated directly to humans:
So was able to keep things neat and tidy with just single quotes and backticks. Now there's mixed use of single quotes, double quotes, escape sequences and backticks 😬! |
@langri-sha what do you mean by "communicated directly to humans", please? You mean, while those humans are reading the code? Or by test failure messages, error messages and debug logs? |
By this I mean strings that are used to express written language. The case the OP makes with:
☝️ I see this more as "I have a problem that I can express strings in two different ways", but I don't think this sufficiently accounts for written language, like this paragraph that I just writing. As I said, we've moved from a consistent use of single quotes and backticks to mixed use of single quotes, double quotes, escape sequences and backticks. |
@langri-sha thank you for the explanation. I understand what you mean now. Personally, it's a non-issue for me. If you have a suggestion, could you please open a new issue with that? |
…res are not used Fixes: standard/standard#838 Fixes: standard/eslint-config-standard#151
Now you could write either
or
And it would pass
standard
linter 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.
The text was updated successfully, but these errors were encountered: