UNPKG

rxjs-tslint-rules

Version:
41 lines (40 loc) 1.8 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 callExpressions = tsquery_1.tsquery(sourceFile, "ExpressionStatement > CallExpression"); callExpressions.forEach(function (callExpression) { var type = typeChecker.getTypeAtLocation(callExpression); if (util_1.couldBeType(type, "Observable")) { failures.push(new Lint.RuleFailure(sourceFile, callExpression.getStart(), callExpression.getStart() + callExpression.getWidth(), Rule.FAILURE_STRING, _this.ruleName)); } }); return failures; }; Rule.metadata = { deprecationMessage: peer.v5 ? peer.v5NotSupportedMessage : undefined, description: "Disallows the ignoring of observables returned by functions.", options: null, optionsDescription: "Not configurable.", requiresTypeInfo: true, ruleName: "rxjs-no-ignored-observable", type: "functionality", typescriptOnly: true, }; Rule.FAILURE_STRING = "Ignoring a returned Observable is forbidden"; return Rule; }(Lint.Rules.TypedRule)); exports.Rule = Rule;