From 4c1c8d453da80436890b75bf77ee888cba2d1855 Mon Sep 17 00:00:00 2001 From: mgechev Date: Tue, 9 Jan 2018 13:01:07 +0200 Subject: [PATCH] fix(i18n): do not warn with interpolation in i18n element Fix #442 --- src/i18nRule.ts | 2 +- test/i18nRule.spec.ts | 44 ++++++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/i18nRule.ts b/src/i18nRule.ts index 965682562..8b948a02e 100644 --- a/src/i18nRule.ts +++ b/src/i18nRule.ts @@ -60,7 +60,7 @@ class I18NTextVisitor extends BasicTemplateAstVisitor implements ConfigurableVis if (!this.visited.has(text)) { this.visited.add(text); const val = text.value; - if (val instanceof ast.ASTWithSource && val.ast instanceof ast.Interpolation) { + if (val instanceof ast.ASTWithSource && val.ast instanceof ast.Interpolation && !this.hasI18n) { const textNonEmpty = val.ast.strings.some(s => /\w+/.test(s)); if (textNonEmpty) { const span = text.sourceSpan; diff --git a/test/i18nRule.spec.ts b/test/i18nRule.spec.ts index 1620d3d40..e10b5c212 100644 --- a/test/i18nRule.spec.ts +++ b/test/i18nRule.spec.ts @@ -14,7 +14,7 @@ const getAst = (code: string, file = 'file.ts') => { describe('i18n', () => { describe('check-id', () => { it('should work with proper id', () => { - let source = ` + const source = ` @Component({ template: \`
Text
@@ -25,8 +25,22 @@ describe('i18n', () => { assertSuccess('i18n', source, ['check-id']); }); + it('should work with proper i18n attribute', () => { + const source = ` + @Component({ + template: \` +
+ Use at least {{ minLength }} characters +
+ \` + }) + class Bar {} + `; + assertSuccess('i18n', source, ['check-text']); + }); + it('should work with proper id', () => { - let source = ` + const source = ` @Component({ template: \`
Text
@@ -38,7 +52,7 @@ describe('i18n', () => { }); it('should work with proper id', () => { - let source = ` + const source = ` @Component({ template: \`
Text
@@ -50,7 +64,7 @@ describe('i18n', () => { }); it('should fail with missing id string', () => { - let source = ` + const source = ` @Component({ template: \`
Text
@@ -68,7 +82,7 @@ describe('i18n', () => { }); it('should fail with missing id', () => { - let source = ` + const source = ` @Component({ template: \`
Text
@@ -86,7 +100,7 @@ describe('i18n', () => { }); it('should fail with missing id', () => { - let source = ` + const source = ` @Component({ template: \`
Text
@@ -106,7 +120,7 @@ describe('i18n', () => { describe('check-text', () => { it('should work with i18n attribute', () => { - let source = ` + const source = ` @Component({ template: \`
Text
@@ -118,7 +132,7 @@ describe('i18n', () => { }); it('should work without i18n attribute & interpolation', () => { - let source = ` + const source = ` @Component({ template: \`
{{text}}
@@ -130,7 +144,7 @@ describe('i18n', () => { }); it('should work with multiple valid elements', () => { - let source = ` + const source = ` @Component({ template: \`
{{text}}
@@ -146,7 +160,7 @@ describe('i18n', () => { }); it('should fail with missing id string', () => { - let source = ` + const source = ` @Component({ template: \`
Text
@@ -164,7 +178,7 @@ describe('i18n', () => { }); it('should fail with missing id string in nested elements', () => { - let source = ` + const source = ` @Component({ template: \`
@@ -185,7 +199,7 @@ describe('i18n', () => { }); it('should fail with text outside element with i18n attribute', () => { - let source = ` + const source = ` @Component({ template: \`
Text
@@ -213,7 +227,7 @@ describe('i18n', () => { }); it('should fail with missing id string', () => { - let source = ` + const source = ` @Component({ template: \`
Text {{ foo }}
@@ -231,7 +245,7 @@ describe('i18n', () => { }); it('should fail with missing id string', () => { - let source = ` + const source = ` @Component({ template: \`
{{ foo }} text
@@ -249,7 +263,7 @@ describe('i18n', () => { }); it('should fail with text outside element with i18n attribute', () => { - let source = ` + const source = ` @Component({ template: \`
Text