rxjs-tslint-rules
Version:
TSLint rules for RxJS
53 lines (52 loc) • 3.08 kB
JavaScript
;
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 tsutils = tslib_1.__importStar(require("tsutils"));
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 identifiers = [];
identifiers.push.apply(identifiers, tslib_1.__spreadArray([], tslib_1.__read(tsquery_1.tsquery(sourceFile, "CallExpression[expression.name.text=\"pipe\"] > CallExpression[typeArguments.length>0] > Identifier"))));
identifiers.push.apply(identifiers, tslib_1.__spreadArray([], tslib_1.__read(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.__spreadArray([], tslib_1.__read(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.__spreadArray([], tslib_1.__read(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;