UNPKG

rxjs-tslint-rules

Version:
56 lines (55 loc) 2.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Rule = void 0; var tslib_1 = require("tslib"); var tsquery_1 = require("@phenomnomnominal/tsquery"); var Lint = tslib_1.__importStar(require("tslint")); var tsutils = tslib_1.__importStar(require("tsutils")); var peer = tslib_1.__importStar(require("../support/peer")); var Rule = (function (_super) { tslib_1.__extends(Rule, _super); function Rule() { return _super !== null && _super.apply(this, arguments) || this; } Rule.prototype.apply = function (sourceFile) { var _this = this; var _a = tslib_1.__read(this.getOptions().ruleArguments, 1), options = _a[0]; var allowConfig = options && options.hasOwnProperty("allowConfig") ? options.allowConfig : false; var failures = []; var callIdentifiers = tsquery_1.tsquery(sourceFile, "CallExpression Identifier[name=\"shareReplay\"]"); callIdentifiers.forEach(function (identifier) { var fail = true; if (allowConfig) { var callExpression = identifier.parent; fail = callExpression.arguments.length !== 1 || !tsutils.isObjectLiteralExpression(callExpression.arguments[0]); } if (fail) { failures.push(new Lint.RuleFailure(sourceFile, identifier.getStart(), identifier.getStart() + identifier.getWidth(), Rule.FAILURE_STRING, _this.ruleName)); } }); return failures; }; Rule.metadata = { deprecationMessage: peer.v5 ? peer.v5NotSupportedMessage : undefined, description: "Disallows using the `shareReplay` operator.", options: { properties: { allowConfig: { type: "boolean" }, }, type: "object", }, optionsDescription: Lint.Utils.dedent(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["\n An optional object with an optional `allowConfig` property.\n If `allowConfig` is `true`, calls to `shareReplay` are allowed if a\n config object is passed - instead of separate parameters"], ["\n An optional object with an optional \\`allowConfig\\` property.\n If \\`allowConfig\\` is \\`true\\`, calls to \\`shareReplay\\` are allowed if a\n config object is passed - instead of separate parameters"]))), requiresTypeInfo: false, ruleName: "rxjs-no-sharereplay", type: "functionality", typescriptOnly: false, }; Rule.FAILURE_STRING = "shareReplay is forbidden"; return Rule; }(Lint.Rules.AbstractRule)); exports.Rule = Rule; var templateObject_1;