diff --git a/docs/rules/attributes-order.md b/docs/rules/attributes-order.md index e7b9a6209..a3f2e5116 100644 --- a/docs/rules/attributes-order.md +++ b/docs/rules/attributes-order.md @@ -90,7 +90,16 @@ Specify custom order of attribute groups :+1: Examples of **correct** code with custom order`: ```html - + +
+
+``` + +```html +
{ + if (item instanceof Array) { + item.forEach((attr) => { + attributePosition[attr] = i + }) + } else attributePosition[item] = i + }) let currentPosition let previousNode @@ -101,8 +106,8 @@ function create (context) { previousNode = null }, 'VAttribute' (node) { - if ((currentPosition === -1) || (currentPosition <= getPosition(node, attributeOrder))) { - currentPosition = getPosition(node, attributeOrder) + if ((currentPosition === -1) || (currentPosition <= getPosition(node, attributePosition))) { + currentPosition = getPosition(node, attributePosition) previousNode = node } else { reportIssue(node, previousNode) diff --git a/tests/lib/rules/attributes-order.js b/tests/lib/rules/attributes-order.js index ece0b262a..d36294411 100644 --- a/tests/lib/rules/attributes-order.js +++ b/tests/lib/rules/attributes-order.js @@ -249,6 +249,33 @@ tester.run('attributes-order', rule, { 'OTHER_DIRECTIVES' ] }] + }, + { + filename: 'test.vue', + code: + ``, + options: [ + { order: + [ + 'CONDITIONALS', + 'LIST_RENDERING', + 'RENDER_MODIFIERS', + 'DEFINITION', + 'EVENTS', + 'UNIQUE', + ['BINDING', 'OTHER_ATTR'], + 'CONTENT', + 'GLOBAL' + ] + }] } ], @@ -515,6 +542,48 @@ tester.run('attributes-order', rule, { nodeType: 'VIdentifier' } ] + }, + { + code: + ``, + options: [ + { order: + [ + 'CONDITIONALS', + 'LIST_RENDERING', + 'RENDER_MODIFIERS', + 'DEFINITION', + 'EVENTS', + 'UNIQUE', + ['BINDING', 'OTHER_ATTR'], + 'CONTENT', + 'GLOBAL' + ] + }], + output: + ``, + errors: [ + { + message: 'Attribute "v-if" should go before "class".', + nodeType: 'VIdentifier' + } + ] } ] })