Skip to content

Commit 30ce299

Browse files
committed
teach lint rules new dynamic import statements
1 parent cebe494 commit 30ce299

8 files changed

Lines changed: 84 additions & 41 deletions

File tree

.vscode/tasks.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"type": "gulp",
3333
"task": "tslint",
3434
"label": "Run tslint",
35-
"problemMatcher": ["$tslint4"]
35+
"problemMatcher": [
36+
"$tslint4"
37+
]
3638
},
3739
{
3840
"taskName": "Run tests",
@@ -59,6 +61,11 @@
5961
"type": "gulp",
6062
"task": "electron",
6163
"label": "Download electron"
64+
},
65+
{
66+
"type": "gulp",
67+
"task": "hygiene",
68+
"problemMatcher": []
6269
}
6370
]
64-
}
71+
}

build/lib/i18n.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -162,50 +162,50 @@ var XLF = (function () {
162162
line.append(content);
163163
this.buffer.push(line.toString());
164164
};
165-
return XLF;
166-
}());
167-
XLF.parse = function (xlfString) {
168-
return new Promise(function (resolve, reject) {
169-
var parser = new xml2js.Parser();
170-
var files = [];
171-
parser.parseString(xlfString, function (err, result) {
172-
if (err) {
173-
reject("Failed to parse XLIFF string. " + err);
174-
}
175-
var fileNodes = result['xliff']['file'];
176-
if (!fileNodes) {
177-
reject('XLIFF file does not contain "xliff" or "file" node(s) required for parsing.');
178-
}
179-
fileNodes.forEach(function (file) {
180-
var originalFilePath = file.$.original;
181-
if (!originalFilePath) {
182-
reject('XLIFF file node does not contain original attribute to determine the original location of the resource file.');
165+
XLF.parse = function (xlfString) {
166+
return new Promise(function (resolve, reject) {
167+
var parser = new xml2js.Parser();
168+
var files = [];
169+
parser.parseString(xlfString, function (err, result) {
170+
if (err) {
171+
reject("Failed to parse XLIFF string. " + err);
183172
}
184-
var language = file.$['target-language'].toLowerCase();
185-
if (!language) {
186-
reject('XLIFF file node does not contain target-language attribute to determine translated language.');
173+
var fileNodes = result['xliff']['file'];
174+
if (!fileNodes) {
175+
reject('XLIFF file does not contain "xliff" or "file" node(s) required for parsing.');
187176
}
188-
var messages = {};
189-
var transUnits = file.body[0]['trans-unit'];
190-
transUnits.forEach(function (unit) {
191-
var key = unit.$.id;
192-
if (!unit.target) {
193-
return; // No translation available
194-
}
195-
var val = unit.target.toString();
196-
if (key && val) {
197-
messages[key] = decodeEntities(val);
177+
fileNodes.forEach(function (file) {
178+
var originalFilePath = file.$.original;
179+
if (!originalFilePath) {
180+
reject('XLIFF file node does not contain original attribute to determine the original location of the resource file.');
198181
}
199-
else {
200-
reject('XLIFF file does not contain full localization data. ID or target translation for one of the trans-unit nodes is not present.');
182+
var language = file.$['target-language'].toLowerCase();
183+
if (!language) {
184+
reject('XLIFF file node does not contain target-language attribute to determine translated language.');
201185
}
186+
var messages = {};
187+
var transUnits = file.body[0]['trans-unit'];
188+
transUnits.forEach(function (unit) {
189+
var key = unit.$.id;
190+
if (!unit.target) {
191+
return; // No translation available
192+
}
193+
var val = unit.target.toString();
194+
if (key && val) {
195+
messages[key] = decodeEntities(val);
196+
}
197+
else {
198+
reject('XLIFF file does not contain full localization data. ID or target translation for one of the trans-unit nodes is not present.');
199+
}
200+
});
201+
files.push({ messages: messages, originalFilePath: originalFilePath, language: language });
202202
});
203-
files.push({ messages: messages, originalFilePath: originalFilePath, language: language });
203+
resolve(files);
204204
});
205-
resolve(files);
206205
});
207-
});
208-
};
206+
};
207+
return XLF;
208+
}());
209209
exports.XLF = XLF;
210210
var iso639_3_to_2 = {
211211
'chs': 'zh-cn',

build/lib/tslint/importPatternsRule.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ var ImportPatterns = (function (_super) {
5151
ImportPatterns.prototype.visitImportDeclaration = function (node) {
5252
this._validateImport(node.moduleSpecifier.getText(), node);
5353
};
54+
ImportPatterns.prototype.visitCallExpression = function (node) {
55+
_super.prototype.visitCallExpression.call(this, node);
56+
// import('foo') statements inside the code
57+
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
58+
var path = node.arguments[0];
59+
this._validateImport(path.getText(), node);
60+
}
61+
};
5462
ImportPatterns.prototype._validateImport = function (path, node) {
5563
// remove quotes
5664
path = path.slice(1, -1);

build/lib/tslint/importPatternsRule.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ class ImportPatterns extends Lint.RuleWalker {
4545
this._validateImport(node.moduleSpecifier.getText(), node);
4646
}
4747

48+
protected visitCallExpression(node: ts.CallExpression): void {
49+
super.visitCallExpression(node);
50+
51+
// import('foo') statements inside the code
52+
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
53+
const [path] = node.arguments;
54+
this._validateImport(path.getText(), node);
55+
}
56+
}
57+
4858
private _validateImport(path: string, node: ts.Node): void {
4959
// remove quotes
5060
path = path.slice(1, -1);

build/lib/tslint/layeringRule.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ var LayeringRule = (function (_super) {
6363
LayeringRule.prototype.visitImportDeclaration = function (node) {
6464
this._validateImport(node.moduleSpecifier.getText(), node);
6565
};
66+
LayeringRule.prototype.visitCallExpression = function (node) {
67+
_super.prototype.visitCallExpression.call(this, node);
68+
// import('foo') statements inside the code
69+
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
70+
var path = node.arguments[0];
71+
this._validateImport(path.getText(), node);
72+
}
73+
};
6674
LayeringRule.prototype._validateImport = function (path, node) {
6775
// remove quotes
6876
path = path.slice(1, -1);

build/lib/tslint/layeringRule.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ class LayeringRule extends Lint.RuleWalker {
6161
this._validateImport(node.moduleSpecifier.getText(), node);
6262
}
6363

64+
protected visitCallExpression(node: ts.CallExpression): void {
65+
super.visitCallExpression(node);
66+
67+
// import('foo') statements inside the code
68+
if (node.expression.kind === ts.SyntaxKind.ImportKeyword) {
69+
const [path] = node.arguments;
70+
this._validateImport(path.getText(), node);
71+
}
72+
}
73+
6474
private _validateImport(path: string, node: ts.Node): void {
6575
// remove quotes
6676
path = path.slice(1, -1);

build/lib/tslint/noUnexternalizedStringsRule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,6 @@ var NoUnexternalizedStringsRuleWalker = (function (_super) {
172172
node = parent;
173173
}
174174
};
175+
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';
175176
return NoUnexternalizedStringsRuleWalker;
176177
}(Lint.RuleWalker));
177-
NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE = '"';

build/lib/tslint/translationRemindRule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ var TranslationRemindRuleWalker = (function (_super) {
7474
this.addFailureAtNode(node, "Please add '" + resource + "' to ./builds/lib/i18n.resources.json file to use translations here.");
7575
}
7676
};
77+
TranslationRemindRuleWalker.NLS_MODULE = 'vs/nls';
7778
return TranslationRemindRuleWalker;
7879
}(Lint.RuleWalker));
79-
TranslationRemindRuleWalker.NLS_MODULE = 'vs/nls';

0 commit comments

Comments
 (0)