eslint-plugin-obsidian
Version:
ESLint rules for Obsidian
92 lines • 3.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isClassLike = isClassLike;
exports.isTypeReference = isTypeReference;
exports.isTypeLiteral = isTypeLiteral;
exports.isImportDeclaration = isImportDeclaration;
exports.isMethodDefinition = isMethodDefinition;
exports.getClassDeclaration = getClassDeclaration;
exports.requireProgram = requireProgram;
exports.getDecoratorProperty = getDecoratorProperty;
exports.mapArrayExpression = mapArrayExpression;
exports.isTypeIntersection = isTypeIntersection;
exports.isTypeAnnotation = isTypeAnnotation;
exports.isAnyType = isAnyType;
exports.isVariableDeclaration = isVariableDeclaration;
const types_1 = require("@typescript-eslint/types");
const assertions_1 = require("./assertions");
function isClassLike(node) {
switch (node.type) {
case types_1.AST_NODE_TYPES.ClassDeclaration:
return true;
case types_1.AST_NODE_TYPES.ExportDefaultDeclaration:
return isClassLike(node.declaration);
case types_1.AST_NODE_TYPES.ExportNamedDeclaration:
return isClassLike(node.declaration);
default:
return false;
}
}
function isTypeReference(node) {
return (node === null || node === void 0 ? void 0 : node.type) === types_1.AST_NODE_TYPES.TSTypeReference;
}
function isTypeLiteral(node) {
return node.type === types_1.AST_NODE_TYPES.TSTypeLiteral;
}
function isImportDeclaration(node) {
return node.type === types_1.AST_NODE_TYPES.ImportDeclaration;
}
function isMethodDefinition(node) {
return node.type === types_1.AST_NODE_TYPES.MethodDefinition;
}
function getClassDeclaration(node) {
switch (node.type) {
case types_1.AST_NODE_TYPES.ClassDeclaration:
return node;
case types_1.AST_NODE_TYPES.ExportDefaultDeclaration:
return getClassDeclaration(node.declaration);
case types_1.AST_NODE_TYPES.ExportNamedDeclaration:
return getClassDeclaration(node.declaration);
default:
return undefined;
}
}
function requireProgram(node) {
(0, assertions_1.assertDefined)(node);
switch (node.type) {
case types_1.AST_NODE_TYPES.Program:
return node;
default:
return requireProgram(node.parent);
}
}
function getDecoratorProperty(decorator, propertyName) {
const expression = decorator.expression;
const property = expression.arguments.map((argument) => {
return getObjectProperty(argument, propertyName);
})[0];
return property;
}
function getObjectProperty(obj, propertyName) {
return obj.properties.find((property) => {
return property.type === types_1.AST_NODE_TYPES.Property
&& property.key.type === types_1.AST_NODE_TYPES.Identifier
&& property.key.name === propertyName;
});
}
function mapArrayExpression(array, map) {
return array.elements.map(map);
}
function isTypeIntersection(node) {
return (node === null || node === void 0 ? void 0 : node.type) === types_1.AST_NODE_TYPES.TSIntersectionType;
}
function isTypeAnnotation(node) {
return (node === null || node === void 0 ? void 0 : node.type) === types_1.AST_NODE_TYPES.TSTypeAnnotation;
}
function isAnyType(node) {
return (node === null || node === void 0 ? void 0 : node.type) === types_1.AST_NODE_TYPES.TSAnyKeyword;
}
function isVariableDeclaration(node) {
return node.type === types_1.AST_NODE_TYPES.VariableDeclaration;
}
//# sourceMappingURL=ast.js.map