fix: resolve all lint errors, improve type safety, and remove unused code
Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 7m26s

Remove unused imports, replace `any` types with proper interfaces in directus.ts
and i18n-loader.ts, exclude scripts/ and coverage/ from ESLint, and fix
unused variable warnings across the codebase.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-17 14:46:35 +01:00
parent a5dba298f3
commit 6fd4756f35
12 changed files with 155 additions and 72 deletions

View File

@@ -5,20 +5,20 @@
* - Caches results (5 min TTL)
*/
import { getMessage, getContentPage } from './directus';
import { getMessage, getContentPage, ContentPage } from './directus';
import enMessages from '@/messages/en.json';
import deMessages from '@/messages/de.json';
const jsonFallback = { en: enMessages, de: deMessages };
// Simple in-memory cache
const cache = new Map<string, { value: any; expires: number }>();
const cache = new Map<string, { value: unknown; expires: number }>();
function setCached(key: string, value: any, ttlSeconds = 300) {
function setCached(key: string, value: unknown, ttlSeconds = 300) {
cache.set(key, { value, expires: Date.now() + ttlSeconds * 1000 });
}
function getCached(key: string): any | null {
function getCached(key: string): unknown | null {
const hit = cache.get(key);
if (!hit) return null;
if (Date.now() > hit.expires) {
@@ -38,7 +38,7 @@ export async function getLocalizedMessage(
): Promise<string> {
const cacheKey = `msg:${key}:${locale}`;
const cached = getCached(cacheKey);
if (cached !== null) return cached;
if (cached !== null) return cached as string;
// Try Directus with requested locale
const dbValue = await getMessage(key, locale);
@@ -84,11 +84,11 @@ export async function getLocalizedMessage(
export async function getLocalizedContent(
slug: string,
locale: string
): Promise<any | null> {
): Promise<ContentPage | null> {
const cacheKey = `page:${slug}:${locale}`;
const cached = getCached(cacheKey);
if (cached !== null) return cached;
if (cached === null && cache.has(cacheKey)) return null; // Already checked, not found
if (cached !== null) return cached as ContentPage;
if (cache.has(cacheKey)) return null; // Already checked, not found
// Try Directus with requested locale
const dbPage = await getContentPage(slug, locale);
@@ -115,14 +115,18 @@ export async function getLocalizedContent(
* Helper: Get nested value from object
* Example: "nav.home" → obj.nav.home
*/
function getNestedValue(obj: any, path: string): any {
function getNestedValue(obj: Record<string, unknown>, path: string): string | null {
const keys = path.split('.');
let value = obj;
let value: unknown = obj;
for (const key of keys) {
value = value?.[key];
if (value && typeof value === 'object' && key in value) {
value = (value as Record<string, unknown>)[key];
} else {
return null;
}
if (value === undefined) return null;
}
return value;
return typeof value === 'string' ? value : null;
}
/**