@@ -22,6 +22,14 @@ const ATTRS = {
22
22
CONTENT : 'CONTENT'
23
23
}
24
24
25
+ function getAttributeName ( attribute , sourceCode ) {
26
+ const isBind = attribute . directive && attribute . key . name . name === 'bind'
27
+ debugger
28
+ return isBind
29
+ ? ( attribute . key . argument ? sourceCode . getText ( attribute . key . argument ) : '' )
30
+ : ( attribute . directive ? sourceCode . getText ( attribute . key . argument ) : attribute . key . name )
31
+ }
32
+
25
33
function getAttributeType ( attribute , sourceCode ) {
26
34
const isBind = attribute . directive && attribute . key . name . name === 'bind'
27
35
const name = isBind
@@ -64,6 +72,14 @@ function getPosition (attribute, attributePosition, sourceCode) {
64
72
return attributePosition . hasOwnProperty ( attributeType ) ? attributePosition [ attributeType ] : - 1
65
73
}
66
74
75
+ function isAlphabetical ( prevNode , currNode , sourceCode ) {
76
+ const isSameType = getAttributeType ( prevNode , sourceCode ) === getAttributeType ( currNode , sourceCode )
77
+ if ( isSameType ) {
78
+ return getAttributeName ( prevNode , sourceCode ) < getAttributeName ( currNode , sourceCode )
79
+ }
80
+ return true
81
+ }
82
+
67
83
function create ( context ) {
68
84
const sourceCode = context . getSourceCode ( )
69
85
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 ]
@@ -110,7 +126,11 @@ function create (context) {
110
126
previousNode = null
111
127
} ,
112
128
'VAttribute' ( node ) {
113
- if ( ( currentPosition === - 1 ) || ( currentPosition <= getPosition ( node , attributePosition , sourceCode ) ) ) {
129
+ let inAlphaOrder = true
130
+ if ( currentPosition !== - 1 && ( context . options [ 0 ] && context . options [ 0 ] . alphabetical ) ) {
131
+ inAlphaOrder = isAlphabetical ( previousNode , node , sourceCode )
132
+ }
133
+ if ( ( currentPosition === - 1 ) || ( ( currentPosition <= getPosition ( node , attributePosition , sourceCode ) ) && inAlphaOrder ) ) {
114
134
currentPosition = getPosition ( node , attributePosition , sourceCode )
115
135
previousNode = node
116
136
} else {
0 commit comments