1
- import { assertSuccess , assertAnnotated , assertMultipleAnnotated , assertFailure , assertFailures } from './testHelper' ;
1
+ import { assertSuccess , assertAnnotated , assertMultipleAnnotated } from './testHelper' ;
2
2
import { Replacement } from 'tslint' ;
3
3
import { expect } from 'chai' ;
4
4
import { FsFileResolver } from '../src/angular/fileResolver/fsFileResolver' ;
5
5
import { MetadataReader } from '../src/angular/metadataReader' ;
6
6
import * as ts from 'typescript' ;
7
7
import chai = require( 'chai' ) ;
8
- import { readFileSync } from 'fs' ;
9
8
10
9
const getAst = ( code : string , file = 'file.ts' ) => {
11
10
return ts . createSourceFile ( file , code , ts . ScriptTarget . ES5 , true ) ;
@@ -119,6 +118,7 @@ describe('angular-whitespace', () => {
119
118
})
120
119
class Bar {}
121
120
` ;
121
+ const reader = new MetadataReader ( new FsFileResolver ( ) ) ;
122
122
const ast = getAst ( code , __dirname + '/../../test/fixtures/angularWhitespace/component.ts' ) ;
123
123
assertSuccess ( 'angular-whitespace' , ast , [ 'check-pipe' ] ) ;
124
124
} ) ;
@@ -167,6 +167,7 @@ describe('angular-whitespace', () => {
167
167
ponies = []
168
168
}
169
169
` ;
170
+ const reader = new MetadataReader ( new FsFileResolver ( ) ) ;
170
171
const ast = getAst ( code , __dirname + '/../../test/fixtures/angularWhitespace/component.ts' ) ;
171
172
assertSuccess ( 'angular-whitespace' , ast , [ 'check-pipe' ] ) ;
172
173
} ) ;
@@ -306,8 +307,8 @@ describe('failure', () => {
306
307
assertMultipleAnnotated ( {
307
308
ruleName : 'angular-whitespace' ,
308
309
failures : [
309
- { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
310
- { char : '^' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
310
+ { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
311
+ { char : '^' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
311
312
] ,
312
313
source,
313
314
options : [ 'check-interpolation' ]
@@ -345,8 +346,8 @@ describe('failure', () => {
345
346
const failures = assertMultipleAnnotated ( {
346
347
ruleName : 'angular-whitespace' ,
347
348
failures : [
348
- { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
349
- { char : '^' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
349
+ { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
350
+ { char : '^' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
350
351
] ,
351
352
source,
352
353
options : [ 'check-interpolation' ]
@@ -378,8 +379,8 @@ describe('failure', () => {
378
379
const failures = assertMultipleAnnotated ( {
379
380
ruleName : 'angular-whitespace' ,
380
381
failures : [
381
- { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
382
- { char : '^' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
382
+ { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
383
+ { char : '^' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
383
384
] ,
384
385
source,
385
386
options : [ 'check-interpolation' ]
@@ -399,118 +400,6 @@ describe('failure', () => {
399
400
class Bar {}` ) ;
400
401
} ) ;
401
402
402
- it ( 'should fail and apply proper replacements when style is incorrect' , ( ) => {
403
- let source = `
404
- @Component({
405
- template: \`
406
- <h1>
407
- {{foo}}
408
- ~~ ^^
409
- </h1>
410
- \`
411
- })
412
- class Bar {}` ;
413
- const failures = assertMultipleAnnotated ( {
414
- ruleName : 'angular-whitespace' ,
415
- failures : [
416
- { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
417
- { char : '^' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
418
- ] ,
419
- source,
420
- options : [ 'check-interpolation' ]
421
- } ) ;
422
-
423
- const res = Replacement . applyAll ( source , [ ] . concat . apply ( [ ] , failures . map ( f => f . getFix ( ) ) ) ) ;
424
- expect ( res ) . to . eq ( `
425
- @Component({
426
- template: \`
427
- <h1>
428
- {{ foo }}
429
- ~~ ^^
430
- </h1>
431
- \`
432
- })
433
- class Bar {}` ) ;
434
- } ) ;
435
-
436
- it ( 'should fail and apply proper replacements when style is incorrect' , ( ) => {
437
- let source = `
438
- @Component({
439
- template: \`
440
- <div>
441
- {{message.ACTIVATED}}
442
- ~~ ^^
443
- </div>
444
- \`
445
- })
446
- class Bar {}` ;
447
- const failures = assertMultipleAnnotated ( {
448
- ruleName : 'angular-whitespace' ,
449
- failures : [
450
- { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
451
- { char : '^' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
452
- ] ,
453
- source,
454
- options : [ 'check-interpolation' ]
455
- } ) ;
456
-
457
- const res = Replacement . applyAll ( source , [ ] . concat . apply ( [ ] , failures . map ( f => f . getFix ( ) ) ) ) ;
458
- expect ( res ) . to . eq ( `
459
- @Component({
460
- template: \`
461
- <div>
462
- {{ message.ACTIVATED }}
463
- ~~ ^^
464
- </div>
465
- \`
466
- })
467
- class Bar {}` ) ;
468
- } ) ;
469
-
470
- it ( 'should work with external templates with interpolation' , ( ) => {
471
- const code = `
472
- @Component({
473
- selector: 'foo',
474
- moduleId: module.id,
475
- templateUrl: 'interpolation.html',
476
- })
477
- class Bar {
478
- ponies = []
479
- }
480
- ` ;
481
- const ast = getAst ( code , __dirname + '/../../test/fixtures/angularWhitespace/component.ts' ) ;
482
- const failures = assertFailures ( 'angular-whitespace' , ast , [ {
483
- message : 'Missing whitespace in interpolation start; expecting {{ expr }}' ,
484
- startPosition : {
485
- line : 2 ,
486
- character : 3
487
- } ,
488
- endPosition : {
489
- line : 2 ,
490
- character : 5
491
- }
492
- } , {
493
- message : 'Missing whitespace in interpolation end; expecting {{ expr }}' ,
494
- startPosition : {
495
- line : 2 ,
496
- character : 22
497
- } ,
498
- endPosition : {
499
- line : 2 ,
500
- character : 24
501
- }
502
- }
503
- ] , [ 'check-interpolation' ] ) ;
504
- const template = readFileSync ( __dirname + '/../../test/fixtures/angularWhitespace/interpolation.html' ) . toString ( ) ;
505
- const res = Replacement . applyAll ( template , [ ] . concat . apply ( [ ] , failures . map ( f => f . getFix ( ) ) ) ) ;
506
- expect ( res ) . to . equal ( `<div class="account-product__sub-title">
507
- <div *ngIf="productIsFixed">
508
- {{ message.ACTIVATED }}
509
- </div>
510
- </div>
511
- ` ) ;
512
- } ) ;
513
-
514
403
it ( 'should fail and apply proper replacements when style is incorrect with multiple failures' , ( ) => {
515
404
let source = `
516
405
@Component({
@@ -529,10 +418,10 @@ describe('failure', () => {
529
418
const failures = assertMultipleAnnotated ( {
530
419
ruleName : 'angular-whitespace' ,
531
420
failures : [
532
- { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
533
- { char : '-' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
534
- { char : '^' , msg : 'Extra whitespace in interpolation start; expecting {{ expr }}' , } ,
535
- { char : '#' , msg : 'Extra whitespace in interpolation end; expecting {{ expr }}' , } ,
421
+ { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
422
+ { char : '-' , msg : 'Missing whitespace in interpolation end; expecting {{ expr }}' , } ,
423
+ { char : '^' , msg : 'Extra whitespace in interpolation start; expecting {{ expr }}' , } ,
424
+ { char : '#' , msg : 'Extra whitespace in interpolation end; expecting {{ expr }}' , } ,
536
425
] ,
537
426
source,
538
427
options : [ 'check-interpolation' ]
@@ -594,8 +483,8 @@ describe('failure', () => {
594
483
const failures = assertMultipleAnnotated ( {
595
484
ruleName : 'angular-whitespace' ,
596
485
failures : [
597
- { char : '~' , msg : 'Extra whitespace in interpolation start; expecting {{ expr }}' , } ,
598
- { char : '^' , msg : 'Extra whitespace in interpolation end; expecting {{ expr }}' , } ,
486
+ { char : '~' , msg : 'Extra whitespace in interpolation start; expecting {{ expr }}' , } ,
487
+ { char : '^' , msg : 'Extra whitespace in interpolation end; expecting {{ expr }}' , } ,
599
488
] ,
600
489
source,
601
490
options : [ 'check-interpolation' ]
@@ -778,8 +667,8 @@ describe('failure', () => {
778
667
const failures = assertMultipleAnnotated ( {
779
668
ruleName : 'angular-whitespace' ,
780
669
failures : [
781
- { char : '~' , msg : 'Missing whitespace after semicolon; expecting \'; expr\'' , } ,
782
- { char : '^' , msg : 'Missing whitespace after semicolon; expecting \'; expr\'' , } ,
670
+ { char : '~' , msg : 'Missing whitespace after semicolon; expecting \'; expr\'' , } ,
671
+ { char : '^' , msg : 'Missing whitespace after semicolon; expecting \'; expr\'' , } ,
783
672
] ,
784
673
source,
785
674
options : [ 'check-semicolon' ]
@@ -808,8 +697,8 @@ describe('failure', () => {
808
697
const failures = assertMultipleAnnotated ( {
809
698
ruleName : 'angular-whitespace' ,
810
699
failures : [
811
- { char : '~' , msg : 'Missing whitespace after semicolon; expecting \'; expr\'' , } ,
812
- { char : '^' , msg : 'Missing whitespace after semicolon; expecting \'; expr\'' , } ,
700
+ { char : '~' , msg : 'Missing whitespace after semicolon; expecting \'; expr\'' , } ,
701
+ { char : '^' , msg : 'Missing whitespace after semicolon; expecting \'; expr\'' , } ,
813
702
] ,
814
703
source,
815
704
options : [ 'check-semicolon' ]
@@ -1041,8 +930,8 @@ describe('pipes', () => {
1041
930
const failures = assertMultipleAnnotated ( {
1042
931
ruleName : 'angular-whitespace' ,
1043
932
failures : [
1044
- { char : '~' , msg : 'The pipe operator should be surrounded by one space on each side, i.e. " | ".' , } ,
1045
- { char : '^' , msg : 'The pipe operator should be surrounded by one space on each side, i.e. " | ".' , } ,
933
+ { char : '~' , msg : 'The pipe operator should be surrounded by one space on each side, i.e. " | ".' , } ,
934
+ { char : '^' , msg : 'The pipe operator should be surrounded by one space on each side, i.e. " | ".' , } ,
1046
935
] ,
1047
936
source,
1048
937
options : [ 'check-pipe' ]
@@ -1167,8 +1056,8 @@ describe('angular-whitespace multiple checks', () => {
1167
1056
const failures = assertMultipleAnnotated ( {
1168
1057
ruleName : 'angular-whitespace' ,
1169
1058
failures : [
1170
- { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
1171
- { char : '^' , msg : 'The pipe operator should be surrounded by one space on each side, i.e. " | ".' , } ,
1059
+ { char : '~' , msg : 'Missing whitespace in interpolation start; expecting {{ expr }}' , } ,
1060
+ { char : '^' , msg : 'The pipe operator should be surrounded by one space on each side, i.e. " | ".' , } ,
1172
1061
] ,
1173
1062
source,
1174
1063
options : [ 'check-interpolation' , 'check-pipe' ]
0 commit comments