Skip to content

Commit

Permalink
fix(no-useless-v-bind): remove spaces around string in fixes (#2408)
Browse files Browse the repository at this point in the history
Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
  • Loading branch information
claneo and FloEdelmann authored Feb 23, 2024
1 parent 0fb68b3 commit 8a781f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rules/no-useless-v-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ module.exports = {
let attrValue
if (quoteChar === '"') {
attrValue = strValue.replace(DOUBLE_QUOTES_RE, '&quot;')
attrValue = quoteChar + attrValue + quoteChar
} else if (quoteChar === "'") {
attrValue = strValue.replace(SINGLE_QUOTES_RE, '&apos;')
attrValue = quoteChar + attrValue + quoteChar
} else {
attrValue = strValue
.replace(DOUBLE_QUOTES_RE, '&quot;')
.replace(SINGLE_QUOTES_RE, '&apos;')
}
yield fixer.replaceText(expression, attrValue)
yield fixer.replaceText(value, attrValue)
}
})
}
Expand Down
28 changes: 28 additions & 0 deletions tests/lib/rules/no-useless-v-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,34 @@ tester.run('no-useless-v-bind', rule, {
'Unexpected `v-bind` with a string literal value.',
'Unexpected `v-bind` with a string literal value.'
]
},
{
code: `
<template>
<div :id=" 'foo' " />
<div :id=' "foo" ' />
<div :id=" \`foo\` " />
<div :id=' \`foo\` ' />
<div :id="' \\'foo\\' '" />
<div :id='" \\"foo\\" "' />
</template>`,
output: `
<template>
<div id="foo" />
<div id='foo' />
<div id="foo" />
<div id='foo' />
<div id=" 'foo' " />
<div id=' "foo" ' />
</template>`,
errors: [
'Unexpected `v-bind` with a string literal value.',
'Unexpected `v-bind` with a string literal value.',
'Unexpected `v-bind` with a string literal value.',
'Unexpected `v-bind` with a string literal value.',
'Unexpected `v-bind` with a string literal value.',
'Unexpected `v-bind` with a string literal value.'
]
}
]
})

0 comments on commit 8a781f0

Please sign in to comment.