@@ -310,6 +310,49 @@ ruleTester.run('sort-comp', rule, {
310
310
'render'
311
311
]
312
312
} ]
313
+ } , {
314
+ // Instance methods should be at the top
315
+ code : [
316
+ 'class Hello extends React.Component {' ,
317
+ ' foo = () => {}' ,
318
+ ' constructor() {}' ,
319
+ ' render() {' ,
320
+ ' return <div>{this.props.text}</div>;' ,
321
+ ' }' ,
322
+ '}'
323
+ ] . join ( '\n' ) ,
324
+ parser : 'babel-eslint' ,
325
+ options : [ {
326
+ order : [
327
+ 'instance-methods' ,
328
+ 'static-methods' ,
329
+ 'lifecycle' ,
330
+ 'everything-else' ,
331
+ 'render'
332
+ ]
333
+ } ]
334
+ } , {
335
+ // Instance variables should be at the top
336
+ code : [
337
+ 'class Hello extends React.Component {' ,
338
+ ' foo = "bar"' ,
339
+ ' constructor() {}' ,
340
+ ' state = {}' ,
341
+ ' render() {' ,
342
+ ' return <div>{this.props.text}</div>;' ,
343
+ ' }' ,
344
+ '}'
345
+ ] . join ( '\n' ) ,
346
+ parser : 'babel-eslint' ,
347
+ options : [ {
348
+ order : [
349
+ 'instance-variables' ,
350
+ 'static-methods' ,
351
+ 'lifecycle' ,
352
+ 'everything-else' ,
353
+ 'render'
354
+ ]
355
+ } ]
313
356
} ] ,
314
357
315
358
invalid : [ {
@@ -515,5 +558,50 @@ ruleTester.run('sort-comp', rule, {
515
558
'render'
516
559
]
517
560
} ]
561
+ } , {
562
+ // Instance methods should not be at the top
563
+ code : [
564
+ 'class Hello extends React.Component {' ,
565
+ ' constructor() {}' ,
566
+ ' foo = () => {}' ,
567
+ ' render() {' ,
568
+ ' return <div>{this.props.text}</div>;' ,
569
+ ' }' ,
570
+ '}'
571
+ ] . join ( '\n' ) ,
572
+ parser : 'babel-eslint' ,
573
+ errors : [ { message : 'constructor should be placed after foo' } ] ,
574
+ options : [ {
575
+ order : [
576
+ 'instance-methods' ,
577
+ 'static-methods' ,
578
+ 'lifecycle' ,
579
+ 'everything-else' ,
580
+ 'render'
581
+ ]
582
+ } ]
583
+ } , {
584
+ // Instance variables should not be at the top
585
+ code : [
586
+ 'class Hello extends React.Component {' ,
587
+ ' constructor() {}' ,
588
+ ' state = {}' ,
589
+ ' foo = "bar"' ,
590
+ ' render() {' ,
591
+ ' return <div>{this.props.text}</div>;' ,
592
+ ' }' ,
593
+ '}'
594
+ ] . join ( '\n' ) ,
595
+ parser : 'babel-eslint' ,
596
+ errors : [ { message : 'foo should be placed before constructor' } ] ,
597
+ options : [ {
598
+ order : [
599
+ 'instance-variables' ,
600
+ 'static-methods' ,
601
+ 'lifecycle' ,
602
+ 'everything-else' ,
603
+ 'render'
604
+ ]
605
+ } ]
518
606
} ]
519
607
} ) ;
0 commit comments