Skip to content

Commit 390a69b

Browse files
authored
fix: handle template expression in quotes (#336)
* fix: handle template expression in quotes * add comments
1 parent 85fe773 commit 390a69b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/eslint-plugin/lib/rules/quotes.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @typedef { import("../types").RuleModule<[Option]> } RuleModule
1010
*/
1111

12+
const { NodeTypes } = require("es-html-parser");
1213
const { RULE_CATEGORY } = require("../constants");
1314
const { getSourceCode } = require("./utils/source-code");
1415
const { createVisitors } = require("./utils/visitors");
@@ -87,6 +88,13 @@ module.exports = {
8788
if (!attr.value || attr.value.value.includes(expectedQuote)) {
8889
return;
8990
}
91+
/**
92+
* Allow template expression.
93+
* ex: html`<div foo=${foo}></div>`
94+
*/
95+
if (attr.value.parts.some((part) => part.type === NodeTypes.Template)) {
96+
return;
97+
}
9098

9199
if (attr.startWrapper && attr.endWrapper) {
92100
const [opening, closing] = getQuotes(attr);

packages/eslint-plugin/tests/rules/quotes.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ foo">
5454
code: `<img src='?size=50&amp;default=retro'>`,
5555
options: ["single"],
5656
},
57+
{
58+
code: `<img src={{foo}}>`,
59+
languageOptions: {
60+
parserOptions: {
61+
templateEngineSyntax: {
62+
"{{": "}}",
63+
},
64+
},
65+
},
66+
},
5767
],
5868
invalid: [
5969
{
@@ -158,6 +168,11 @@ templateRuleTester.run("[template] quotes", rule, {
158168
{
159169
code: `html\`<div id = "\${foo}">\``,
160170
},
171+
{
172+
code: `
173+
const handler = () => {};
174+
html\`<div onclick=\${handler}></div>\``,
175+
},
161176
],
162177
invalid: [
163178
{

0 commit comments

Comments
 (0)