fix lint errors

This commit is contained in:
Felix Schulze 2025-04-29 22:48:39 +02:00
parent 5e0ff2891a
commit 26d2ec68b8
2 changed files with 23 additions and 25 deletions

View File

@ -175,7 +175,6 @@ export default function FireCalculatorForm() {
// Simulate retirement phase for chart data (using 4% withdrawal adjusted for inflation) // Simulate retirement phase for chart data (using 4% withdrawal adjusted for inflation)
let simulationCapital = currentCapital; let simulationCapital = currentCapital;
let simulationAge = retirementAge; let simulationAge = retirementAge;
let simulationAllowance = finalInflationAdjustedAllowance!;
// Mark retirement phase in existing data // Mark retirement phase in existing data
yearlyData.forEach((data) => { yearlyData.forEach((data) => {
@ -214,7 +213,6 @@ export default function FireCalculatorForm() {
while (age < lifeExpectancy && iterations < maxIterations) { while (age < lifeExpectancy && iterations < maxIterations) {
// Simulate one year of saving and growth // Simulate one year of saving and growth
let yearStartCapital = currentCapital;
for (let month = 0; month < 12; month++) { for (let month = 0; month < 12; month++) {
currentCapital += monthlySavings; currentCapital += monthlySavings;
currentCapital *= 1 + monthlyGrowthRate; currentCapital *= 1 + monthlyGrowthRate;
@ -238,16 +236,12 @@ export default function FireCalculatorForm() {
// Simulate retirement phase to check sufficiency // Simulate retirement phase to check sufficiency
while (testAge < lifeExpectancy) { while (testAge < lifeExpectancy) {
let yearlyStartCapital = testCapital; const yearlyStartCapital = testCapital;
let yearlyGrowth = 0;
let yearlyWithdrawal = 0;
for (let month = 0; month < 12; month++) { for (let month = 0; month < 12; month++) {
let withdrawal = testAllowance; const withdrawal = testAllowance;
yearlyWithdrawal += withdrawal;
testCapital -= withdrawal; testCapital -= withdrawal;
let growth = testCapital * monthlyGrowthRate; const growth = testCapital * monthlyGrowthRate;
yearlyGrowth += growth;
testCapital += growth; // Apply growth *after* withdrawal for the month testCapital += growth; // Apply growth *after* withdrawal for the month
testAllowance *= 1 + monthlyInflationRate; // Inflate allowance for next month testAllowance *= 1 + monthlyInflationRate; // Inflate allowance for next month
} }

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
"use client"; "use client";
import * as React from "react"; import * as React from "react";
@ -8,15 +9,16 @@ import { cn } from "@/lib/utils";
// Format: { THEME_NAME: CSS_SELECTOR } // Format: { THEME_NAME: CSS_SELECTOR }
const THEMES = { light: "", dark: ".dark" } as const; const THEMES = { light: "", dark: ".dark" } as const;
export type ChartConfig = { export type ChartConfig = Record<
[k in string]: { string,
{
label?: React.ReactNode; label?: React.ReactNode;
icon?: React.ComponentType; icon?: React.ComponentType;
} & ( } & (
| { color?: string; theme?: never } | { color?: string; theme?: never }
| { color?: never; theme: Record<keyof typeof THEMES, string> } | { color?: never; theme: Record<keyof typeof THEMES, string> }
); )
}; >;
type ChartContextProps = { type ChartContextProps = {
config: ChartConfig; config: ChartConfig;
@ -47,7 +49,7 @@ function ChartContainer({
>["children"]; >["children"];
}) { }) {
const uniqueId = React.useId(); const uniqueId = React.useId();
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`; const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;
return ( return (
<ChartContext.Provider value={{ config }}> <ChartContext.Provider value={{ config }}>
@ -71,7 +73,7 @@ function ChartContainer({
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => { const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
const colorConfig = Object.entries(config).filter( const colorConfig = Object.entries(config).filter(
([, config]) => config.theme || config.color, ([, config]) => config.theme ?? config.color,
); );
if (!colorConfig.length) { if (!colorConfig.length) {
@ -88,7 +90,7 @@ ${prefix} [data-chart=${id}] {
${colorConfig ${colorConfig
.map(([key, itemConfig]) => { .map(([key, itemConfig]) => {
const color = const color =
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] || itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ??
itemConfig.color; itemConfig.color;
return color ? ` --color-${key}: ${color};` : null; return color ? ` --color-${key}: ${color};` : null;
}) })
@ -134,11 +136,11 @@ function ChartTooltipContent({
} }
const [item] = payload; const [item] = payload;
const key = `${labelKey || item?.dataKey || item?.name || "value"}`; const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
const itemConfig = getPayloadConfigFromPayload(config, item, key); const itemConfig = getPayloadConfigFromPayload(config, item, key);
const value = const value =
!labelKey && typeof label === "string" !labelKey && typeof label === "string"
? config[label as keyof typeof config]?.label || label ? (config[label]?.label ?? label)
: itemConfig?.label; : itemConfig?.label;
if (labelFormatter) { if (labelFormatter) {
@ -180,9 +182,11 @@ function ChartTooltipContent({
{!nestLabel ? tooltipLabel : null} {!nestLabel ? tooltipLabel : null}
<div className="grid gap-1.5"> <div className="grid gap-1.5">
{payload.map((item, index) => { {payload.map((item, index) => {
const key = `${nameKey || item.name || item.dataKey || "value"}`; const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`;
const itemConfig = getPayloadConfigFromPayload(config, item, key); const itemConfig = getPayloadConfigFromPayload(config, item, key);
const indicatorColor = color || item.payload.fill || item.color; const indicatorColor: string | undefined =
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
color ?? item.payload.fill ?? item.color;
return ( return (
<div <div
@ -193,6 +197,7 @@ function ChartTooltipContent({
)} )}
> >
{formatter && item?.value !== undefined && item.name ? ( {formatter && item?.value !== undefined && item.name ? (
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
formatter(item.value, item.name, item, index, item.payload) formatter(item.value, item.name, item, index, item.payload)
) : ( ) : (
<> <>
@ -229,7 +234,7 @@ function ChartTooltipContent({
<div className="grid gap-1.5"> <div className="grid gap-1.5">
{nestLabel ? tooltipLabel : null} {nestLabel ? tooltipLabel : null}
<span className="text-muted-foreground"> <span className="text-muted-foreground">
{itemConfig?.label || item.name} {itemConfig?.label ?? item.name}
</span> </span>
</div> </div>
{item.value && ( {item.value && (
@ -276,7 +281,8 @@ function ChartLegendContent({
)} )}
> >
{payload.map((item) => { {payload.map((item) => {
const key = `${nameKey || item.dataKey || "value"}`; // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
const key = `${nameKey ?? item.dataKey ?? "value"}`;
const itemConfig = getPayloadConfigFromPayload(config, item, key); const itemConfig = getPayloadConfigFromPayload(config, item, key);
return ( return (
@ -338,9 +344,7 @@ function getPayloadConfigFromPayload(
] as string; ] as string;
} }
return configLabelKey in config return configLabelKey in config ? config[configLabelKey] : config[key];
? config[configLabelKey]
: config[key as keyof typeof config];
} }
export { export {