diff --git a/lib/rules/attributes-order.js b/lib/rules/attributes-order.js index 1808d3817..5aac15b63 100644 --- a/lib/rules/attributes-order.js +++ b/lib/rules/attributes-order.js @@ -8,6 +8,19 @@ const utils = require('../utils') // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ +const ATTRS = { + DEFINITION: 'DEFINITION', + LIST_RENDERING: 'LIST_RENDERING', + CONDITIONALS: 'CONDITIONALS', + RENDER_MODIFIERS: 'RENDER_MODIFIERS', + GLOBAL: 'GLOBAL', + UNIQUE: 'UNIQUE', + TWO_WAY_BINDING: 'TWO_WAY_BINDING', + OTHER_DIRECTIVES: 'OTHER_DIRECTIVES', + OTHER_ATTR: 'OTHER_ATTR', + EVENTS: 'EVENTS', + CONTENT: 'CONTENT', +}; function getAttributeType (attribute, sourceCode) { const isBind = attribute.directive && attribute.key.name.name === 'bind' @@ -17,31 +30,31 @@ function getAttributeType (attribute, sourceCode) { if (attribute.directive && !isBind) { if (name === 'for') { - return 'LIST_RENDERING' + return ATTRS.LIST_RENDERING } else if (name === 'if' || name === 'else-if' || name === 'else' || name === 'show' || name === 'cloak') { - return 'CONDITIONALS' + return ATTRS.CONDITIONALS } else if (name === 'pre' || name === 'once') { - return 'RENDER_MODIFIERS' + return ATTRS.RENDER_MODIFIERS } else if (name === 'model') { - return 'TWO_WAY_BINDING' + return ATTRS.TWO_WAY_BINDING } else if (name === 'on') { - return 'EVENTS' + return ATTRS.EVENTS } else if (name === 'html' || name === 'text') { - return 'CONTENT' + return ATTRS.CONTENT } else if (name === 'slot') { - return 'UNIQUE' + return ATTRS.UNIQUE } else { - return 'OTHER_DIRECTIVES' + return ATTRS.OTHER_DIRECTIVES } } else { if (name === 'is') { - return 'DEFINITION' + return ATTRS.DEFINITION } else if (name === 'id') { - return 'GLOBAL' + return ATTRS.GLOBAL } else if (name === 'ref' || name === 'key' || name === 'slot' || name === 'slot-scope') { - return 'UNIQUE' + return ATTRS.UNIQUE } else { - return 'OTHER_ATTR' + return ATTRS.OTHER_ATTR } } } @@ -53,7 +66,7 @@ function getPosition (attribute, attributePosition, sourceCode) { function create (context) { const sourceCode = context.getSourceCode() - let attributeOrder = ['DEFINITION', 'LIST_RENDERING', 'CONDITIONALS', 'RENDER_MODIFIERS', 'GLOBAL', 'UNIQUE', 'TWO_WAY_BINDING', 'OTHER_DIRECTIVES', 'OTHER_ATTR', 'EVENTS', 'CONTENT'] + let attributeOrder = [ATTRS.DEFINITION, ATTRS.LIST_RENDERING, ATTRS.CONDITIONALS, ATTRS.RENDER_MODIFIERS, ATTRS.GLOBAL, ATTRS.UNIQUE, ATTRS.TWO_WAY_BINDING, ATTRS.OTHER_DIRECTIVES, ATTRS.OTHER_ATTR, ATTRS.EVENTS, ATTRS.CONTENT] if (context.options[0] && context.options[0].order) { attributeOrder = context.options[0].order }