From e109e68c8869ebdf868b05eb57371e9a9e88fa49 Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Wed, 30 Jan 2019 15:28:53 +0700 Subject: [PATCH] fix(allow-template-call-expression): allow $any in expressions --- src/noTemplateCallExpressionRule.ts | 6 +++++- test/noTemplateCallExpressionRule.spec.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/noTemplateCallExpressionRule.ts b/src/noTemplateCallExpressionRule.ts index 2206de621..1fa22bba9 100644 --- a/src/noTemplateCallExpressionRule.ts +++ b/src/noTemplateCallExpressionRule.ts @@ -33,6 +33,8 @@ class TemplateVisitor extends BasicTemplateAstVisitor { } class ExpressionVisitor extends RecursiveAngularExpressionVisitor { + private allowedMethodNames = ['$any']; + visitFunctionCall(node: e.FunctionCall, context: any) { this.addFailureFromStartToEnd(node.span.start, node.span.end, Rule.FAILURE_STRING); @@ -40,7 +42,9 @@ class ExpressionVisitor extends RecursiveAngularExpressionVisitor { } visitMethodCall(node: e.MethodCall, context: any) { - this.addFailureFromStartToEnd(node.span.start, node.span.end, Rule.FAILURE_STRING); + if (this.allowedMethodNames.indexOf(node.name) === -1) { + this.addFailureFromStartToEnd(node.span.start, node.span.end, Rule.FAILURE_STRING); + } super.visitMethodCall(node, context); } diff --git a/test/noTemplateCallExpressionRule.spec.ts b/test/noTemplateCallExpressionRule.spec.ts index d6cbb2e4c..05cc9494b 100644 --- a/test/noTemplateCallExpressionRule.spec.ts +++ b/test/noTemplateCallExpressionRule.spec.ts @@ -21,6 +21,16 @@ describe('no-template-call-expression', () => { `; assertSuccess('no-template-call-expression', source); }); + + it('should allow $any to wrap unknown variables', () => { + let source = ` + @Component({ + template: '{{$any(info)}}' + }) + class Bar {} + `; + assertSuccess('no-template-call-expression', source); + }); }); describe('failure', () => {