Skip to content

Commit

Permalink
Fix false negatives for v-bind="object" in vue/attributes-order rule (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Feb 14, 2021
1 parent 5129cef commit b978258
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 8 deletions.
8 changes: 0 additions & 8 deletions lib/rules/attributes-order.js
Expand Up @@ -344,14 +344,6 @@ function create(context) {
return getPositionFromAttrIndex(nextIndex)
}
}
for (let prevIndex = index - 1; prevIndex >= 0; prevIndex--) {
const prev = attributes[prevIndex]

if (isVAttributeOrVBind(prev) && !isVBindObject(prev)) {
// It is considered to be in the same order as the prev bind prop node.
return getPositionFromAttrIndex(prevIndex)
}
}
}
return getPosition(node, attributePosition)
}
Expand Down
129 changes: 129 additions & 0 deletions tests/lib/rules/attributes-order.js
Expand Up @@ -21,6 +21,29 @@ const tester = new RuleTester({
})
tester.run('attributes-order', rule, {
valid: [
{
// https://github.com/vuejs/eslint-plugin-vue/issues/1433
filename: 'test.vue',
code: `
<template>
<div
ref="ref"
v-model="model"
v-bind="object"
@click="handleClick"/>
</template>`
},
{
filename: 'test.vue',
code: `
<template>
<div
v-bind="object"
ref="ref"
v-model="model"
@click="handleClick"/>
</template>`
},
{
filename: 'test.vue',
code: '<template><div></div></template>'
Expand Down Expand Up @@ -1334,6 +1357,112 @@ tester.run('attributes-order', rule, {
message: 'Attribute "ref" should go before "bar".'
}
]
},

{
filename: 'test.vue',
code: `
<template>
<div
v-bind="object"
v-if="show"
v-model="model"
ref="ref"
@click="handleClick"/>
</template>`,
output: `
<template>
<div
v-if="show"
v-bind="object"
ref="ref"
v-model="model"
@click="handleClick"/>
</template>`,
errors: [
'Attribute "v-if" should go before "v-bind".',
'Attribute "ref" should go before "v-model".'
]
},

{
filename: 'test.vue',
code: `
<template>
<div
@click="handleClick"
v-bind="object"/>
</template>`,
output: `
<template>
<div
v-bind="object"
@click="handleClick"/>
</template>`,
errors: ['Attribute "v-bind" should go before "@click".']
},

{
filename: 'test.vue',
code: `
<template>
<div
ref="ref"
@click="handleClick"
v-bind="object"
@input="handleInput"/>
</template>`,
output: `
<template>
<div
ref="ref"
v-bind="object"
@click="handleClick"
@input="handleInput"/>
</template>`,
errors: ['Attribute "v-bind" should go before "@click".']
},

{
filename: 'test.vue',
code: `
<template>
<div
ref="ref"
@click="handleClick"
v-bind="object"
@input="handleInput"/>
</template>`,
options: [{ order: ['UNIQUE', 'EVENTS', 'OTHER_ATTR'] }],
output: `
<template>
<div
ref="ref"
@click="handleClick"
@input="handleInput"
v-bind="object"/>
</template>`,
errors: ['Attribute "@input" should go before "v-bind".']
},

{
filename: 'test.vue',
code: `
<template>
<div
v-bind="object"
@click="handleClick"
attr="foo"/>
</template>`,
options: [{ order: ['UNIQUE', 'EVENTS', 'OTHER_ATTR'] }],
output: `
<template>
<div
@click="handleClick"
v-bind="object"
attr="foo"/>
</template>`,
errors: ['Attribute "@click" should go before "v-bind".']
}
]
})

0 comments on commit b978258

Please sign in to comment.