UNPKG

eslint-plugin-obsidian

Version:

ESLint rules for Obsidian

59 lines 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Clazz = void 0; const decorator_1 = require("./decorator"); const assertions_1 = require("../utils/assertions"); const ast_1 = require("../utils/ast"); const method_1 = require("./method"); const identifier_1 = require("./identifier"); class Clazz { constructor(node) { this.node = node; (0, assertions_1.assertDefined)(this.node); } get isAbstract() { return this.node.abstract; } isDecoratedWithIgnoreCase(decoratorName) { return this.decoratorNames.some(name => name.toLowerCase() === decoratorName.toLowerCase()); } get decoratorNames() { return this.decorators.map((decorator) => { return decorator.expression.callee.name; }) || []; } get decorators() { var _a; return ((_a = this.node.decorators) !== null && _a !== void 0 ? _a : []).map((decorator) => { return new decorator_1.Decorator(decorator); }); } get superClass() { return this.node.superClass && new identifier_1.Identifier(this.node.superClass).name; } get body() { return this.node.body.body; } mapDecoratedMethods(decoratorName, mapper) { return this.getDecoratedMethods(decoratorName).map(mapper); } getDecoratedMethods(decoratorName) { return this.body .filter(ast_1.isMethodDefinition) .map((node) => new method_1.Method(node)) .filter(method => method.isDecoratedWithIgnoreCase(decoratorName)); } requireDecoratorIgnoreCase(name) { const decorator = this.decorators.find(($decorator) => { return $decorator.expression.callee.name.toLowerCase() === name.toLowerCase(); }); (0, assertions_1.assertDefined)(decorator, `Decorator ${name} not found on class ${this.name}`); return decorator; } get name() { var _a; return (_a = this.node.id) === null || _a === void 0 ? void 0 : _a.name; } } exports.Clazz = Clazz; //# sourceMappingURL=class.js.map