Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false negatives for v-bind="object" in vue/attributes-order rule #1434

Merged
merged 1 commit into from Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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".']
}
]
})