view data fixes
This commit is contained in:
@@ -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',
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user