UNPKG

rxjs-tslint-rules

Version:
52 lines (51 loc) 2.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var tsquery_1 = require("@phenomnomnominal/tsquery"); var Lint = require("tslint"); var tsutils = require("tsutils"); var peer = 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 identifiers = []; identifiers.push.apply(identifiers, tslib_1.__spread(tsquery_1.tsquery(sourceFile, "CallExpression[expression.name.text=\"pipe\"] > CallExpression[typeArguments.length>0] > Identifier"))); identifiers.push.apply(identifiers, tslib_1.__spread(tsquery_1.tsquery(sourceFile, "CallExpression[typeArguments.length>0] > Identifier[name=/^(from|of)$/]"))); var behaviourSubjectIdentifiers = tsquery_1.tsquery(sourceFile, "NewExpression[typeArguments.length>0] > Identifier[name=\"BehaviorSubject\"]"); identifiers.push.apply(identifiers, tslib_1.__spread(behaviourSubjectIdentifiers.filter(function (identifier) { var newExpression = identifier.parent; var _a = tslib_1.__read(newExpression.arguments, 1), arg = _a[0]; return (!tsutils.isArrayLiteralExpression(arg) && !tsutils.isObjectLiteralExpression(arg)); }))); var notificationIdentifiers = tsquery_1.tsquery(sourceFile, "NewExpression[typeArguments.length>0] > Identifier[name=\"Notification\"]"); identifiers.push.apply(identifiers, tslib_1.__spread(notificationIdentifiers.filter(function (identifier) { var newExpression = identifier.parent; var _a = tslib_1.__read(newExpression.arguments, 2), kind = _a[0], value = _a[1]; return (tsutils.isStringLiteral(kind) && kind.text === "N" && !tsutils.isArrayLiteralExpression(value) && !tsutils.isObjectLiteralExpression(value)); }))); return identifiers.map(function (identifier) { return new Lint.RuleFailure(sourceFile, identifier.getStart(), identifier.getStart() + identifier.getWidth(), Rule.FAILURE_STRING, _this.ruleName); }); }; Rule.metadata = { deprecationMessage: peer.v5 ? peer.v5NotSupportedMessage : undefined, description: "Disallows explicit generic type arguments.", options: null, optionsDescription: "Not configurable.", requiresTypeInfo: false, ruleName: "rxjs-no-explicit-generics", type: "functionality", typescriptOnly: true }; Rule.FAILURE_STRING = "Explicit generic type arguments are forbidden"; return Rule; }(Lint.Rules.AbstractRule)); exports.Rule = Rule;