UNPKG

rxjs-tslint-rules

Version:
51 lines (50 loc) 2.21 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 ts = tslib_1.__importStar(require("typescript")); 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.applyWithProgram = function (sourceFile, program) { var _this = this; var failures = []; var callExpressions = tsquery_1.tsquery(sourceFile, "CallExpression[expression.text=\"takeWhile\"]"); callExpressions.forEach(function (callExpression) { var fail = false; var _a = tslib_1.__read(callExpression.arguments, 1), arg = _a[0]; if (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) { var _b = tslib_1.__read(arg.parameters, 1), parameter = _b[0]; if (parameter) { var identifiers = tsquery_1.tsquery(arg, "Identifier[name=\"" + parameter.name.getText() + "\"]"); fail = identifiers.length < 2; } else { fail = true; } } if (fail) { failures.push(new Lint.RuleFailure(sourceFile, arg.getStart(), arg.getStart() + arg.getWidth(), Rule.FAILURE_STRING, _this.ruleName)); } }); return failures; }; Rule.metadata = { deprecationMessage: peer.v5 ? peer.v5NotSupportedMessage : undefined, description: "Disallows the ignoring of the `takeWhile` value.", options: null, optionsDescription: "Not configurable.", requiresTypeInfo: true, ruleName: "rxjs-no-ignored-takewhile-value", type: "functionality", typescriptOnly: true, }; Rule.FAILURE_STRING = "Ignoring the takeWhile value is forbidden"; return Rule; }(Lint.Rules.TypedRule)); exports.Rule = Rule;