website refactor
This commit is contained in:
58
apps/website/eslint-rules/test-rule-simple.js
Normal file
58
apps/website/eslint-rules/test-rule-simple.js
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Simple test for page-query-must-use-builders rule
|
||||
*/
|
||||
|
||||
const rule = require('./page-query-must-use-builders.js');
|
||||
|
||||
// Simulate the AST traversal
|
||||
const mockContext = {
|
||||
getSourceCode: () => ({ ast: {} }),
|
||||
report: (data) => {
|
||||
console.log('REPORT:', data.messageId);
|
||||
}
|
||||
};
|
||||
|
||||
const visitor = rule.create(mockContext);
|
||||
|
||||
// Simulate visiting AdminDashboardPageQuery
|
||||
console.log('Starting test...');
|
||||
|
||||
// 1. ClassDeclaration
|
||||
visitor.ClassDeclaration({
|
||||
id: { name: 'AdminDashboardPageQuery' }
|
||||
});
|
||||
|
||||
// 2. MethodDefinition (execute)
|
||||
visitor.MethodDefinition({
|
||||
key: { type: 'Identifier', name: 'execute' },
|
||||
parent: { type: 'ClassBody' }
|
||||
});
|
||||
|
||||
// 3. VariableDeclarator (const apiDto = ...) - NOT an ObjectExpression
|
||||
visitor.VariableDeclarator({
|
||||
init: { type: 'CallExpression' } // apiDto = await adminService.getDashboardStats()
|
||||
});
|
||||
|
||||
// 4. ReturnStatement (return Result.ok(apiDto))
|
||||
// This is a CallExpression with callee = Result.ok and argument = apiDto
|
||||
visitor.ReturnStatement({
|
||||
argument: {
|
||||
type: 'CallExpression',
|
||||
callee: {
|
||||
type: 'MemberExpression',
|
||||
object: { type: 'Identifier', name: 'Result' },
|
||||
property: { type: 'Identifier', name: 'ok' }
|
||||
},
|
||||
arguments: [{ type: 'Identifier', name: 'apiDto' }]
|
||||
}
|
||||
});
|
||||
|
||||
// 5. MethodDefinition:exit
|
||||
visitor['MethodDefinition:exit']({
|
||||
key: { type: 'Identifier', name: 'execute' }
|
||||
});
|
||||
|
||||
// 6. Program:exit
|
||||
visitor['Program:exit']();
|
||||
|
||||
console.log('Test complete');
|
||||
Reference in New Issue
Block a user