view data fixes
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m42s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-22 23:40:38 +01:00
parent 1288a9dc30
commit 18133aef4c
111 changed files with 841 additions and 324 deletions

View File

@@ -24,7 +24,7 @@ module.exports = {
create(context) {
const filename = context.getFilename();
const isInViewData = filename.includes('/lib/view-data/');
const isInViewData = filename.includes('/lib/view-data/') && !filename.includes('/contracts/');
if (!isInViewData) return {};
@@ -42,9 +42,15 @@ module.exports = {
// Check if it extends ViewData
if (node.extends && node.extends.length > 0) {
for (const ext of node.extends) {
if (ext.type === 'TSExpressionWithTypeArguments' &&
ext.expression.type === 'Identifier' &&
ext.expression.name === 'ViewData') {
// Use context.getSourceCode().getText(ext) to be absolutely sure
const extendsText = context.getSourceCode().getText(ext).trim();
// We check for 'ViewData' but must be careful not to match 'SomethingViewData'
// unless it's exactly 'ViewData' or part of a qualified name
if (extendsText === 'ViewData' ||
extendsText.endsWith('.ViewData') ||
extendsText.startsWith('ViewData<') ||
extendsText.startsWith('ViewData ') ||
/\bViewData\b/.test(extendsText)) { // Use regex for word boundary
hasViewDataExtends = true;
}
}
@@ -74,16 +80,31 @@ module.exports = {
},
'Program:exit'() {
if (!hasCorrectName) {
// Only report if we are in a file that should be a ViewData
// and we didn't find a valid declaration
const baseName = filename.split('/').pop();
// All files in lib/view-data/ must end with ViewData.ts
if (baseName && !baseName.endsWith('ViewData.ts') && !baseName.endsWith('ViewData.tsx')) {
context.report({
node: context.getSourceCode().ast,
messageId: 'notAnInterface',
});
} else if (!hasViewDataExtends) {
context.report({
node: context.getSourceCode().ast,
messageId: 'missingExtends',
});
return;
}
if (baseName && (baseName.endsWith('ViewData.ts') || baseName.endsWith('ViewData.tsx'))) {
if (!hasCorrectName) {
context.report({
node: context.getSourceCode().ast,
messageId: 'notAnInterface',
});
} else if (!hasViewDataExtends) {
context.report({
node: context.getSourceCode().ast,
messageId: 'missingExtends',
});
}
}
},
};