website refactor
This commit is contained in:
63
apps/website/eslint-rules/test-rule.js
Normal file
63
apps/website/eslint-rules/test-rule.js
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Test script for page-query-must-use-builders rule
|
||||
*/
|
||||
|
||||
const rule = require('./page-query-must-use-builders.js');
|
||||
const { Linter } = require('eslint');
|
||||
|
||||
const linter = new Linter();
|
||||
|
||||
// Register the plugin
|
||||
linter.defineRule('gridpilot-rules/page-query-must-use-builders', rule);
|
||||
|
||||
const code = `
|
||||
import { AdminApiClient } from '@/lib/api/admin/AdminApiClient';
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { AdminService } from '@/lib/services/admin/AdminService';
|
||||
import type { DashboardStats } from '@/lib/api/admin/AdminApiClient';
|
||||
|
||||
export class AdminDashboardPageQuery implements PageQuery<DashboardStats, void> {
|
||||
async execute(): Promise<Result<DashboardStats, string>> {
|
||||
try {
|
||||
const logger = new ConsoleLogger();
|
||||
const errorReporter = new EnhancedErrorReporter(logger, {
|
||||
showUserNotifications: false,
|
||||
logToConsole: true,
|
||||
reportToExternal: process.env.NODE_ENV === 'production',
|
||||
});
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3001';
|
||||
const apiClient = new AdminApiClient(baseUrl, errorReporter, logger);
|
||||
const adminService = new AdminService(apiClient);
|
||||
|
||||
const apiDto = await adminService.getDashboardStats();
|
||||
|
||||
return Result.ok(apiDto);
|
||||
} catch (err) {
|
||||
console.error('AdminDashboardPageQuery failed:', err);
|
||||
|
||||
if (err instanceof Error && (err.message.includes('403') || err.message.includes('401'))) {
|
||||
return Result.err('notFound');
|
||||
}
|
||||
|
||||
return Result.err('admin_dashboard_fetch_failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const messages = linter.verify(code, {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 2020,
|
||||
sourceType: 'module',
|
||||
},
|
||||
rules: {
|
||||
'gridpilot-rules/page-query-must-use-builders': 'error',
|
||||
},
|
||||
});
|
||||
|
||||
console.log('ESLint messages:', messages);
|
||||
Reference in New Issue
Block a user