@@ -5,89 +5,93 @@ const {
5
5
FAILURE_STRING ,
6
6
metadata : { ruleName }
7
7
} = Rule ;
8
- const className = 'Test' ;
9
8
10
- const getFailureAnnotations = ( num : number ) : string => {
11
- return '~' . repeat ( num ) ;
12
- } ;
13
-
14
- const getComposedOptions = ( prefixes : string [ ] ) : ( boolean | string ) [ ] => {
15
- return [ true , ...prefixes ] ;
9
+ const getComposedOptions = ( blacklistedPrefixes : string [ ] ) : ( boolean | string ) [ ] => {
10
+ return [ true , ...blacklistedPrefixes ] ;
16
11
} ;
17
12
18
13
describe ( ruleName , ( ) => {
19
14
describe ( 'failure' , ( ) => {
20
15
it ( 'should fail when an input property is prefixed by a blacklisted prefix and blacklist is composed by one prefix' , ( ) => {
21
- const prefixes = [ 'is' ] ;
22
- const propertyName = `${ prefixes [ 0 ] } Disabled` ;
23
- const inputExpression = `@Input() ${ propertyName } : boolean;` ;
16
+ const blacklistedPrefixes = [ 'is' ] ;
17
+ const source = `
18
+ @Directive()
19
+ class Test {
20
+ @Input() isDisabled: boolean;
21
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22
+ }
23
+ ` ;
24
+ assertAnnotated ( {
25
+ message : getFailureMessage ( blacklistedPrefixes ) ,
26
+ options : getComposedOptions ( blacklistedPrefixes ) ,
27
+ ruleName,
28
+ source
29
+ } ) ;
30
+ } ) ;
31
+
32
+ it ( 'should fail when an input property is strictly equal to a blacklisted prefix' , ( ) => {
33
+ const blacklistedPrefixes = [ 'should' ] ;
24
34
const source = `
25
35
@Directive()
26
- class ${ className } {
27
- ${ inputExpression }
28
- ${ getFailureAnnotations ( inputExpression . length ) }
36
+ class Test {
37
+ @Input() should: boolean;
38
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
29
39
}
30
40
` ;
31
41
assertAnnotated ( {
32
- message : getFailureMessage ( className , propertyName , prefixes ) ,
33
- options : getComposedOptions ( prefixes ) ,
42
+ message : getFailureMessage ( blacklistedPrefixes ) ,
43
+ options : getComposedOptions ( blacklistedPrefixes ) ,
34
44
ruleName,
35
45
source
36
46
} ) ;
37
47
} ) ;
38
48
39
- it ( 'should fail when an input property is prefixed by a blacklisted prefix and blacklist is composed by two prefixes' , ( ) => {
40
- const prefixes = [ 'can' , 'is' ] ;
41
- const propertyName = `${ prefixes [ 0 ] } Enable` ;
42
- const inputExpression = `@Input() ${ propertyName } : boolean;` ;
49
+ it ( 'should fail when an input property is prefixed by a blacklisted prefix and blacklist is composed by two blacklistedPrefixes' , ( ) => {
50
+ const blacklistedPrefixes = [ 'can' , 'is' ] ;
43
51
const source = `
44
52
@Component()
45
- class ${ className } {
46
- ${ inputExpression }
47
- ${ getFailureAnnotations ( inputExpression . length ) }
53
+ class Test {
54
+ @Input() canEnable: boolean;
55
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48
56
}
49
57
` ;
50
58
assertAnnotated ( {
51
- message : getFailureMessage ( className , propertyName , prefixes ) ,
52
- options : getComposedOptions ( prefixes ) ,
59
+ message : getFailureMessage ( blacklistedPrefixes ) ,
60
+ options : getComposedOptions ( blacklistedPrefixes ) ,
53
61
ruleName,
54
62
source
55
63
} ) ;
56
64
} ) ;
57
65
58
- it ( 'should fail when an input property is prefixed by a blacklisted prefix and blacklist is composed by two concurrent prefixes' , ( ) => {
59
- const prefixes = [ 'is' , 'isc' ] ;
60
- const propertyName = `${ prefixes [ 1 ] } Hange` ;
61
- const inputExpression = `@Input() ${ propertyName } : boolean;` ;
66
+ it ( 'should fail when an input property is prefixed by a blacklisted prefix and blacklist is composed by two concurrent blacklistedPrefixes' , ( ) => {
67
+ const blacklistedPrefixes = [ 'is' , 'isc' ] ;
62
68
const source = `
63
69
@Component()
64
- class ${ className } {
65
- ${ inputExpression }
66
- ${ getFailureAnnotations ( inputExpression . length ) }
70
+ class Test {
71
+ @Input() iscHange: boolean;
72
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
67
73
}
68
74
` ;
69
75
assertAnnotated ( {
70
- message : getFailureMessage ( className , propertyName , prefixes ) ,
71
- options : getComposedOptions ( prefixes ) ,
76
+ message : getFailureMessage ( blacklistedPrefixes ) ,
77
+ options : getComposedOptions ( blacklistedPrefixes ) ,
72
78
ruleName,
73
79
source
74
80
} ) ;
75
81
} ) ;
76
82
77
83
it ( 'should fail when an input property is snakecased and contains a blacklisted prefix' , ( ) => {
78
- const prefixes = [ 'do' ] ;
79
- const propertyName = `${ prefixes [ 0 ] } _it` ;
80
- const inputExpression = `@Input() ${ propertyName } : number;` ;
84
+ const blacklistedPrefixes = [ 'do' ] ;
81
85
const source = `
82
86
@Directive()
83
- class ${ className } {
84
- ${ inputExpression }
85
- ${ getFailureAnnotations ( inputExpression . length ) }
87
+ class Test {
88
+ @Input() do_it: number;
89
+ ~~~~~~~~~~~~~~~~~~~~~~~
86
90
}
87
91
` ;
88
92
assertAnnotated ( {
89
- message : getFailureMessage ( className , propertyName , prefixes ) ,
90
- options : getComposedOptions ( prefixes ) ,
93
+ message : getFailureMessage ( blacklistedPrefixes ) ,
94
+ options : getComposedOptions ( blacklistedPrefixes ) ,
91
95
ruleName,
92
96
source
93
97
} ) ;
@@ -96,26 +100,28 @@ describe(ruleName, () => {
96
100
97
101
describe ( 'success' , ( ) => {
98
102
it ( 'should succeed when an input property is not prefixed' , ( ) => {
103
+ const blacklistedPrefixes = [ 'must' ] ;
99
104
const source = `
100
105
@Directive()
101
- class ${ className } {
106
+ class Test {
102
107
@Input() mustmust = true;
103
108
}
104
109
` ;
105
- assertSuccess ( ruleName , source , getComposedOptions ( [ 'must' ] ) ) ;
110
+ assertSuccess ( ruleName , source , getComposedOptions ( blacklistedPrefixes ) ) ;
106
111
} ) ;
107
112
108
113
it ( 'should succeed when multiple input properties are prefixed by something not present in the blacklist' , ( ) => {
114
+ const blacklistedPrefixes = [ 'can' , 'dis' , 'disable' , 'should' ] ;
109
115
const source = `
110
116
@Component()
111
- class ${ className } {
117
+ class Test {
112
118
@Input() cana: string;
113
119
@Input() disabledThing: boolean;
114
120
@Input() isFoo = 'yes';
115
121
@Input() shoulddoit: boolean;
116
122
}
117
123
` ;
118
- assertSuccess ( ruleName , source , getComposedOptions ( [ 'can' , 'should' , 'dis' , 'disable' ] ) ) ;
124
+ assertSuccess ( ruleName , source , getComposedOptions ( blacklistedPrefixes ) ) ;
119
125
} ) ;
120
126
} ) ;
121
127
} ) ;
0 commit comments