Skip to content

Commit b978258

Browse files
authored
Fix false negatives for v-bind="object" in vue/attributes-order rule (#1434)
1 parent 5129cef commit b978258

File tree

2 files changed

+129
-8
lines changed

2 files changed

+129
-8
lines changed

lib/rules/attributes-order.js

-8
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,6 @@ function create(context) {
344344
return getPositionFromAttrIndex(nextIndex)
345345
}
346346
}
347-
for (let prevIndex = index - 1; prevIndex >= 0; prevIndex--) {
348-
const prev = attributes[prevIndex]
349-
350-
if (isVAttributeOrVBind(prev) && !isVBindObject(prev)) {
351-
// It is considered to be in the same order as the prev bind prop node.
352-
return getPositionFromAttrIndex(prevIndex)
353-
}
354-
}
355347
}
356348
return getPosition(node, attributePosition)
357349
}

tests/lib/rules/attributes-order.js

+129
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ const tester = new RuleTester({
2121
})
2222
tester.run('attributes-order', rule, {
2323
valid: [
24+
{
25+
// https://github.com/vuejs/eslint-plugin-vue/issues/1433
26+
filename: 'test.vue',
27+
code: `
28+
<template>
29+
<div
30+
ref="ref"
31+
v-model="model"
32+
v-bind="object"
33+
@click="handleClick"/>
34+
</template>`
35+
},
36+
{
37+
filename: 'test.vue',
38+
code: `
39+
<template>
40+
<div
41+
v-bind="object"
42+
ref="ref"
43+
v-model="model"
44+
@click="handleClick"/>
45+
</template>`
46+
},
2447
{
2548
filename: 'test.vue',
2649
code: '<template><div></div></template>'
@@ -1334,6 +1357,112 @@ tester.run('attributes-order', rule, {
13341357
message: 'Attribute "ref" should go before "bar".'
13351358
}
13361359
]
1360+
},
1361+
1362+
{
1363+
filename: 'test.vue',
1364+
code: `
1365+
<template>
1366+
<div
1367+
v-bind="object"
1368+
v-if="show"
1369+
v-model="model"
1370+
ref="ref"
1371+
@click="handleClick"/>
1372+
</template>`,
1373+
output: `
1374+
<template>
1375+
<div
1376+
v-if="show"
1377+
v-bind="object"
1378+
ref="ref"
1379+
v-model="model"
1380+
@click="handleClick"/>
1381+
</template>`,
1382+
errors: [
1383+
'Attribute "v-if" should go before "v-bind".',
1384+
'Attribute "ref" should go before "v-model".'
1385+
]
1386+
},
1387+
1388+
{
1389+
filename: 'test.vue',
1390+
code: `
1391+
<template>
1392+
<div
1393+
@click="handleClick"
1394+
v-bind="object"/>
1395+
</template>`,
1396+
output: `
1397+
<template>
1398+
<div
1399+
v-bind="object"
1400+
@click="handleClick"/>
1401+
</template>`,
1402+
errors: ['Attribute "v-bind" should go before "@click".']
1403+
},
1404+
1405+
{
1406+
filename: 'test.vue',
1407+
code: `
1408+
<template>
1409+
<div
1410+
ref="ref"
1411+
@click="handleClick"
1412+
v-bind="object"
1413+
@input="handleInput"/>
1414+
</template>`,
1415+
output: `
1416+
<template>
1417+
<div
1418+
ref="ref"
1419+
v-bind="object"
1420+
@click="handleClick"
1421+
@input="handleInput"/>
1422+
</template>`,
1423+
errors: ['Attribute "v-bind" should go before "@click".']
1424+
},
1425+
1426+
{
1427+
filename: 'test.vue',
1428+
code: `
1429+
<template>
1430+
<div
1431+
ref="ref"
1432+
@click="handleClick"
1433+
v-bind="object"
1434+
@input="handleInput"/>
1435+
</template>`,
1436+
options: [{ order: ['UNIQUE', 'EVENTS', 'OTHER_ATTR'] }],
1437+
output: `
1438+
<template>
1439+
<div
1440+
ref="ref"
1441+
@click="handleClick"
1442+
@input="handleInput"
1443+
v-bind="object"/>
1444+
</template>`,
1445+
errors: ['Attribute "@input" should go before "v-bind".']
1446+
},
1447+
1448+
{
1449+
filename: 'test.vue',
1450+
code: `
1451+
<template>
1452+
<div
1453+
v-bind="object"
1454+
@click="handleClick"
1455+
attr="foo"/>
1456+
</template>`,
1457+
options: [{ order: ['UNIQUE', 'EVENTS', 'OTHER_ATTR'] }],
1458+
output: `
1459+
<template>
1460+
<div
1461+
@click="handleClick"
1462+
v-bind="object"
1463+
attr="foo"/>
1464+
</template>`,
1465+
errors: ['Attribute "@click" should go before "v-bind".']
13371466
}
13381467
]
13391468
})

0 commit comments

Comments
 (0)