@@ -22,6 +22,13 @@ var expectedError = {
22
22
message : 'Props should be sorted alphabetically' ,
23
23
type : 'JSXAttribute'
24
24
} ;
25
+ var expectedCallbackError = {
26
+ message : 'Callbacks must be listed after all other props' ,
27
+ type : 'JSXAttribute'
28
+ } ;
29
+ var callbacksLastArgs = [ {
30
+ callbacksLast : true
31
+ } ] ;
25
32
var ignoreCaseArgs = [ {
26
33
ignoreCase : true
27
34
} ] ;
@@ -40,9 +47,12 @@ ruleTester.run('jsx-sort-props', rule, {
40
47
{ code : '<App {...this.props} a="c" b="b" c="a" />;' , ecmaFeatures : features } ,
41
48
{ code : '<App c="a" {...this.props} a="c" b="b" />;' , ecmaFeatures : features } ,
42
49
{ code : '<App A a />;' , ecmaFeatures : features } ,
50
+ // Ignoring case
43
51
{ code : '<App a A />;' , options : ignoreCaseArgs , ecmaFeatures : features } ,
44
52
{ code : '<App a B c />;' , options : ignoreCaseArgs , ecmaFeatures : features } ,
45
- { code : '<App A b C />;' , options : ignoreCaseArgs , ecmaFeatures : features }
53
+ { code : '<App A b C />;' , options : ignoreCaseArgs , ecmaFeatures : features } ,
54
+ // Sorting callbacks below all other props
55
+ { code : '<App a z onBar onFoo />;' , options : callbacksLastArgs , ecmaFeatures : features }
46
56
] ,
47
57
invalid : [
48
58
{ code : '<App b a />;' , errors : [ expectedError ] , ecmaFeatures : features } ,
@@ -53,6 +63,13 @@ ruleTester.run('jsx-sort-props', rule, {
53
63
{ code : '<App B A c />;' , options : ignoreCaseArgs , errors : [ expectedError ] , ecmaFeatures : features } ,
54
64
{ code : '<App c="a" a="c" b="b" />;' , errors : 2 , ecmaFeatures : features } ,
55
65
{ code : '<App {...this.props} c="a" a="c" b="b" />;' , errors : 2 , ecmaFeatures : features } ,
56
- { code : '<App d="d" b="b" {...this.props} c="a" a="c" />;' , errors : 2 , ecmaFeatures : features }
66
+ { code : '<App d="d" b="b" {...this.props} c="a" a="c" />;' , errors : 2 , ecmaFeatures : features } ,
67
+ { code : '<App a z onFoo onBar />;' , errors : [ expectedError ] , options : callbacksLastArgs , ecmaFeatures : features } ,
68
+ {
69
+ code : '<App a onBar onFoo z />;' ,
70
+ errors : [ expectedCallbackError ] ,
71
+ options : callbacksLastArgs ,
72
+ ecmaFeatures : features
73
+ }
57
74
]
58
75
} ) ;
0 commit comments