Skip to content

Commit b381829

Browse files
committed
Add fix to non-externalized string warning
1 parent cdc432d commit b381829

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

build/lib/tslint/noUnexternalizedStringsRule.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ var NoUnexternalizedStringsRuleWalker = (function (_super) {
8989
if (functionName && this.ignores[functionName]) {
9090
return;
9191
}
92+
var x = "foo";
9293
if (doubleQuoted && (!callInfo || callInfo.argIndex === -1 || !this.signatures[functionName])) {
93-
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Unexternalized string found: " + node.getText()));
94+
var s = node.getText();
95+
var replacement = new Lint.Replacement(node.getStart(), node.getWidth(), "nls.localize('KEY-" + s.substring(1, s.length - 1) + "', " + s + ")");
96+
var fix = new Lint.Fix("Unexternalitzed string", [replacement]);
97+
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), "Unexternalized string found: " + node.getText(), fix));
9498
return;
9599
}
96100
// We have a single quoted string outside a localize function name.
@@ -109,8 +113,8 @@ var NoUnexternalizedStringsRuleWalker = (function (_super) {
109113
for (var i = 0; i < keyArg.properties.length; i++) {
110114
var property = keyArg.properties[i];
111115
if (isPropertyAssignment(property)) {
112-
var name_1 = property.name.getText();
113-
if (name_1 === 'key') {
116+
var name = property.name.getText();
117+
if (name === 'key') {
114118
var initializer = property.initializer;
115119
if (isStringLiteral(initializer)) {
116120
this.recordKey(initializer, this.messageIndex ? callInfo.callExpression.arguments[this.messageIndex] : undefined);

build/lib/tslint/noUnexternalizedStringsRule.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker {
109109
if (functionName && this.ignores[functionName]) {
110110
return;
111111
}
112+
112113
if (doubleQuoted && (!callInfo || callInfo.argIndex === -1 || !this.signatures[functionName])) {
113-
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), `Unexternalized string found: ${node.getText()}`));
114+
const s = node.getText();
115+
const replacement = new Lint.Replacement(node.getStart(), node.getWidth(), `nls.localize('KEY-${s.substring(1, s.length - 1)}', ${s})`);
116+
const fix = new Lint.Fix("Unexternalitzed string", [replacement]);
117+
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), `Unexternalized string found: ${node.getText()}`, fix));
114118
return;
115119
}
116120
// We have a single quoted string outside a localize function name.

0 commit comments

Comments
 (0)