UNPKG

rxjs-tslint-rules

Version:
50 lines (49 loc) 2.16 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 peer = tslib_1.__importStar(require("../support/peer")); var util_1 = require("../support/util"); 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) { var _this = this; var failures = []; var typeChecker = program.getTypeChecker(); var callIdentifiers = tsquery_1.tsquery(sourceFile, "CallExpression Identifier[name=/^(multicast|publish|publishBehavior|publishLast|publishReplay)$/]"); callIdentifiers.forEach(function (identifier) { var callExpression = identifier.parent; var fail = false; if (identifier.getText() === "multicast") { fail = callExpression.arguments.length === 1; } else { fail = !callExpression.arguments.some(function (arg) { return util_1.couldBeFunction(typeChecker.getTypeAtLocation(arg)); }); } 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 operators that return connectable observables.", options: null, optionsDescription: "Not configurable.", requiresTypeInfo: true, ruleName: "rxjs-no-connectable", type: "functionality", typescriptOnly: true, }; Rule.FAILURE_STRING = "Connectable observables are forbidden"; return Rule; }(Lint.Rules.TypedRule)); exports.Rule = Rule;