UNPKG

rxjs-tslint-rules

Version:
55 lines (54 loc) 2.38 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 peer = tslib_1.__importStar(require("../support/peer")); 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 = { deprecationMessage: peer.v6 && !peer.compat ? peer.v6NotNeededMessage : undefined, description: "Disallows the importation of patched observables or operators that are not used in the module.", options: null, optionsDescription: "Not configurable.", requiresTypeInfo: true, ruleName: "rxjs-no-unused-add", type: "maintainability", typescriptOnly: true, }; Rule.FAILURE_STRING = "RxJS add import is unused"; 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.onSourceFileEnd = function () { var _this = this; Object.keys(this.addedObservables).forEach(function (key) { if (!_this.usedObservables[key]) { _this.addedObservables[key].forEach(function (node) { return _this.addFailureAtNode(tsutils.isImportDeclaration(node) ? node.moduleSpecifier : node, Rule.FAILURE_STRING + ": " + key); }); } }); Object.keys(this.addedOperators).forEach(function (key) { if (!_this.usedOperators[key]) { _this.addedOperators[key].forEach(function (node) { return _this.addFailureAtNode(tsutils.isImportDeclaration(node) ? node.moduleSpecifier : node, Rule.FAILURE_STRING + ": " + key); }); } }); }; return Walker; }(used_walker_1.UsedWalker));