mirror of
https://github.com/Microsoft/vscode
synced 2024-08-24 19:46:05 +00:00
teach lint rules new dynamic import statements
This commit is contained in:
parent
cebe4943ae
commit
30ce2998fd
11
.vscode/tasks.json
vendored
11
.vscode/tasks.json
vendored
|
@ -32,7 +32,9 @@
|
|||
"type": "gulp",
|
||||
"task": "tslint",
|
||||
"label": "Run tslint",
|
||||
"problemMatcher": ["$tslint4"]
|
||||
"problemMatcher": [
|
||||
"$tslint4"
|
||||
]
|
||||
},
|
||||
{
|
||||
"taskName": "Run tests",
|
||||
|
@ -59,6 +61,11 @@
|
|||
"type": "gulp",
|
||||
"task": "electron",
|
||||
"label": "Download electron"
|
||||
},
|
||||
{
|
||||
"type": "gulp",
|
||||
"task": "hygiene",
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,50 +162,50 @@ var XLF = (function () {
|
|||
line.append(content);
|
||||
this.buffer.push(line.toString());
|
||||
};
|
||||
XLF.parse = function (xlfString) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var parser = new xml2js.Parser();
|
||||
var files = [];
|
||||
parser.parseString(xlfString, function (err, result) {
|
||||
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();
|
||||
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 });
|
||||
});
|
||||
resolve(files);
|
||||
});
|
||||
});
|
||||
};
|
||||
return XLF;
|
||||
}());
|
||||
XLF.parse = function (xlfString) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var parser = new xml2js.Parser();
|
||||
var files = [];
|
||||
parser.parseString(xlfString, function (err, result) {
|
||||
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();
|
||||
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 });
|
||||
});
|
||||
resolve(files);
|
||||
});
|
||||
});
|
||||
};
|
||||
exports.XLF = XLF;
|
||||
var iso639_3_to_2 = {
|
||||
'chs': 'zh-cn',
|
||||
|
|
|
@ -51,6 +51,14 @@ var ImportPatterns = (function (_super) {
|
|||
ImportPatterns.prototype.visitImportDeclaration = function (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) {
|
||||
// remove quotes
|
||||
path = path.slice(1, -1);
|
||||
|
|
|
@ -45,6 +45,16 @@ class ImportPatterns extends Lint.RuleWalker {
|
|||
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 {
|
||||
// remove quotes
|
||||
path = path.slice(1, -1);
|
||||
|
|
|
@ -63,6 +63,14 @@ var LayeringRule = (function (_super) {
|
|||
LayeringRule.prototype.visitImportDeclaration = function (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) {
|
||||
// remove quotes
|
||||
path = path.slice(1, -1);
|
||||
|
|
|
@ -61,6 +61,16 @@ class LayeringRule extends Lint.RuleWalker {
|
|||
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 {
|
||||
// remove quotes
|
||||
path = path.slice(1, -1);
|
||||
|
|
|
@ -172,6 +172,6 @@ var NoUnexternalizedStringsRuleWalker = (function (_super) {
|
|||
node = parent;
|
||||
}
|
||||
};
|
||||
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';
|
||||
return NoUnexternalizedStringsRuleWalker;
|
||||
}(Lint.RuleWalker));
|
||||
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
};
|
||||
TranslationRemindRuleWalker.NLS_MODULE = 'vs/nls';
|
||||
return TranslationRemindRuleWalker;
|
||||
}(Lint.RuleWalker));
|
||||
TranslationRemindRuleWalker.NLS_MODULE = 'vs/nls';
|
||||
|
|
Loading…
Reference in a new issue