@@ -13,9 +13,16 @@ var RuleTester = require('eslint').RuleTester;
13
13
14
14
var MESSAGE_AFTER_PROPS = [ { message : 'The closing bracket must be placed after the last prop' } ] ;
15
15
var MESSAGE_AFTER_TAG = [ { message : 'The closing bracket must be placed after the opening tag' } ] ;
16
- var MESSAGE_PROPS_ALIGNED = [ { message : 'The closing bracket must be aligned with the last prop' } ] ;
17
- var MESSAGE_TAG_ALIGNED = [ { message : 'The closing bracket must be aligned with the opening tag' } ] ;
18
- var MESSAGE_LINE_ALIGNED = [ { message : 'The closing bracket must be aligned with the line containing the opening tag' } ] ;
16
+
17
+ var MESSAGE_PROPS_ALIGNED = 'The closing bracket must be aligned with the last prop' ;
18
+ var MESSAGE_TAG_ALIGNED = 'The closing bracket must be aligned with the opening tag' ;
19
+ var MESSAGE_LINE_ALIGNED = 'The closing bracket must be aligned with the line containing the opening tag' ;
20
+
21
+ var messageWithDetails = function ( message , expectedColumn , expectedNextLine ) {
22
+ var details = ' (expected column ' + expectedColumn +
23
+ ( expectedNextLine ? ' on the next line)' : ')' ) ;
24
+ return message + details ;
25
+ } ;
19
26
20
27
// ------------------------------------------------------------------------------
21
28
// Tests
@@ -335,23 +342,35 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
335
342
] . join ( '\n' ) ,
336
343
options : [ { location : 'props-aligned' } ] ,
337
344
ecmaFeatures : { jsx : true } ,
338
- errors : MESSAGE_PROPS_ALIGNED
345
+ errors : [ {
346
+ message : messageWithDetails ( MESSAGE_PROPS_ALIGNED , 3 , true ) ,
347
+ line : 2 ,
348
+ column : 7
349
+ } ]
339
350
} , {
340
351
code : [
341
352
'<App ' ,
342
353
' foo />'
343
354
] . join ( '\n' ) ,
344
355
options : [ { location : 'tag-aligned' } ] ,
345
356
ecmaFeatures : { jsx : true } ,
346
- errors : MESSAGE_TAG_ALIGNED
357
+ errors : [ {
358
+ message : messageWithDetails ( MESSAGE_TAG_ALIGNED , 1 , true ) ,
359
+ line : 2 ,
360
+ column : 7
361
+ } ]
347
362
} , {
348
363
code : [
349
364
'<App ' ,
350
365
' foo />'
351
366
] . join ( '\n' ) ,
352
367
options : [ { location : 'line-aligned' } ] ,
353
368
ecmaFeatures : { jsx : true } ,
354
- errors : MESSAGE_LINE_ALIGNED
369
+ errors : [ {
370
+ message : messageWithDetails ( MESSAGE_LINE_ALIGNED , 1 , true ) ,
371
+ line : 2 ,
372
+ column : 7
373
+ } ]
355
374
} , {
356
375
code : [
357
376
'<App ' ,
@@ -369,7 +388,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
369
388
] . join ( '\n' ) ,
370
389
options : [ { location : 'props-aligned' } ] ,
371
390
ecmaFeatures : { jsx : true } ,
372
- errors : MESSAGE_PROPS_ALIGNED
391
+ errors : [ {
392
+ message : messageWithDetails ( MESSAGE_PROPS_ALIGNED , 3 , false ) ,
393
+ line : 3 ,
394
+ column : 1
395
+ } ]
373
396
} , {
374
397
code : [
375
398
'<App ' ,
@@ -387,7 +410,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
387
410
] . join ( '\n' ) ,
388
411
options : [ { location : 'tag-aligned' } ] ,
389
412
ecmaFeatures : { jsx : true } ,
390
- errors : MESSAGE_TAG_ALIGNED
413
+ errors : [ {
414
+ message : messageWithDetails ( MESSAGE_TAG_ALIGNED , 1 , false ) ,
415
+ line : 3 ,
416
+ column : 3
417
+ } ]
391
418
} , {
392
419
code : [
393
420
'<App ' ,
@@ -396,7 +423,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
396
423
] . join ( '\n' ) ,
397
424
options : [ { location : 'line-aligned' } ] ,
398
425
ecmaFeatures : { jsx : true } ,
399
- errors : MESSAGE_LINE_ALIGNED
426
+ errors : [ {
427
+ message : messageWithDetails ( MESSAGE_LINE_ALIGNED , 1 , false ) ,
428
+ line : 3 ,
429
+ column : 3
430
+ } ]
400
431
} , {
401
432
code : [
402
433
'<App' ,
@@ -414,7 +445,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
414
445
] . join ( '\n' ) ,
415
446
options : [ { location : 'props-aligned' } ] ,
416
447
ecmaFeatures : { jsx : true } ,
417
- errors : MESSAGE_PROPS_ALIGNED
448
+ errors : [ {
449
+ message : messageWithDetails ( MESSAGE_PROPS_ALIGNED , 3 , false ) ,
450
+ line : 3 ,
451
+ column : 1
452
+ } ]
418
453
} , {
419
454
code : [
420
455
'<App' ,
@@ -432,7 +467,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
432
467
] . join ( '\n' ) ,
433
468
options : [ { location : 'tag-aligned' } ] ,
434
469
ecmaFeatures : { jsx : true } ,
435
- errors : MESSAGE_TAG_ALIGNED
470
+ errors : [ {
471
+ message : messageWithDetails ( MESSAGE_TAG_ALIGNED , 1 , false ) ,
472
+ line : 3 ,
473
+ column : 3
474
+ } ]
436
475
} , {
437
476
code : [
438
477
'<App' ,
@@ -441,7 +480,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
441
480
] . join ( '\n' ) ,
442
481
options : [ { location : 'line-aligned' } ] ,
443
482
ecmaFeatures : { jsx : true } ,
444
- errors : MESSAGE_LINE_ALIGNED
483
+ errors : [ {
484
+ message : messageWithDetails ( MESSAGE_LINE_ALIGNED , 1 , false ) ,
485
+ line : 3 ,
486
+ column : 3
487
+ } ]
445
488
} , {
446
489
code : [
447
490
'<Provider ' ,
@@ -453,7 +496,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
453
496
] . join ( '\n' ) ,
454
497
options : [ { selfClosing : 'props-aligned' } ] ,
455
498
ecmaFeatures : { jsx : true } ,
456
- errors : MESSAGE_TAG_ALIGNED
499
+ errors : [ {
500
+ message : messageWithDetails ( MESSAGE_TAG_ALIGNED , 1 , true ) ,
501
+ line : 2 ,
502
+ column : 8
503
+ } ]
457
504
} , {
458
505
code : [
459
506
'<Provider' ,
@@ -466,7 +513,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
466
513
] . join ( '\n' ) ,
467
514
options : [ { nonEmpty : 'props-aligned' } ] ,
468
515
ecmaFeatures : { jsx : true } ,
469
- errors : MESSAGE_TAG_ALIGNED
516
+ errors : [ {
517
+ message : messageWithDetails ( MESSAGE_TAG_ALIGNED , 3 , false ) ,
518
+ line : 6 ,
519
+ column : 5
520
+ } ]
470
521
} , {
471
522
code : [
472
523
'<Provider ' ,
@@ -477,7 +528,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
477
528
] . join ( '\n' ) ,
478
529
options : [ { selfClosing : 'after-props' } ] ,
479
530
ecmaFeatures : { jsx : true } ,
480
- errors : MESSAGE_TAG_ALIGNED
531
+ errors : [ {
532
+ message : messageWithDetails ( MESSAGE_TAG_ALIGNED , 1 , true ) ,
533
+ line : 2 ,
534
+ column : 8
535
+ } ]
481
536
} , {
482
537
code : [
483
538
'<Provider ' ,
@@ -489,7 +544,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
489
544
] . join ( '\n' ) ,
490
545
options : [ { nonEmpty : 'after-props' } ] ,
491
546
ecmaFeatures : { jsx : true } ,
492
- errors : MESSAGE_TAG_ALIGNED
547
+ errors : [ {
548
+ message : messageWithDetails ( MESSAGE_TAG_ALIGNED , 3 , false ) ,
549
+ line : 5 ,
550
+ column : 5
551
+ } ]
493
552
} , {
494
553
code : [
495
554
'var x = function() {' ,
@@ -500,7 +559,11 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
500
559
] . join ( '\n' ) ,
501
560
options : [ { location : 'line-aligned' } ] ,
502
561
ecmaFeatures : { jsx : true } ,
503
- errors : MESSAGE_LINE_ALIGNED
562
+ errors : [ {
563
+ message : messageWithDetails ( MESSAGE_LINE_ALIGNED , 3 , false ) ,
564
+ line : 4 ,
565
+ column : 10
566
+ } ]
504
567
} , {
505
568
code : [
506
569
'var x = <App' ,
@@ -509,6 +572,10 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
509
572
] . join ( '\n' ) ,
510
573
options : [ { location : 'line-aligned' } ] ,
511
574
ecmaFeatures : { jsx : true } ,
512
- errors : MESSAGE_LINE_ALIGNED
575
+ errors : [ {
576
+ message : messageWithDetails ( MESSAGE_LINE_ALIGNED , 1 , false ) ,
577
+ line : 3 ,
578
+ column : 9
579
+ } ]
513
580
} ]
514
581
} ) ;
0 commit comments