Skip to content

Commit

Permalink
rule:attrubutes-order moved attributest to constants (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiiKudriashov authored and ota-meshi committed Dec 26, 2019
1 parent b0a4a26 commit d397635
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions lib/rules/attributes-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
}
}
}
Expand All @@ -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
}
Expand Down

0 comments on commit d397635

Please sign in to comment.