UNPKG

rxjs-tslint-rules

Version:
98 lines (97 loc) 4.47 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 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 calling of patched methods.", options: { properties: { allowObservables: { oneOf: [ { type: "boolean" }, { type: "array", items: { type: "string" } }, ], }, allowOperators: { oneOf: [ { type: "boolean" }, { type: "array", items: { type: "string" } }, ], }, }, type: "object", }, optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n An optional object with the optional properties `allowObservables` and `allowOperators`.\n The properties can be specifed as booleans (they default to `false`) or as arrays containing\n the names of the observables or operators that are allowed."], ["\n An optional object with the optional properties \\`allowObservables\\` and \\`allowOperators\\`.\n The properties can be specifed as booleans (they default to \\`false\\`) or as arrays containing\n the names of the observables or operators that are allowed."]))), requiresTypeInfo: true, ruleName: "rxjs-no-patched", type: "functionality", typescriptOnly: true, }; Rule.FAILURE_STRING = "RxJS patched methods are 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.onSourceFileEnd = function () { var _this = this; var allowAllObservables = false; var allowAllOperators = false; var allowedObservables = []; var allowedOperators = []; var _a = tslib_1.__read(this.getOptions(), 1), options = _a[0]; if (options) { if (options.hasOwnProperty("allowObservables")) { if (typeof options.allowObservables.length === "number") { allowedObservables = options.allowObservables; } else { allowAllObservables = Boolean(options.allowObservables); } } if (options.hasOwnProperty("allowOperators")) { if (typeof options.allowOperators.length === "number") { allowedOperators = options.allowOperators; } else { allowAllOperators = Boolean(options.allowOperators); } } } if (!allowAllObservables) { Object.keys(this.usedObservables).forEach(function (key) { if (allowedObservables.indexOf(key) === -1) { _this.usedObservables[key].forEach(function (node) { return _this.addFailureAtNode(node, Rule.FAILURE_STRING + ": " + key); }); } }); } if (!allowAllOperators) { Object.keys(this.usedOperators).forEach(function (key) { if (allowedOperators.indexOf(key) === -1) { _this.usedOperators[key].forEach(function (node) { return _this.addFailureAtNode(node, Rule.FAILURE_STRING + ": " + key); }); } }); } }; return Walker; }(used_walker_1.UsedWalker)); var templateObject_1;