view data fixes

This commit is contained in:
2026-01-23 15:30:23 +01:00
parent e22033be38
commit f8099f04bc
213 changed files with 3466 additions and 3003 deletions

View File

@@ -4,6 +4,7 @@
* ViewData files in lib/view-data/ must:
* 1. Be interfaces or types named *ViewData
* 2. Extend the ViewData interface from contracts
* 3. NOT contain ViewModels (ViewModels are for ClientWrappers/Hooks)
*/
module.exports = {
@@ -19,6 +20,7 @@ module.exports = {
messages: {
notAnInterface: 'ViewData files must be interfaces or types named *ViewData',
missingExtends: 'ViewData must extend the ViewData interface from lib/contracts/view-data/ViewData.ts',
noViewModelsInViewData: 'ViewData must not contain ViewModels. ViewData is for plain JSON data (DTOs) passed through SSR. Use ViewModels in ClientWrappers or Hooks instead.',
},
},
@@ -32,12 +34,37 @@ module.exports = {
let hasCorrectName = false;
return {
// Check for ViewModel imports
ImportDeclaration(node) {
if (!isInViewData) return;
const importPath = node.source.value;
if (importPath.includes('/lib/view-models/')) {
context.report({
node,
messageId: 'noViewModelsInViewData',
});
}
},
// Check interface declarations
TSInterfaceDeclaration(node) {
const interfaceName = node.id?.name;
if (interfaceName && interfaceName.endsWith('ViewData')) {
hasCorrectName = true;
// Check for ViewModel usage in properties
node.body.body.forEach(member => {
if (member.type === 'TSPropertySignature' && member.typeAnnotation) {
const typeAnnotation = member.typeAnnotation.typeAnnotation;
if (isViewModelType(typeAnnotation)) {
context.report({
node: member,
messageId: 'noViewModelsInViewData',
});
}
}
});
// Check if it extends ViewData
if (node.extends && node.extends.length > 0) {