UNPKG

rxjs-tslint-rules

Version:
98 lines (97 loc) 4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Rule = void 0; var tslib_1 = require("tslib"); var Lint = tslib_1.__importStar(require("tslint")); var tsutils = tslib_1.__importStar(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 use of Finnish notation.", options: null, optionsDescription: "Not configurable.", requiresTypeInfo: true, ruleName: "rxjs-no-finnish", type: "style", typescriptOnly: true, }; Rule.FAILURE_STRING = "Finnish notation 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.visitFunctionDeclaration = function (node) { this.validateNode(node, node.type); _super.prototype.visitFunctionDeclaration.call(this, node); }; Walker.prototype.visitFunctionExpression = function (node) { this.validateNode(node, node.type); _super.prototype.visitFunctionExpression.call(this, node); }; Walker.prototype.visitGetAccessor = function (node) { this.validateNode(node); _super.prototype.visitGetAccessor.call(this, node); }; Walker.prototype.visitMethodDeclaration = function (node) { this.validateNode(node, node.type); _super.prototype.visitMethodDeclaration.call(this, node); }; Walker.prototype.visitMethodSignature = function (node) { this.validateNode(node, node.type); _super.prototype.visitMethodSignature.call(this, node); }; Walker.prototype.visitObjectLiteralExpression = function (node) { var _this = this; node.properties.forEach(function (property) { if (property.name && !tsutils.isComputedPropertyName(property.name)) { _this.validateNode(property); } }); _super.prototype.visitObjectLiteralExpression.call(this, node); }; Walker.prototype.visitParameterDeclaration = function (node) { this.validateNode(node); _super.prototype.visitParameterDeclaration.call(this, node); }; Walker.prototype.visitPropertyDeclaration = function (node) { this.validateNode(node); _super.prototype.visitPropertyDeclaration.call(this, node); }; Walker.prototype.visitPropertySignature = function (node) { this.validateNode(node); _super.prototype.visitPropertySignature.call(this, node); }; Walker.prototype.visitSetAccessor = function (node) { this.validateNode(node); _super.prototype.visitSetAccessor.call(this, node); }; Walker.prototype.visitVariableDeclarationList = function (node) { var _this = this; tsutils.forEachDeclaredVariable(node, function (variable) { _this.validateNode(variable); }); _super.prototype.visitVariableDeclarationList.call(this, node); }; Walker.prototype.validateNode = function (node, typeNode) { var name = node.name; if (name) { var text = name.getText(); var type = this.getTypeChecker().getTypeAtLocation(typeNode || node); if (/\$$/.test(text) && util_1.couldBeType(type, "Observable")) { this.addFailureAtNode(name, Rule.FAILURE_STRING); } } }; return Walker; }(Lint.ProgramAwareRuleWalker));