@@ -3,7 +3,7 @@ import * as Lint from 'tslint';
33import * as ts from 'typescript' ;
44import { DirectiveMetadata } from './angular/metadata' ;
55import { NgWalker } from './angular/ngWalker' ;
6- import { getClassName } from './util/utils' ;
6+ import { getClassName , kebabToCamelCase , toTitleCase } from './util/utils' ;
77
88export class Rule extends Lint . Rules . AbstractRule {
99 static readonly metadata : Lint . IRuleMetadata = {
@@ -32,8 +32,6 @@ export const getFailureMessage = (className: string, propertyName: string): stri
3232 return sprintf ( Rule . FAILURE_STRING , className , propertyName ) ;
3333} ;
3434
35- const kebabToCamelCase = ( value : string ) => value . replace ( / - [ a - z A - Z ] / g, x => x [ 1 ] . toUpperCase ( ) ) ;
36-
3735// source: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques
3836const whiteListAliases = new Set < string > ( [
3937 'aria-activedescendant' ,
@@ -75,26 +73,28 @@ const whiteListAliases = new Set<string>([
7573] ) ;
7674
7775export class InputMetadataWalker extends NgWalker {
78- private directiveSelectors ! : ReadonlySet < DirectiveMetadata [ 'selector' ] > ;
76+ private directiveSelectors ! : ReadonlyArray < DirectiveMetadata [ 'selector' ] > ;
7977
8078 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 ( ',' ) ) ) ;
8280 super . visitNgDirective ( metadata ) ;
8381 }
8482
8583 protected visitNgInput ( property : ts . PropertyDeclaration , input : ts . Decorator , args : string [ ] ) {
86- this . validateInput ( property , input , args ) ;
84+ this . validateInput ( property , args ) ;
8785 super . visitNgInput ( property , input , args ) ;
8886 }
8987
9088 private canPropertyBeAliased ( propertyAlias : string , propertyName : string ) : boolean {
9189 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 ) ) ) ||
9393 ( whiteListAliases . has ( propertyAlias ) && propertyName === kebabToCamelCase ( propertyAlias ) )
9494 ) ;
9595 }
9696
97- private validateInput ( property : ts . PropertyDeclaration , input : ts . Decorator , args : string [ ] ) {
97+ private validateInput ( property : ts . PropertyDeclaration , args : string [ ] ) {
9898 const className = getClassName ( property ) ! ;
9999 const memberName = property . name . getText ( ) ;
100100
0 commit comments