From b978258b616da35283d9757074037fb030dbe428 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sun, 14 Feb 2021 09:40:49 +0900 Subject: [PATCH] Fix false negatives for v-bind="object" in vue/attributes-order rule (#1434) --- lib/rules/attributes-order.js | 8 -- tests/lib/rules/attributes-order.js | 129 ++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 8 deletions(-) diff --git a/lib/rules/attributes-order.js b/lib/rules/attributes-order.js index 8e618ebac..8f2917dd7 100644 --- a/lib/rules/attributes-order.js +++ b/lib/rules/attributes-order.js @@ -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) } diff --git a/tests/lib/rules/attributes-order.js b/tests/lib/rules/attributes-order.js index 15ccccae0..c956dae8d 100644 --- a/tests/lib/rules/attributes-order.js +++ b/tests/lib/rules/attributes-order.js @@ -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: ` + ` + }, + { + filename: 'test.vue', + code: ` + ` + }, { filename: 'test.vue', code: '' @@ -1334,6 +1357,112 @@ tester.run('attributes-order', rule, { message: 'Attribute "ref" should go before "bar".' } ] + }, + + { + filename: 'test.vue', + code: ` + `, + output: ` + `, + errors: [ + 'Attribute "v-if" should go before "v-bind".', + 'Attribute "ref" should go before "v-model".' + ] + }, + + { + filename: 'test.vue', + code: ` + `, + output: ` + `, + errors: ['Attribute "v-bind" should go before "@click".'] + }, + + { + filename: 'test.vue', + code: ` + `, + output: ` + `, + errors: ['Attribute "v-bind" should go before "@click".'] + }, + + { + filename: 'test.vue', + code: ` + `, + options: [{ order: ['UNIQUE', 'EVENTS', 'OTHER_ATTR'] }], + output: ` + `, + errors: ['Attribute "@input" should go before "v-bind".'] + }, + + { + filename: 'test.vue', + code: ` + `, + options: [{ order: ['UNIQUE', 'EVENTS', 'OTHER_ATTR'] }], + output: ` + `, + errors: ['Attribute "@click" should go before "v-bind".'] } ] })