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

rule:attrubutes-order moved attributest to constants #951

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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