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
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:
153
lib/directus.ts
153
lib/directus.ts
@@ -130,7 +130,7 @@ export async function getMessages(locale: string): Promise<Record<string, string
|
||||
});
|
||||
|
||||
return dictionary;
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ export async function getMessage(key: string, locale: string): Promise<string |
|
||||
const translations = messages[0]?.translations || [];
|
||||
const translation = translations.find((t) => t.languages_code?.code === directusLocale);
|
||||
return translation?.value || null;
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -279,13 +279,6 @@ const fallbackTechStackData: Record<string, Array<{ key: string; items: string[]
|
||||
]
|
||||
};
|
||||
|
||||
const categoryIconMap: Record<string, string> = {
|
||||
frontend: 'Globe',
|
||||
backend: 'Server',
|
||||
tools: 'Wrench',
|
||||
security: 'Shield'
|
||||
};
|
||||
|
||||
const categoryNames: Record<string, Record<string, string>> = {
|
||||
'en-US': {
|
||||
frontend: 'Frontend & Mobile',
|
||||
@@ -413,7 +406,7 @@ export async function getTechStack(locale: string): Promise<TechStackCategory[]
|
||||
icon: cat.icon,
|
||||
sort: cat.sort,
|
||||
name: cat.translations?.[0]?.name || categoryNames[directusLocale]?.[cat.key] || cat.key,
|
||||
items: itemsToUse.map((item: any) => ({
|
||||
items: itemsToUse.map((item: TechStackItem) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
url: item.url,
|
||||
@@ -424,8 +417,8 @@ export async function getTechStack(locale: string): Promise<TechStackCategory[]
|
||||
});
|
||||
|
||||
return categoriesWithItems;
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch tech stack (${locale}):`, error);
|
||||
} catch (_error) {
|
||||
console.error(`Failed to fetch tech stack (${locale}):`, _error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -468,12 +461,23 @@ export async function getHobbies(locale: string): Promise<Hobby[] | null> {
|
||||
{ body: { query } }
|
||||
);
|
||||
|
||||
const hobbies = (result as any)?.hobbies;
|
||||
interface HobbiesResult {
|
||||
hobbies: Array<{
|
||||
id: string;
|
||||
key: string;
|
||||
icon: string;
|
||||
translations?: Array<{
|
||||
title?: string;
|
||||
description?: string;
|
||||
}>;
|
||||
}>;
|
||||
}
|
||||
const hobbies = (result as HobbiesResult | null)?.hobbies;
|
||||
if (!hobbies || hobbies.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return hobbies.map((hobby: any) => ({
|
||||
return hobbies.map((hobby) => ({
|
||||
id: hobby.id,
|
||||
key: hobby.key,
|
||||
icon: hobby.icon,
|
||||
@@ -533,15 +537,30 @@ export async function getBookReviews(locale: string): Promise<BookReview[] | nul
|
||||
{ body: { query } }
|
||||
);
|
||||
|
||||
const reviews = (result as any)?.book_reviews;
|
||||
interface BookReviewsResult {
|
||||
book_reviews: Array<{
|
||||
id: string;
|
||||
hardcover_id?: string;
|
||||
book_title: string;
|
||||
book_author: string;
|
||||
book_image?: string;
|
||||
rating: number | string;
|
||||
finished_at?: string;
|
||||
translations?: Array<{
|
||||
review?: string;
|
||||
languages_code?: { code: string };
|
||||
}>;
|
||||
}>;
|
||||
}
|
||||
const reviews = (result as BookReviewsResult | null)?.book_reviews;
|
||||
if (!reviews || reviews.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return reviews.map((item: any) => {
|
||||
return reviews.map((item) => {
|
||||
// Filter die passende Übersetzung im Code
|
||||
const translation = item.translations?.find(
|
||||
(t: any) => t.languages_code?.code === directusLocale
|
||||
(t) => t.languages_code?.code === directusLocale
|
||||
) || item.translations?.[0]; // Fallback auf die erste Übersetzung falls locale nicht passt
|
||||
|
||||
return {
|
||||
@@ -682,19 +701,52 @@ export async function getProjects(
|
||||
{ body: { query } }
|
||||
);
|
||||
|
||||
const projects = (result as any)?.projects;
|
||||
interface ProjectsResult {
|
||||
projects: Array<{
|
||||
id: string;
|
||||
slug: string;
|
||||
category?: string;
|
||||
difficulty?: string;
|
||||
tags?: string[] | string;
|
||||
technologies?: string[] | string;
|
||||
challenges?: string;
|
||||
lessons_learned?: string;
|
||||
future_improvements?: string;
|
||||
github?: string;
|
||||
live?: string;
|
||||
image_url?: string;
|
||||
demo_video?: string;
|
||||
performance_metrics?: string;
|
||||
screenshots?: string[] | string;
|
||||
date_created?: string;
|
||||
date_updated?: string;
|
||||
featured?: boolean | number;
|
||||
status?: string;
|
||||
translations?: Array<{
|
||||
title?: string;
|
||||
description?: string;
|
||||
content?: string;
|
||||
meta_description?: string;
|
||||
keywords?: string;
|
||||
button_live_label?: string;
|
||||
button_github_label?: string;
|
||||
languages_code?: { code: string };
|
||||
}>;
|
||||
}>;
|
||||
}
|
||||
const projects = (result as ProjectsResult | null)?.projects;
|
||||
if (!projects || projects.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return projects.map((proj: any) => {
|
||||
return projects.map((proj) => {
|
||||
const trans =
|
||||
proj.translations?.find((t: any) => t.languages_code?.code === directusLocale) ||
|
||||
proj.translations?.find((t) => t.languages_code?.code === directusLocale) ||
|
||||
proj.translations?.[0] ||
|
||||
{};
|
||||
|
||||
// Parse JSON string fields if needed
|
||||
const parseTags = (tags: any) => {
|
||||
const parseTags = (tags: string[] | string | undefined): string[] => {
|
||||
if (!tags) return [];
|
||||
if (Array.isArray(tags)) return tags;
|
||||
if (typeof tags === 'string') {
|
||||
@@ -706,7 +758,7 @@ export async function getProjects(
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
|
||||
return {
|
||||
id: proj.id,
|
||||
slug: proj.slug,
|
||||
@@ -734,8 +786,8 @@ export async function getProjects(
|
||||
updated_at: proj.date_updated
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch projects (${locale}):`, error);
|
||||
} catch (_error) {
|
||||
console.error(`Failed to fetch projects (${locale}):`, _error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -797,19 +849,51 @@ export async function getProjectBySlug(
|
||||
{ body: { query } }
|
||||
);
|
||||
|
||||
const projects = (result as any)?.projects;
|
||||
interface ProjectResult {
|
||||
projects: Array<{
|
||||
id: string;
|
||||
slug: string;
|
||||
category?: string;
|
||||
difficulty?: string;
|
||||
tags?: string[] | string;
|
||||
technologies?: string[] | string;
|
||||
challenges?: string;
|
||||
lessons_learned?: string;
|
||||
future_improvements?: string;
|
||||
github?: string;
|
||||
live?: string;
|
||||
image_url?: string;
|
||||
demo_video?: string;
|
||||
screenshots?: string[] | string;
|
||||
date_created?: string;
|
||||
date_updated?: string;
|
||||
featured?: boolean | number;
|
||||
status?: string;
|
||||
translations?: Array<{
|
||||
title?: string;
|
||||
description?: string;
|
||||
content?: string;
|
||||
meta_description?: string;
|
||||
keywords?: string;
|
||||
button_live_label?: string;
|
||||
button_github_label?: string;
|
||||
languages_code?: { code: string };
|
||||
}>;
|
||||
}>;
|
||||
}
|
||||
const projects = (result as ProjectResult | null)?.projects;
|
||||
if (!projects || projects.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const proj = projects[0];
|
||||
const trans =
|
||||
proj.translations?.find((t: any) => t.languages_code?.code === directusLocale) ||
|
||||
proj.translations?.find((t) => t.languages_code?.code === directusLocale) ||
|
||||
proj.translations?.[0] ||
|
||||
{};
|
||||
|
||||
// Parse JSON string fields if needed
|
||||
const parseTags = (tags: any) => {
|
||||
const parseTags = (tags: string[] | string | undefined): string[] => {
|
||||
if (!tags) return [];
|
||||
if (Array.isArray(tags)) return tags;
|
||||
if (typeof tags === 'string') {
|
||||
@@ -821,7 +905,7 @@ export async function getProjectBySlug(
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
|
||||
return {
|
||||
id: proj.id,
|
||||
slug: proj.slug,
|
||||
@@ -847,8 +931,8 @@ export async function getProjectBySlug(
|
||||
created_at: proj.date_created,
|
||||
updated_at: proj.date_updated
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch project by slug ${slug} (${locale}):`, error);
|
||||
} catch (_error) {
|
||||
console.error(`Failed to fetch project by slug ${slug} (${locale}):`, _error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -895,14 +979,17 @@ export async function getSnippets(limit = 10, featured?: boolean): Promise<Snipp
|
||||
{ body: { query } }
|
||||
);
|
||||
|
||||
const snippets = (result as any)?.snippets;
|
||||
interface SnippetsResult {
|
||||
snippets: Snippet[];
|
||||
}
|
||||
const snippets = (result as SnippetsResult | null)?.snippets;
|
||||
if (!snippets || snippets.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return snippets;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch snippets:', error);
|
||||
} catch (_error) {
|
||||
console.error('Failed to fetch snippets:', _error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user