| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- "use strict";
- var __extends = (this && this.__extends) || function (d, b) {
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- };
- var ts = require("typescript");
- var Lint = require("../lint");
- var Rule = (function (_super) {
- __extends(Rule, _super);
- function Rule() {
- _super.apply(this, arguments);
- }
- Rule.prototype.apply = function (sourceFile) {
- var options = this.getOptions();
- var banFunctionWalker = new BanFunctionWalker(sourceFile, options);
- var functionsToBan = options.ruleArguments;
- functionsToBan.forEach(function (f) { return banFunctionWalker.addBannedFunction(f); });
- return this.applyWithWalker(banFunctionWalker);
- };
- Rule.FAILURE_STRING_PART = "function invocation disallowed: ";
- return Rule;
- }(Lint.Rules.AbstractRule));
- exports.Rule = Rule;
- var BanFunctionWalker = (function (_super) {
- __extends(BanFunctionWalker, _super);
- function BanFunctionWalker() {
- _super.apply(this, arguments);
- this.bannedFunctions = [];
- }
- BanFunctionWalker.prototype.addBannedFunction = function (bannedFunction) {
- this.bannedFunctions.push(bannedFunction);
- };
- BanFunctionWalker.prototype.visitCallExpression = function (node) {
- var expression = node.expression;
- if (expression.kind === ts.SyntaxKind.PropertyAccessExpression
- && expression.getChildCount() >= 3) {
- var firstToken = expression.getFirstToken();
- var secondToken = expression.getChildAt(1);
- var thirdToken = expression.getChildAt(2);
- var firstText = firstToken.getText();
- var thirdText = thirdToken.getFullText();
- if (secondToken.kind === ts.SyntaxKind.DotToken) {
- for (var _i = 0, _a = this.bannedFunctions; _i < _a.length; _i++) {
- var bannedFunction = _a[_i];
- if (firstText === bannedFunction[0] && thirdText === bannedFunction[1]) {
- var failure = this.createFailure(expression.getStart(), expression.getWidth(), "" + Rule.FAILURE_STRING_PART + firstText + "." + thirdText);
- this.addFailure(failure);
- }
- }
- }
- }
- _super.prototype.visitCallExpression.call(this, node);
- };
- return BanFunctionWalker;
- }(Lint.RuleWalker));
- exports.BanFunctionWalker = BanFunctionWalker;
|