@@ -3,7 +3,7 @@ import * as Lint from 'tslint';
3
3
import * as ts from 'typescript' ;
4
4
import { DirectiveMetadata } from './angular/metadata' ;
5
5
import { NgWalker } from './angular/ngWalker' ;
6
- import { getClassName } from './util/utils' ;
6
+ import { getClassName , kebabToCamelCase , toTitleCase } from './util/utils' ;
7
7
8
8
export class Rule extends Lint . Rules . AbstractRule {
9
9
static readonly metadata : Lint . IRuleMetadata = {
@@ -32,8 +32,6 @@ export const getFailureMessage = (className: string, propertyName: string): stri
32
32
return sprintf ( Rule . FAILURE_STRING , className , propertyName ) ;
33
33
} ;
34
34
35
- const kebabToCamelCase = ( value : string ) => value . replace ( / - [ a - z A - Z ] / g, x => x [ 1 ] . toUpperCase ( ) ) ;
36
-
37
35
// source: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques
38
36
const whiteListAliases = new Set < string > ( [
39
37
'aria-activedescendant' ,
@@ -75,26 +73,28 @@ const whiteListAliases = new Set<string>([
75
73
] ) ;
76
74
77
75
export class InputMetadataWalker extends NgWalker {
78
- private directiveSelectors ! : ReadonlySet < DirectiveMetadata [ 'selector' ] > ;
76
+ private directiveSelectors ! : ReadonlyArray < DirectiveMetadata [ 'selector' ] > ;
79
77
80
78
protected visitNgDirective ( metadata : DirectiveMetadata ) : void {
81
- this . directiveSelectors = new Set ( ( metadata . selector || '' ) . replace ( / [ \[ \] \s ] / g, '' ) . split ( ',' ) ) ;
79
+ this . directiveSelectors = Array . from ( new Set ( ( metadata . selector || '' ) . replace ( / [ \[ \] \s ] / g, '' ) . split ( ',' ) ) ) ;
82
80
super . visitNgDirective ( metadata ) ;
83
81
}
84
82
85
83
protected visitNgInput ( property : ts . PropertyDeclaration , input : ts . Decorator , args : string [ ] ) {
86
- this . validateInput ( property , input , args ) ;
84
+ this . validateInput ( property , args ) ;
87
85
super . visitNgInput ( property , input , args ) ;
88
86
}
89
87
90
88
private canPropertyBeAliased ( propertyAlias : string , propertyName : string ) : boolean {
91
89
return ! ! (
92
- ( this . directiveSelectors && this . directiveSelectors . has ( propertyAlias ) && propertyAlias !== propertyName ) ||
90
+ ( propertyAlias !== propertyName &&
91
+ this . directiveSelectors &&
92
+ this . directiveSelectors . some ( x => new RegExp ( `^${ x } ((${ toTitleCase ( propertyName ) } $)|(?=$))` ) . test ( propertyAlias ) ) ) ||
93
93
( whiteListAliases . has ( propertyAlias ) && propertyName === kebabToCamelCase ( propertyAlias ) )
94
94
) ;
95
95
}
96
96
97
- private validateInput ( property : ts . PropertyDeclaration , input : ts . Decorator , args : string [ ] ) {
97
+ private validateInput ( property : ts . PropertyDeclaration , args : string [ ] ) {
98
98
const className = getClassName ( property ) ! ;
99
99
const memberName = property . name . getText ( ) ;
100
100
0 commit comments