Skip to content

Commit af5c4c0

Browse files
aggmoulikota-meshi
andauthored
fix(eslint-plugin-vue): [valid-v-bind-sync] Added Case: when valid is then valid .sync (#1335)
* fix(eslint-plugin-vue): [valid-v-bind-sync] If Valid Is then .sync is Valid Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com> * Formatted Document Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com> * fix: [v-bind-sync] added check for :is bind attribute Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com> * fix: [valid-v-bind-sync] add unit tests for `v-bind:is` Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com> * Update tests/lib/rules/valid-v-bind-sync.js * Update package.json Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
1 parent f1c6789 commit af5c4c0

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

lib/rules/valid-v-bind-sync.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ function maybeNullObjectMemberExpression(node) {
8282
return false
8383
}
8484

85+
function isValidIs(node) {
86+
const { attributes } = node
87+
const isAttribute = attributes.some((attr) => {
88+
// check for `VAttribute`
89+
if (attr.type === 'VAttribute') {
90+
// check for `is` attribute
91+
if (attr.key.type === 'VIdentifier' && attr.key.name === 'is') return true
92+
93+
// check for `:is` `bind` attribute
94+
if (attr.key.type === 'VDirectiveKey' && attr.key.argument.name === 'is')
95+
return true
96+
}
97+
})
98+
return isAttribute
99+
}
100+
85101
// ------------------------------------------------------------------------------
86102
// Rule Definition
87103
// ------------------------------------------------------------------------------
@@ -120,7 +136,7 @@ module.exports = {
120136
const element = node.parent.parent
121137
const name = element.name
122138

123-
if (!isValidElement(element)) {
139+
if (!isValidElement(element) && !isValidIs(node.parent)) {
124140
context.report({
125141
node,
126142
loc: node.loc,

tests/lib/rules/valid-v-bind-sync.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,48 @@ tester.run('valid-v-bind-sync', rule, {
145145
{
146146
filename: 'empty-value.vue',
147147
code: '<template><MyComponent :foo.sync="" /></template>'
148+
},
149+
{
150+
filename: 'test.vue',
151+
code: `
152+
<template>
153+
<table>
154+
<tr is="my-row"
155+
:some-prop.sync="somePropValue"
156+
:some-other-prop.sync="someOtherPropValue">
157+
<td></td>
158+
</tr>
159+
</table>
160+
</template>
161+
`
162+
},
163+
{
164+
filename: 'test.vue',
165+
code: `
166+
<template>
167+
<table>
168+
<tr :is="my-row"
169+
:some-prop.sync="somePropValue"
170+
:some-other-prop.sync="someOtherPropValue">
171+
<td></td>
172+
</tr>
173+
</table>
174+
</template>
175+
`
176+
},
177+
{
178+
filename: 'test.vue',
179+
code: `
180+
<template>
181+
<table>
182+
<tr v-bind:is="myRow"
183+
:some-prop.sync="somePropValue"
184+
:some-other-prop.sync="someOtherPropValue">
185+
<td></td>
186+
</tr>
187+
</table>
188+
</template>
189+
`
148190
}
149191
],
150192
invalid: [

0 commit comments

Comments
 (0)