UNPKG

@addon24/eslint-config

Version:

ESLint configuration rules for WorldOfTextcraft projects - Centralized configuration for all project types

99 lines (89 loc) 3.6 kB
/** * ESLint-Regel: DTO Namenskonvention * * Diese Regel stellt sicher, dass: * 1. DTOs im dto/Entity Ordner mit "EntityDto" enden * 2. "EntityEntityDto" ist verboten (doppeltes Entity) * 3. Andere DTO-Typen (Request, Response, etc.) haben ihre eigenen Konventionen */ export default { meta: { type: "problem", docs: { description: "DTOs im dto/Entity Ordner müssen mit 'EntityDto' enden, aber nicht 'EntityEntityDto'", category: "Best Practices", recommended: true, }, fixable: null, schema: [], messages: { entityDtoMustEndWithEntityDto: "DTO im dto/Entity Ordner muss mit 'EntityDto' enden, nicht '{{currentName}}'. Erwartet: '{{expectedName}}'", entityDtoCannotHaveDoubleEntity: "DTO im dto/Entity Ordner darf nicht 'EntityEntityDto' enthalten. Verwende '{{suggestedName}}'", nonEntityDtoCannotEndWithEntityDto: "DTO außerhalb des dto/Entity Ordners darf nicht mit 'EntityDto' enden. Verwende '{{suggestedName}}'", }, }, create(context) { const filename = context.getFilename(); // Prüfe, ob es sich um einen dto/Entity Ordner handelt const isEntityDtoFolder = filename.includes("/dto/Entity/"); // Prüfe, ob es sich um andere DTO-Ordner handelt const isRequestDtoFolder = filename.includes("/dto/Request/"); const isResponseDtoFolder = filename.includes("/dto/Response/"); const isFilterDtoFolder = filename.includes("/dto/Filter/"); const isCommonDtoFolder = filename.includes("/dto/Common/"); return { ExportDefaultDeclaration(node) { // Prüfe nur, wenn es sich um eine Klassendeklaration handelt if (node.declaration.type === "ClassDeclaration") { const className = node.declaration.id?.name; if (!className) { return; // Anonyme Klassen ignorieren } // DTOs im dto/Entity Ordner if (isEntityDtoFolder) { // Prüfe auf doppeltes "Entity" (EntityEntityDto) if (className.includes("EntityEntityDto")) { const suggestedName = className.replace("EntityEntityDto", "EntityDto"); context.report({ node: node.declaration.id, messageId: "entityDtoCannotHaveDoubleEntity", data: { suggestedName, }, }); return; } // Prüfe, ob die Klasse mit "EntityDto" endet if (!className.endsWith("EntityDto")) { const expectedName = className.endsWith("Dto") ? className.replace("Dto", "EntityDto") : className + "EntityDto"; context.report({ node: node.declaration.id, messageId: "entityDtoMustEndWithEntityDto", data: { currentName: className, expectedName, }, }); } } // DTOs außerhalb des dto/Entity Ordners else if (isRequestDtoFolder || isResponseDtoFolder || isFilterDtoFolder || isCommonDtoFolder) { // Diese DTOs dürfen NICHT mit "EntityDto" enden if (className.endsWith("EntityDto")) { const suggestedName = className.replace("EntityDto", "Dto"); context.report({ node: node.declaration.id, messageId: "nonEntityDtoCannotEndWithEntityDto", data: { suggestedName, }, }); } } } }, }; }, };