UNPKG

rxjs-tslint-rules

Version:
62 lines (61 loc) 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Walker = exports.Rule = void 0; var tslib_1 = require("tslib"); var Lint = tslib_1.__importStar(require("tslint")); var tsutils = tslib_1.__importStar(require("tsutils")); 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) { return this.applyWithWalker(new Walker(sourceFile, this.getOptions(), program)); }; Rule.metadata = { description: "Disallows accessing the value property of a BehaviorSubject instance.", options: null, optionsDescription: "Not configurable.", requiresTypeInfo: true, ruleName: "rxjs-no-subject-value", type: "functionality", typescriptOnly: true, }; Rule.FAILURE_STRING = "Accessing the value property of a BehaviorSubject is 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.visitCallExpression = function (node) { var expression = node.expression; if (tsutils.isPropertyAccessExpression(expression)) { var name_1 = expression.name.getText(); var typeChecker = this.getTypeChecker(); var type = typeChecker.getTypeAtLocation(expression.expression); if (name_1 === "getValue" && util_1.isReferenceType(type) && util_1.couldBeType(type.target, "BehaviorSubject")) { this.addFailureAtNode(expression.name, Rule.FAILURE_STRING); } } _super.prototype.visitCallExpression.call(this, node); }; Walker.prototype.visitPropertyAccessExpression = function (node) { var name = node.name.getText(); var typeChecker = this.getTypeChecker(); var type = typeChecker.getTypeAtLocation(node.expression); if (name === "value" && util_1.isReferenceType(type) && util_1.couldBeType(type.target, "BehaviorSubject")) { this.addFailureAtNode(node.name, Rule.FAILURE_STRING); } _super.prototype.visitPropertyAccessExpression.call(this, node); }; return Walker; }(Lint.ProgramAwareRuleWalker)); exports.Walker = Walker;