website refactor
This commit is contained in:
@@ -140,11 +140,59 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
// Helper to recursively check if type contains ViewData
|
||||
function typeContainsViewData(typeNode) {
|
||||
if (!typeNode) return false;
|
||||
|
||||
// Check direct type name
|
||||
if (typeNode.type === 'TSTypeReference' &&
|
||||
typeNode.typeName &&
|
||||
typeNode.typeName.name &&
|
||||
typeNode.typeName.name.includes('ViewData')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check nested in object type
|
||||
if (typeNode.type === 'TSTypeLiteral' && typeNode.members) {
|
||||
for (const member of typeNode.members) {
|
||||
if (member.type === 'TSPropertySignature' &&
|
||||
member.typeAnnotation &&
|
||||
typeContainsViewData(member.typeAnnotation.typeAnnotation)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check union/intersection types
|
||||
if (typeNode.type === 'TSUnionType' || typeNode.type === 'TSIntersectionType') {
|
||||
return typeNode.types.some(t => typeContainsViewData(t));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
FunctionDeclaration(node) {
|
||||
if (node.params.length === 0 ||
|
||||
!node.params[0].typeAnnotation ||
|
||||
!node.params[0].typeAnnotation.typeAnnotation.type.includes('ViewData')) {
|
||||
if (node.params.length === 0) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'message',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const firstParam = node.params[0];
|
||||
if (!firstParam.typeAnnotation || !firstParam.typeAnnotation.typeAnnotation) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'message',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const typeAnnotation = firstParam.typeAnnotation.typeAnnotation;
|
||||
|
||||
if (!typeContainsViewData(typeAnnotation)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'message',
|
||||
@@ -170,9 +218,24 @@ module.exports = {
|
||||
create(context) {
|
||||
return {
|
||||
ExportNamedDeclaration(node) {
|
||||
if (node.declaration &&
|
||||
(node.declaration.type === 'FunctionDeclaration' ||
|
||||
if (node.declaration &&
|
||||
(node.declaration.type === 'FunctionDeclaration' ||
|
||||
node.declaration.type === 'VariableDeclaration')) {
|
||||
|
||||
// Get the function/variable name
|
||||
const name = node.declaration.id?.name;
|
||||
|
||||
// Allow the main template component (ends with Template)
|
||||
if (name && name.endsWith('Template')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow default exports
|
||||
if (node.declaration.type === 'VariableDeclaration' &&
|
||||
node.declaration.declarations.some(d => d.id.type === 'Identifier' && d.id.name.endsWith('Template'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'message',
|
||||
|
||||
Reference in New Issue
Block a user