提交 30ce2998 编写于 作者: J Johannes Rieken

teach lint rules new dynamic import statements

上级 cebe4943
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
"type": "gulp", "type": "gulp",
"task": "tslint", "task": "tslint",
"label": "Run tslint", "label": "Run tslint",
"problemMatcher": ["$tslint4"] "problemMatcher": [
"$tslint4"
]
}, },
{ {
"taskName": "Run tests", "taskName": "Run tests",
...@@ -59,6 +61,11 @@ ...@@ -59,6 +61,11 @@
"type": "gulp", "type": "gulp",
"task": "electron", "task": "electron",
"label": "Download electron" "label": "Download electron"
},
{
"type": "gulp",
"task": "hygiene",
"problemMatcher": []
} }
] ]
} }
\ No newline at end of file
...@@ -162,50 +162,50 @@ var XLF = (function () { ...@@ -162,50 +162,50 @@ var XLF = (function () {
line.append(content); line.append(content);
this.buffer.push(line.toString()); this.buffer.push(line.toString());
}; };
return XLF; XLF.parse = function (xlfString) {
}()); return new Promise(function (resolve, reject) {
XLF.parse = function (xlfString) { var parser = new xml2js.Parser();
return new Promise(function (resolve, reject) { var files = [];
var parser = new xml2js.Parser(); parser.parseString(xlfString, function (err, result) {
var files = []; if (err) {
parser.parseString(xlfString, function (err, result) { reject("Failed to parse XLIFF string. " + err);
if (err) {
reject("Failed to parse XLIFF string. " + err);
}
var fileNodes = result['xliff']['file'];
if (!fileNodes) {
reject('XLIFF file does not contain "xliff" or "file" node(s) required for parsing.');
}
fileNodes.forEach(function (file) {
var originalFilePath = file.$.original;
if (!originalFilePath) {
reject('XLIFF file node does not contain original attribute to determine the original location of the resource file.');
} }
var language = file.$['target-language'].toLowerCase(); var fileNodes = result['xliff']['file'];
if (!language) { if (!fileNodes) {
reject('XLIFF file node does not contain target-language attribute to determine translated language.'); reject('XLIFF file does not contain "xliff" or "file" node(s) required for parsing.');
} }
var messages = {}; fileNodes.forEach(function (file) {
var transUnits = file.body[0]['trans-unit']; var originalFilePath = file.$.original;
transUnits.forEach(function (unit) { if (!originalFilePath) {
var key = unit.$.id; reject('XLIFF file node does not contain original attribute to determine the original location of the resource file.');
if (!unit.target) {
return; // No translation available
}
var val = unit.target.toString();
if (key && val) {
messages[key] = decodeEntities(val);
} }
else { var language = file.$['target-language'].toLowerCase();
reject('XLIFF file does not contain full localization data. ID or target translation for one of the trans-unit nodes is not present.'); if (!language) {
reject('XLIFF file node does not contain target-language attribute to determine translated language.');
} }
var messages = {};
var transUnits = file.body[0]['trans-unit'];
transUnits.forEach(function (unit) {
var key = unit.$.id;
if (!unit.target) {
return; // No translation available
}
var val = unit.target.toString();
if (key && val) {
messages[key] = decodeEntities(val);
}
else {
reject('XLIFF file does not contain full localization data. ID or target translation for one of the trans-unit nodes is not present.');
}
});
files.push({ messages: messages, originalFilePath: originalFilePath, language: language });
}); });
files.push({ messages: messages, originalFilePath: originalFilePath, language: language }); resolve(files);
}); });
resolve(files);
}); });
}); };
}; return XLF;
}());
exports.XLF = XLF; exports.XLF = XLF;
var iso639_3_to_2 = { var iso639_3_to_2 = {
'chs': 'zh-cn', 'chs': 'zh-cn',
......
...@@ -51,6 +51,14 @@ var ImportPatterns = (function (_super) { ...@@ -51,6 +51,14 @@ var ImportPatterns = (function (_super) {
ImportPatterns.prototype.visitImportDeclaration = function (node) { ImportPatterns.prototype.visitImportDeclaration = function (node) {
this._validateImport(node.moduleSpecifier.getText(), node); this._validateImport(node.moduleSpecifier.getText(), node);
}; };
ImportPatterns.prototype.visitCallExpression = function (node) {
_super.prototype.visitCallExpression.call(this, node);
// import('foo') statements inside the code
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
var path = node.arguments[0];
this._validateImport(path.getText(), node);
}
};
ImportPatterns.prototype._validateImport = function (path, node) { ImportPatterns.prototype._validateImport = function (path, node) {
// remove quotes // remove quotes
path = path.slice(1, -1); path = path.slice(1, -1);
......
...@@ -45,6 +45,16 @@ class ImportPatterns extends Lint.RuleWalker { ...@@ -45,6 +45,16 @@ class ImportPatterns extends Lint.RuleWalker {
this._validateImport(node.moduleSpecifier.getText(), node); this._validateImport(node.moduleSpecifier.getText(), node);
} }
protected visitCallExpression(node: ts.CallExpression): void {
super.visitCallExpression(node);
// import('foo') statements inside the code
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
const [path] = node.arguments;
this._validateImport(path.getText(), node);
}
}
private _validateImport(path: string, node: ts.Node): void { private _validateImport(path: string, node: ts.Node): void {
// remove quotes // remove quotes
path = path.slice(1, -1); path = path.slice(1, -1);
......
...@@ -63,6 +63,14 @@ var LayeringRule = (function (_super) { ...@@ -63,6 +63,14 @@ var LayeringRule = (function (_super) {
LayeringRule.prototype.visitImportDeclaration = function (node) { LayeringRule.prototype.visitImportDeclaration = function (node) {
this._validateImport(node.moduleSpecifier.getText(), node); this._validateImport(node.moduleSpecifier.getText(), node);
}; };
LayeringRule.prototype.visitCallExpression = function (node) {
_super.prototype.visitCallExpression.call(this, node);
// import('foo') statements inside the code
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
var path = node.arguments[0];
this._validateImport(path.getText(), node);
}
};
LayeringRule.prototype._validateImport = function (path, node) { LayeringRule.prototype._validateImport = function (path, node) {
// remove quotes // remove quotes
path = path.slice(1, -1); path = path.slice(1, -1);
......
...@@ -61,6 +61,16 @@ class LayeringRule extends Lint.RuleWalker { ...@@ -61,6 +61,16 @@ class LayeringRule extends Lint.RuleWalker {
this._validateImport(node.moduleSpecifier.getText(), node); this._validateImport(node.moduleSpecifier.getText(), node);
} }
protected visitCallExpression(node: ts.CallExpression): void {
super.visitCallExpression(node);
// import('foo') statements inside the code
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
const [path] = node.arguments;
this._validateImport(path.getText(), node);
}
}
private _validateImport(path: string, node: ts.Node): void { private _validateImport(path: string, node: ts.Node): void {
// remove quotes // remove quotes
path = path.slice(1, -1); path = path.slice(1, -1);
......
...@@ -172,6 +172,6 @@ var NoUnexternalizedStringsRuleWalker = (function (_super) { ...@@ -172,6 +172,6 @@ var NoUnexternalizedStringsRuleWalker = (function (_super) {
node = parent; node = parent;
} }
}; };
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';
return NoUnexternalizedStringsRuleWalker; return NoUnexternalizedStringsRuleWalker;
}(Lint.RuleWalker)); }(Lint.RuleWalker));
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';
...@@ -74,6 +74,6 @@ var TranslationRemindRuleWalker = (function (_super) { ...@@ -74,6 +74,6 @@ var TranslationRemindRuleWalker = (function (_super) {
this.addFailureAtNode(node, "Please add '" + resource + "' to ./builds/lib/i18n.resources.json file to use translations here."); this.addFailureAtNode(node, "Please add '" + resource + "' to ./builds/lib/i18n.resources.json file to use translations here.");
} }
}; };
TranslationRemindRuleWalker.NLS_MODULE = 'vs/nls';
return TranslationRemindRuleWalker; return TranslationRemindRuleWalker;
}(Lint.RuleWalker)); }(Lint.RuleWalker));
TranslationRemindRuleWalker.NLS_MODULE = 'vs/nls';
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册