@@ -69,9 +69,10 @@ function getShapeProperties(node) {
69
69
* @param {Boolean= } ignoreCase whether or not to ignore case when comparing the two elements.
70
70
* @param {Boolean= } requiredFirst whether or not to sort required elements first.
71
71
* @param {Boolean= } callbacksLast whether or not to sort callbacks after everything else.
72
+ * @param {Boolean= } noSortAlphabetically whether or not to disable alphabetical sorting of the elements.
72
73
* @returns {Number } the sort order of the two elements.
73
74
*/
74
- function sorter ( a , b , context , ignoreCase , requiredFirst , callbacksLast ) {
75
+ function sorter ( a , b , context , ignoreCase , requiredFirst , callbacksLast , noSortAlphabetically ) {
75
76
const aKey = String ( astUtil . getKeyValue ( context , a ) ) ;
76
77
const bKey = String ( astUtil . getKeyValue ( context , b ) ) ;
77
78
@@ -93,15 +94,17 @@ function sorter(a, b, context, ignoreCase, requiredFirst, callbacksLast) {
93
94
}
94
95
}
95
96
96
- if ( ignoreCase ) {
97
- return aKey . localeCompare ( bKey ) ;
98
- }
97
+ if ( ! noSortAlphabetically ) {
98
+ if ( ignoreCase ) {
99
+ return aKey . localeCompare ( bKey ) ;
100
+ }
99
101
100
- if ( aKey < bKey ) {
101
- return - 1 ;
102
- }
103
- if ( aKey > bKey ) {
104
- return 1 ;
102
+ if ( aKey < bKey ) {
103
+ return - 1 ;
104
+ }
105
+ if ( aKey > bKey ) {
106
+ return 1 ;
107
+ }
105
108
}
106
109
return 0 ;
107
110
}
@@ -119,7 +122,16 @@ function sorter(a, b, context, ignoreCase, requiredFirst, callbacksLast) {
119
122
* @returns {Object|*|{range, text} } the sort order of the two elements.
120
123
*/
121
124
const commentnodeMap = new WeakMap ( ) ; // all nodes reference WeakMap for start and end range
122
- function fixPropTypesSort ( fixer , context , declarations , ignoreCase , requiredFirst , callbacksLast , sortShapeProp ) {
125
+ function fixPropTypesSort (
126
+ fixer ,
127
+ context ,
128
+ declarations ,
129
+ ignoreCase ,
130
+ requiredFirst ,
131
+ callbacksLast ,
132
+ noSortAlphabetically ,
133
+ sortShapeProp
134
+ ) {
123
135
function sortInSource ( allNodes , source ) {
124
136
const originalSource = source ;
125
137
const sourceCode = context . getSourceCode ( ) ;
@@ -161,7 +173,7 @@ function fixPropTypesSort(fixer, context, declarations, ignoreCase, requiredFirs
161
173
nodeGroups . forEach ( ( nodes ) => {
162
174
const sortedAttributes = toSorted (
163
175
nodes ,
164
- ( a , b ) => sorter ( a , b , context , ignoreCase , requiredFirst , callbacksLast )
176
+ ( a , b ) => sorter ( a , b , context , ignoreCase , requiredFirst , callbacksLast , noSortAlphabetically )
165
177
) ;
166
178
167
179
source = nodes . reduceRight ( ( acc , attr , index ) => {
0 commit comments