提交 d426ebf7 编写于 作者: D Dirk Baeumer

Add linter rule to check for valid localize keys

上级 9b19f820
......@@ -52,6 +52,12 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker {
visitSourceFile(node) {
super.visitSourceFile(node);
Object.keys(this.usedKeys).forEach(key => {
// Keys are quoted.
let identifier = key.substr(1, key.length - 2);
if (!NoUnexternalizedStringsRuleWalker.IDENTIFIER.test(identifier)) {
let occurrence = this.usedKeys[key][0];
this.addFailure(this.createFailure(occurrence.key.getStart(), occurrence.key.getWidth(), `The key ${occurrence.key.getText()} doesn't conform to a valid localize identifier`));
}
const occurrences = this.usedKeys[key];
if (occurrences.length > 1) {
occurrences.forEach(occurrence => {
......@@ -172,3 +178,4 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker {
}
NoUnexternalizedStringsRuleWalker.ImportFailureMessage = 'Do not use double quotes for imports.';
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';
NoUnexternalizedStringsRuleWalker.IDENTIFIER = /^[_a-zA-Z0-9][ .\-_a-zA-Z0-9]*$/;
......@@ -81,9 +81,16 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker {
}
}
private static IDENTIFIER = /^[_a-zA-Z0-9][ .\-_a-zA-Z0-9]*$/;
protected visitSourceFile(node: ts.SourceFile): void {
super.visitSourceFile(node);
Object.keys(this.usedKeys).forEach(key => {
// Keys are quoted.
let identifier = key.substr(1, key.length - 2);
if (!NoUnexternalizedStringsRuleWalker.IDENTIFIER.test(identifier)) {
let occurrence = this.usedKeys[key][0];
this.addFailure(this.createFailure(occurrence.key.getStart(), occurrence.key.getWidth(), `The key ${occurrence.key.getText()} doesn't conform to a valid localize identifier`));
}
const occurrences = this.usedKeys[key];
if (occurrences.length > 1) {
occurrences.forEach(occurrence => {
......
......@@ -236,7 +236,7 @@ export class FeedbackDropdown extends Dropdown {
// Remaining Characters
const remainingCharacterCountContainer = dom.append(this.feedbackForm, dom.$('h3'));
remainingCharacterCountContainer.textContent = nls.localize("tell us why?", "Tell us why?");
remainingCharacterCountContainer.textContent = nls.localize("tell us why", "Tell us why?");
this.remainingCharacterCount = dom.append(remainingCharacterCountContainer, dom.$('span.char-counter'));
this.remainingCharacterCount.textContent = this.getCharCountText(0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册