Skip to content

Commit 8a781f0

Browse files
claneoFloEdelmann
andauthored
fix(no-useless-v-bind): remove spaces around string in fixes (#2408)
Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
1 parent 0fb68b3 commit 8a781f0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/rules/no-useless-v-bind.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ module.exports = {
132132
let attrValue
133133
if (quoteChar === '"') {
134134
attrValue = strValue.replace(DOUBLE_QUOTES_RE, '&quot;')
135+
attrValue = quoteChar + attrValue + quoteChar
135136
} else if (quoteChar === "'") {
136137
attrValue = strValue.replace(SINGLE_QUOTES_RE, '&apos;')
138+
attrValue = quoteChar + attrValue + quoteChar
137139
} else {
138140
attrValue = strValue
139141
.replace(DOUBLE_QUOTES_RE, '&quot;')
140142
.replace(SINGLE_QUOTES_RE, '&apos;')
141143
}
142-
yield fixer.replaceText(expression, attrValue)
144+
yield fixer.replaceText(value, attrValue)
143145
}
144146
})
145147
}

tests/lib/rules/no-useless-v-bind.js

+28
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,34 @@ tester.run('no-useless-v-bind', rule, {
136136
'Unexpected `v-bind` with a string literal value.',
137137
'Unexpected `v-bind` with a string literal value.'
138138
]
139+
},
140+
{
141+
code: `
142+
<template>
143+
<div :id=" 'foo' " />
144+
<div :id=' "foo" ' />
145+
<div :id=" \`foo\` " />
146+
<div :id=' \`foo\` ' />
147+
<div :id="' \\'foo\\' '" />
148+
<div :id='" \\"foo\\" "' />
149+
</template>`,
150+
output: `
151+
<template>
152+
<div id="foo" />
153+
<div id='foo' />
154+
<div id="foo" />
155+
<div id='foo' />
156+
<div id=" 'foo' " />
157+
<div id=' "foo" ' />
158+
</template>`,
159+
errors: [
160+
'Unexpected `v-bind` with a string literal value.',
161+
'Unexpected `v-bind` with a string literal value.',
162+
'Unexpected `v-bind` with a string literal value.',
163+
'Unexpected `v-bind` with a string literal value.',
164+
'Unexpected `v-bind` with a string literal value.',
165+
'Unexpected `v-bind` with a string literal value.'
166+
]
139167
}
140168
]
141169
})

0 commit comments

Comments
 (0)