Skip to content

Commit

Permalink
fix: replace conditional prop binding with ternary instead of &&
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelWD committed Apr 15, 2024
1 parent 2892491 commit a577bd0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/rules/no-deprecated-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ module.exports = {
return [fixer.replaceText(propNameNode, replace.name), fixer.replaceText(attr.value, `"${value}"`)]
} else {
const expression = context.getSourceCode().getText(attr.value.expression)
return [fixer.replaceText(propNameNode, replace.name), fixer.replaceText(attr.value, `"${expression} && '${value}'"`)]
return [fixer.replaceText(propNameNode, replace.name), fixer.replaceText(attr.value, `"${expression} ? '${value}' : undefined"`)]
}
} else {
return fixer.replaceText(attr, `${replace.bind ? ':' : ''}${replace.name}="${value}"`)
Expand Down
6 changes: 3 additions & 3 deletions tests/rules/no-deprecated-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ tester.run('no-deprecated-props', rule, {
},
{
code: '<template><v-btn :outline="false" /></template>',
output: `<template><v-btn :variant="false && 'outlined'" /></template>`,
output: `<template><v-btn :variant="false ? 'outlined' : undefined" /></template>`,
errors: [{ messageId: 'replacedWith' }],
},
{
code: '<template><v-btn v-bind:outline="false" /></template>',
output: `<template><v-btn v-bind:variant="false && 'outlined'" /></template>`,
output: `<template><v-btn v-bind:variant="false ? 'outlined' : undefined" /></template>`,
errors: [{ messageId: 'replacedWith' }],
},
{
Expand Down Expand Up @@ -73,7 +73,7 @@ tester.run('no-deprecated-props', rule, {
},
{
code: '<template><v-window :vertical="condition" /></template>',
output: `<template><v-window :direction="condition && 'vertical'" /></template>`,
output: `<template><v-window :direction="condition ? 'vertical' : undefined" /></template>`,
errors: [{ messageId: 'replacedWith' }],
},
{
Expand Down

0 comments on commit a577bd0

Please sign in to comment.