UNPKG

2.11 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || function (d, b) {
2 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3 function __() { this.constructor = d; }
4 __.prototype = b.prototype;
5 d.prototype = new __();
6};
7var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
8var AstUtils = require('./utils/AstUtils');
9var Rule = (function (_super) {
10 __extends(Rule, _super);
11 function Rule() {
12 _super.apply(this, arguments);
13 }
14 Rule.prototype.apply = function (sourceFile) {
15 var documentRegistry = ts.createDocumentRegistry();
16 var languageServiceHost = Lint.createLanguageServiceHost('file.ts', sourceFile.getFullText());
17 var languageService = ts.createLanguageService(languageServiceHost, documentRegistry);
18 return this.applyWithWalker(new NoFunctionConstructorWithStringArgsWalker(sourceFile, this.getOptions(), languageService));
19 };
20 Rule.FAILURE_STRING = 'forbidden: Function constructor with string arguments ';
21 return Rule;
22})(Lint.Rules.AbstractRule);
23exports.Rule = Rule;
24var NoFunctionConstructorWithStringArgsWalker = (function (_super) {
25 __extends(NoFunctionConstructorWithStringArgsWalker, _super);
26 function NoFunctionConstructorWithStringArgsWalker(sourceFile, options, languageServices) {
27 _super.call(this, sourceFile, options);
28 this.languageService = languageServices;
29 this.typeChecker = this.languageService.getProgram().getTypeChecker();
30 }
31 NoFunctionConstructorWithStringArgsWalker.prototype.visitNewExpression = function (node) {
32 var functionName = AstUtils.getFunctionName(node);
33 if (functionName === 'Function') {
34 if (node.arguments.length > 0) {
35 this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
36 }
37 }
38 _super.prototype.visitNewExpression.call(this, node);
39 };
40 return NoFunctionConstructorWithStringArgsWalker;
41})(ErrorTolerantWalker);
42//# sourceMappingURL=noFunctionConstructorWithStringArgsRule.js.map
\No newline at end of file