rxjs-tslint-rules
Version:
TSLint rules for RxJS
51 lines (50 loc) • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Lint = require("tslint");
var tsutils = 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 the calling of subscribe without specifying arguments.",
options: null,
optionsDescription: "Not configurable.",
requiresTypeInfo: true,
ruleName: "rxjs-no-ignored-subscribe",
type: "functionality",
typescriptOnly: true
};
Rule.FAILURE_STRING = "Calling subscribe without arguments 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 === "subscribe" &&
util_1.isReferenceType(type) &&
util_1.couldBeType(type, "Observable") &&
node.arguments.length === 0) {
this.addFailureAtNode(expression.name, Rule.FAILURE_STRING);
}
}
_super.prototype.visitCallExpression.call(this, node);
};
return Walker;
}(Lint.ProgramAwareRuleWalker));
exports.Walker = Walker;