@@ -22,6 +22,14 @@ const ATTRS = {
2222 CONTENT : 'CONTENT'
2323}
2424
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+
2533function getAttributeType ( attribute , sourceCode ) {
2634 const isBind = attribute . directive && attribute . key . name . name === 'bind'
2735 const name = isBind
@@ -64,6 +72,14 @@ function getPosition (attribute, attributePosition, sourceCode) {
6472 return attributePosition . hasOwnProperty ( attributeType ) ? attributePosition [ attributeType ] : - 1
6573}
6674
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+
6783function create ( context ) {
6884 const sourceCode = context . getSourceCode ( )
6985 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) {
110126 previousNode = null
111127 } ,
112128 '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 ) ) {
114134 currentPosition = getPosition ( node , attributePosition , sourceCode )
115135 previousNode = node
116136 } else {
0 commit comments