Skip to content

Commit

Permalink
fix: false positive in quoted-expressions (43081j#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpradelle committed Jul 23, 2024
1 parent 406b902 commit bdad361
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/rules/quoted-expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ const rule: Rule.RuleModule = {
continue;
}

const isQuoted =
const isQuotedForAlwaysQuote =
previousQuasi.value.raw.endsWith('="') ||
previousQuasi.value.raw.endsWith("='");
const isQuotedForNeverQuote =
(previousQuasi.value.raw.endsWith('="') &&
nextQuasi.value.raw.startsWith('"')) ||
(previousQuasi.value.raw.endsWith("='") &&
nextQuasi.value.raw.startsWith("'"));

if (alwaysQuote && !isQuoted) {
if (alwaysQuote && !isQuotedForAlwaysQuote) {
context.report({
node: expression,
messageId: 'alwaysQuote',
Expand All @@ -93,7 +96,7 @@ const rule: Rule.RuleModule = {
});
}

if (!alwaysQuote && isQuoted) {
if (!alwaysQuote && isQuotedForNeverQuote) {
context.report({
node: expression,
messageId: 'neverQuote',
Expand Down
24 changes: 24 additions & 0 deletions src/test/rules/quoted-expressions_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ ruleTester.run('quoted-expressions', rule, {
{
code: "html`<x-foo attr='${v}'></x-foo>`",
options: ['always']
},
{
code: 'html`<x-foo attr="${v} bar"></x-foo>`',
options: ['always']
},
{
code: 'html`<x-foo attr="foo ${v} bar"></x-foo>`',
options: ['always']
},
{
code: 'html`<x-foo attr="foo ${v}${w} bar"></x-foo>`',
options: ['always']
},
{
code: 'html`<x-foo attr="foo ${v} bar ${w} baz"></x-foo>`',
options: ['always']
},
{
code: 'html`<x-foo attr="${v ? "foo" : "bar"} baz"></x-foo>`',
options: ['always']
},
{
code: 'html`<x-foo attr="foo ${v}"></x-foo>`',
options: ['always']
}
],

Expand Down

0 comments on commit bdad361

Please sign in to comment.