UNPKG

rxjs-tslint-rules

Version:
64 lines (63 loc) 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Rule = void 0; var tslib_1 = require("tslib"); var Lint = tslib_1.__importStar(require("tslint")); var tsutils = tslib_1.__importStar(require("tsutils")); var used_walker_1 = require("../support/used-walker"); var Rule = (function (_super) { tslib_1.__extends(Rule, _super); function Rule() { return _super !== null && _super.apply(this, arguments) || this; } Rule.prototype.applyWithProgram = function (sourceFile, program) { return this.applyWithWalker(new Walker(sourceFile, this.getOptions(), program)); }; Rule.metadata = { description: "Disallows the use of the do operator.", options: null, optionsDescription: "Not configurable.", requiresTypeInfo: true, ruleName: "rxjs-no-do", type: "functionality", typescriptOnly: true, }; Rule.FAILURE_STRING = "RxJS do/tap operator is forbidden"; return Rule; }(Lint.Rules.TypedRule)); exports.Rule = Rule; var Walker = (function (_super) { tslib_1.__extends(Walker, _super); function Walker() { return _super !== null && _super.apply(this, arguments) || this; } Walker.prototype.visitImportDeclaration = function (node) { var _this = this; var moduleSpecifier = node.moduleSpecifier.getText(); if (/^['"]rxjs\/operators?/.test(moduleSpecifier)) { if (tsutils.isNamedImports(node.importClause.namedBindings)) { node.importClause.namedBindings.elements.forEach(function (binding) { _this.validateName(binding.propertyName || binding.name); }); } } else if (/^['"]rxjs\/add\/operator\/do['"]/.test(moduleSpecifier)) { this.addFailureAtNode(node.moduleSpecifier, Rule.FAILURE_STRING); } _super.prototype.visitImportDeclaration.call(this, node); }; Walker.prototype.onSourceFileEnd = function () { var _this = this; if (this.usedOperators["do"]) { this.usedOperators["do"].forEach(function (node) { return _this.addFailureAtNode(node, Rule.FAILURE_STRING); }); } }; Walker.prototype.validateName = function (name) { if (/^(_do|tap)$/.test(name.getText())) { this.addFailureAtNode(name, Rule.FAILURE_STRING); } }; return Walker; }(used_walker_1.UsedWalker));