@@ -21,6 +21,25 @@ function isDependencyArrayHook(node) {
21
21
/** @type {import('eslint').Rule.RuleModule } */
22
22
module . exports = {
23
23
create ( context ) {
24
+ function getSortableNameFromNode ( node ) {
25
+ if ( ! node ) return '' ;
26
+
27
+ switch ( node . type ) {
28
+ case 'Identifier' :
29
+ return node . name ;
30
+ case 'MemberExpression' :
31
+ // For chained expressions, e.g., `a.b.c`, we'll return `a.b.c`
32
+ return (
33
+ getSortableNameFromNode ( node . object ) +
34
+ '.' +
35
+ getSortableNameFromNode ( node . property )
36
+ ) ;
37
+ default :
38
+ // For any other types or for simplicity, you could just stringify the node.
39
+ return context . getSourceCode ( ) . getText ( node ) ;
40
+ }
41
+ }
42
+
24
43
return {
25
44
CallExpression ( node ) {
26
45
if ( isDependencyArrayHook ( node . callee ) ) {
@@ -33,12 +52,19 @@ module.exports = {
33
52
) {
34
53
const currentDependencies = [ ...dependencies . elements ] ;
35
54
const currentNames = currentDependencies . map (
36
- ( item ) => item . name
55
+ getSortableNameFromNode
37
56
) ;
38
57
39
- const sortedDependencies = [
40
- ...dependencies . elements ,
41
- ] . sort ( ( a , b ) => ( a . name < b . name ? - 1 : 1 ) ) ;
58
+ const sortedDependencies = [ ...dependencies . elements ]
59
+ . map ( ( n ) => ( {
60
+ ...n ,
61
+ name : getSortableNameFromNode ( n ) ,
62
+ } ) )
63
+ . sort ( ( a , b ) =>
64
+ a . name
65
+ . toLowerCase ( )
66
+ . localeCompare ( b . name . toLowerCase ( ) )
67
+ ) ;
42
68
const sortedNames = sortedDependencies . map (
43
69
( item ) => item . name
44
70
) ;
0 commit comments