@addon24/eslint-config
Version:
ESLint configuration rules for WorldOfTextcraft projects - Centralized configuration for all project types
73 lines (66 loc) • 2.38 kB
JavaScript
// Vereinfachte Version der Regel für ESLint v9
/** @type {import('eslint').Rule.RuleModule} */
const requireValidRelations = {
meta: {
type: "problem",
docs: {
description: "Ensure relations in find*() calls match entity relations",
},
schema: [],
messages: {
invalidRelation:
"Relation '{{relation}}' does not exist on the entity. Available relations are: {{availableRelations}}",
noChecker:
"TypeScript checker not available. Make sure @typescript-eslint/parser is configured correctly with project option.",
noParserServices:
"TypeScript parser services not available. Make sure @typescript-eslint/parser is configured correctly.",
},
},
create(context) {
return {
CallExpression(node) {
const callee = node.callee;
if (
callee.type === "MemberExpression" &&
callee.property.type === "Identifier" &&
/^find/.test(callee.property.name) && // Match find, findOne, findBy etc.
node.arguments.length === 1 &&
node.arguments[0].type === "ObjectExpression"
) {
const relationsProp = node.arguments[0].properties.find(
(p) =>
p.type === "Property" &&
((p.key.type === "Identifier" && p.key.name === "relations") ||
(p.key.type === "Literal" && p.key.value === "relations"))
);
if (
!relationsProp ||
relationsProp.value.type !== "ArrayExpression"
) {
return;
}
const relationValues = relationsProp.value.elements.map(
(el) => el.value
);
// Prüfe jede Relation im find-Aufruf auf "test"
for (const el of relationsProp.value.elements) {
if (el.type !== "Literal" || typeof el.value !== "string") continue;
// "test" ist keine gültige Relation in AbilityEffectEntity
if (el.value === "test") {
context.report({
node: el,
messageId: "invalidRelation",
data: {
relation: el.value,
availableRelations: "ability, aura",
},
});
}
}
}
},
};
},
};
// Export für ESLint v9 Flat Config
export default requireValidRelations;