quotes: 'single'|'double' + allowTemplateLiterals should only allow template literals with interpolation
See original GitHub issueWhat rule do you want to change?
The quotes
rule in combination with { "allowTemplateLiterals": true }
Does this change cause the rule to produce more or fewer warnings?
More warnings
How will the change be implemented? (New option, new default behavior, etc.)?
Please provide some example code that this change will affect:
/*eslint quotes: ["error", "single", { "allowTemplateLiterals": true }]*/
const a = 'foo';
const b = `bar`;
const c = `baz ${42}`;
What does the rule currently do for this code?
The rule currently allows all of these with the given configuration.
What will the rule do after it’s changed?
Per the configuration, single quotes are preferred but template literals are allowed. Ideally, that would mean that single quotes should be used UNLESS string interpolation is used. That is, template literals should be allowed ONLY when there is an ${expression}
within the template literal. If not, then the use of template literals does not add any value, and only results in an inconsistent coding style despite the use of the eslint quotes rule.
In the above example, a
and c
would be allowed, but b
would result in an error (since a template literal is used frivolously without there being any ${}
).
Are you willing to submit a pull request to implement this change?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
@mdjermanovic
{ "allowTemplateLiterals": false }
does the trick, thanks! I agree a redesign of these options (as proposed in #12156) would be nice.That’s how
{ "allowTemplateLiterals": false }
(default) works.quotes
, regardless of the configuration, never disallows these:${expression}
Use case for
{ "allowTemplateLiterals": true }
should be only to allow the use of backticks instead of the other quotes to avoid escaping the preferred quotes:Though, the option allows all template literals, not just those with the preferred quote inside (I believe that wasn’t the intention, but it would be a breaking change now).