@@ -22,6 +22,7 @@ const parserOptions = {
22
22
// -----------------------------------------------------------------------------
23
23
24
24
const ERROR_MESSAGE = 'Typo in static class property declaration' ;
25
+ const ERROR_MESSAGE_LIFECYCLE_METHOD = 'Typo in component lifecycle method declaration' ;
25
26
26
27
const ruleTester = new RuleTester ( ) ;
27
28
ruleTester . run ( 'no-typos' , rule , {
@@ -181,6 +182,64 @@ ruleTester.run('no-typos', rule, {
181
182
'First[defautProps] = {};'
182
183
] . join ( '\n' ) ,
183
184
parserOptions : parserOptions
185
+ } , {
186
+ code : [
187
+ 'class Hello extends React.Component {' ,
188
+ ' componentWillMount() { }' ,
189
+ ' componentDidMount() { }' ,
190
+ ' componentWillReceiveProps() { }' ,
191
+ ' shouldComponentUpdate() { }' ,
192
+ ' componentWillUpdate() { }' ,
193
+ ' componentDidUpdate() { }' ,
194
+ ' componentWillUnmount() { }' ,
195
+ ' render() {' ,
196
+ ' return <div>Hello {this.props.name}</div>;' ,
197
+ ' }' ,
198
+ '}'
199
+ ] . join ( '\n' ) ,
200
+ parserOptions : parserOptions
201
+ } , {
202
+ code : [
203
+ 'class MyClass {' ,
204
+ ' componentWillMount() { }' ,
205
+ ' componentDidMount() { }' ,
206
+ ' componentWillReceiveProps() { }' ,
207
+ ' shouldComponentUpdate() { }' ,
208
+ ' componentWillUpdate() { }' ,
209
+ ' componentDidUpdate() { }' ,
210
+ ' componentWillUnmount() { }' ,
211
+ ' render() { }' ,
212
+ '}'
213
+ ] . join ( '\n' ) ,
214
+ parserOptions : parserOptions
215
+ } , {
216
+ code : [
217
+ 'class MyClass {' ,
218
+ ' componentwillmount() { }' ,
219
+ ' componentdidmount() { }' ,
220
+ ' componentwillreceiveprops() { }' ,
221
+ ' shouldcomponentupdate() { }' ,
222
+ ' componentwillupdate() { }' ,
223
+ ' componentdidupdate() { }' ,
224
+ ' componentwillUnmount() { }' ,
225
+ ' render() { }' ,
226
+ '}'
227
+ ] . join ( '\n' ) ,
228
+ parserOptions : parserOptions
229
+ } , {
230
+ code : [
231
+ 'class MyClass {' ,
232
+ ' Componentwillmount() { }' ,
233
+ ' Componentdidmount() { }' ,
234
+ ' Componentwillreceiveprops() { }' ,
235
+ ' Shouldcomponentupdate() { }' ,
236
+ ' Componentwillupdate() { }' ,
237
+ ' Componentdidupdate() { }' ,
238
+ ' ComponentwillUnmount() { }' ,
239
+ ' Render() { }' ,
240
+ '}'
241
+ ] . join ( '\n' ) ,
242
+ parserOptions : parserOptions
184
243
} ] ,
185
244
186
245
invalid : [ {
@@ -367,5 +426,122 @@ ruleTester.run('no-typos', rule, {
367
426
] . join ( '\n' ) ,
368
427
parserOptions : parserOptions ,
369
428
errors : [ { message : ERROR_MESSAGE } ]
429
+ } , {
430
+ code : [
431
+ 'class Hello extends React.Component {' ,
432
+ ' ComponentWillMount() { }' ,
433
+ ' ComponentDidMount() { }' ,
434
+ ' ComponentWillReceiveProps() { }' ,
435
+ ' ShouldComponentUpdate() { }' ,
436
+ ' ComponentWillUpdate() { }' ,
437
+ ' ComponentDidUpdate() { }' ,
438
+ ' ComponentWillUnmount() { }' ,
439
+ ' render() {' ,
440
+ ' return <div>Hello {this.props.name}</div>;' ,
441
+ ' }' ,
442
+ '}'
443
+ ] . join ( '\n' ) ,
444
+ parserOptions : parserOptions ,
445
+ errors : [ {
446
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
447
+ type : 'MethodDefinition'
448
+ } , {
449
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
450
+ type : 'MethodDefinition'
451
+ } , {
452
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
453
+ type : 'MethodDefinition'
454
+ } , {
455
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
456
+ type : 'MethodDefinition'
457
+ } , {
458
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
459
+ type : 'MethodDefinition'
460
+ } , {
461
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
462
+ type : 'MethodDefinition'
463
+ } , {
464
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
465
+ type : 'MethodDefinition'
466
+ } ]
467
+ } , {
468
+ code : [
469
+ 'class Hello extends React.Component {' ,
470
+ ' Componentwillmount() { }' ,
471
+ ' Componentdidmount() { }' ,
472
+ ' Componentwillreceiveprops() { }' ,
473
+ ' Shouldcomponentupdate() { }' ,
474
+ ' Componentwillupdate() { }' ,
475
+ ' Componentdidupdate() { }' ,
476
+ ' Componentwillunmount() { }' ,
477
+ ' Render() {' ,
478
+ ' return <div>Hello {this.props.name}</div>;' ,
479
+ ' }' ,
480
+ '}'
481
+ ] . join ( '\n' ) ,
482
+ parserOptions : parserOptions ,
483
+ errors : [ {
484
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
485
+ type : 'MethodDefinition'
486
+ } , {
487
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
488
+ type : 'MethodDefinition'
489
+ } , {
490
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
491
+ type : 'MethodDefinition'
492
+ } , {
493
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
494
+ type : 'MethodDefinition'
495
+ } , {
496
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
497
+ type : 'MethodDefinition'
498
+ } , {
499
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
500
+ type : 'MethodDefinition'
501
+ } , {
502
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
503
+ type : 'MethodDefinition'
504
+ } , {
505
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
506
+ type : 'MethodDefinition'
507
+ } ]
508
+ } , {
509
+ code : [
510
+ 'class Hello extends React.Component {' ,
511
+ ' componentwillmount() { }' ,
512
+ ' componentdidmount() { }' ,
513
+ ' componentwillreceiveprops() { }' ,
514
+ ' shouldcomponentupdate() { }' ,
515
+ ' componentwillupdate() { }' ,
516
+ ' componentdidupdate() { }' ,
517
+ ' componentwillunmount() { }' ,
518
+ ' render() {' ,
519
+ ' return <div>Hello {this.props.name}</div>;' ,
520
+ ' }' ,
521
+ '}'
522
+ ] . join ( '\n' ) ,
523
+ parserOptions : parserOptions ,
524
+ errors : [ {
525
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
526
+ type : 'MethodDefinition'
527
+ } , {
528
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
529
+ type : 'MethodDefinition'
530
+ } , {
531
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
532
+ type : 'MethodDefinition'
533
+ } , {
534
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
535
+ type : 'MethodDefinition'
536
+ } , {
537
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
538
+ type : 'MethodDefinition'
539
+ } , {
540
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
541
+ type : 'MethodDefinition'
542
+ } , {
543
+ message : ERROR_MESSAGE_LIFECYCLE_METHOD ,
544
+ type : 'MethodDefinition'
545
+ } ]
370
546
} ]
371
547
} ) ;
0 commit comments