UNPKG

eslint-plugin-obsidian

Version:

ESLint rules for Obsidian

74 lines 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.File = void 0; const class_1 = require("./class"); const ast_1 = require("../utils/ast"); const import_1 = require("./import"); const classFile_1 = require("./classFile"); const assertions_1 = require("../utils/assertions"); const variable_1 = require("./variable"); class File { constructor(program, path) { this.program = program; this.path = path; } requireGraph(name) { const graph = this.classNodes.find((node) => { var _a; return ((_a = node === null || node === void 0 ? void 0 : node.id) === null || _a === void 0 ? void 0 : _a.name) === name; }); (0, assertions_1.assertDefined)(graph, `Graph ${name} not found in file`); return new class_1.Clazz(graph); } get classNodes() { return this.body .filter(ast_1.isClassLike) .map(ast_1.getClassDeclaration); } get body() { return this.program.body; } toClassWithImports() { return this.graphs.map((graph) => { return new classFile_1.ClassFile(graph, this.imports, this.path); }); } get imports() { return this.body .filter(ast_1.isImportDeclaration) .map((node) => new import_1.Import(node)); } get graphs() { return this.body .filter(ast_1.isClassLike) .map((node) => { const clazz = (0, ast_1.getClassDeclaration)(node); return clazz && new class_1.Clazz(clazz); }) .filter((clazz) => { return clazz ? clazz.isDecoratedWithIgnoreCase('Graph') : false; }); } findClass(byName) { const clazz = this.classes.find(($clazz) => $clazz.name === byName); return clazz && new classFile_1.ClassFile(clazz, this.imports, this.path); } get classes() { return this.body .filter(ast_1.isClassLike) .map((node) => { const clazz = (0, ast_1.getClassDeclaration)(node); return clazz && new class_1.Clazz(clazz); }) .filter(Boolean); } get variables() { return this.body .filter(ast_1.isVariableDeclaration) .map((node) => node.declarations) .flat() .map((node) => new variable_1.Variable(node)); } } exports.File = File; //# sourceMappingURL=file.js.map