UNPKG

rxjs-tslint-rules

Version:
53 lines (52 loc) 2.78 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 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 failures = []; var newIdentifiers = tsquery_1.tsquery(sourceFile, "NewExpression > Identifier[name=\"ReplaySubject\"]"); newIdentifiers.forEach(function (identifier) { var newExpression = identifier.parent; if (!newExpression.arguments || newExpression.arguments.length === 0) { failures.push(new Lint.RuleFailure(sourceFile, identifier.getStart(), identifier.getStart() + identifier.getWidth(), Rule.FAILURE_STRING, _this.ruleName)); } }); var nestedNewIdentitiers = tsquery_1.tsquery(sourceFile, "NewExpression PropertyAccessExpression Identifier[name=\"ReplaySubject\"]"); nestedNewIdentitiers.forEach(function (identifier) { var newExpression = identifier.parent.parent; if (!newExpression.arguments || newExpression.arguments.length === 0) { failures.push(new Lint.RuleFailure(sourceFile, identifier.getStart(), identifier.getStart() + identifier.getWidth(), Rule.FAILURE_STRING, _this.ruleName)); } }); var callIdentifiers = tsquery_1.tsquery(sourceFile, "CallExpression Identifier[name=/(publishReplay|shareReplay)/]"); callIdentifiers.forEach(function (identifier) { var callExpression = identifier.parent; if (callExpression.arguments.length === 0) { 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 `ReplaySubject`, `publishReplay` or `shareReplay` without specifying the buffer size.", options: null, optionsDescription: "Not configurable.", requiresTypeInfo: false, ruleName: "rxjs-no-ignored-replay-buffer", type: "functionality", typescriptOnly: false, }; Rule.FAILURE_STRING = "Ignoring the buffer size is forbidden"; return Rule; }(Lint.Rules.AbstractRule)); exports.Rule = Rule;