Skip to content

Commit 4c0429b

Browse files
committed
chore: apply additional linter improvements and constants
- Add configurable constants for magic numbers (RECENT_DAYS_DEFAULT, WARNING_THRESHOLD, etc.) - Complete type assertion fixes for remaining for...of loops - Apply automated ESLint formatting improvements - All lint errors resolved, tests passing, type checking clean
1 parent 238dab5 commit 4c0429b

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

‎src/commands/blocks.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import { sharedCommandConfig } from '../shared-args.internal.ts';
1313
import { formatCurrency, formatModelsDisplay, formatNumber } from '../utils.internal.ts';
1414
import { ResponsiveTable } from '../utils.table.ts';
1515

16+
// Constants for configurable values
17+
const RECENT_DAYS_DEFAULT = 3;
18+
const WARNING_THRESHOLD = 0.8;
19+
const COMPACT_WIDTH_THRESHOLD = 120;
20+
const DEFAULT_TERMINAL_WIDTH = 120;
21+
1622
function formatBlockTime(block: FiveHourBlock, compact = false): string {
1723
const start = compact
1824
? block.startTime.toLocaleString(undefined, {
@@ -97,7 +103,7 @@ export const blocksCommand = define({
97103
recent: {
98104
type: 'boolean',
99105
short: 'r',
100-
description: 'Show blocks from last 3 days (including active)',
106+
description: `Show blocks from last ${RECENT_DAYS_DEFAULT} days (including active)`,
101107
default: false,
102108
},
103109
tokenLimit: {
@@ -148,7 +154,7 @@ export const blocksCommand = define({
148154

149155
// Apply filters
150156
if (ctx.values.recent) {
151-
blocks = filterRecentBlocks(blocks, 3);
157+
blocks = filterRecentBlocks(blocks, RECENT_DAYS_DEFAULT);
152158
}
153159

154160
if (ctx.values.active) {
@@ -197,7 +203,7 @@ export const blocksCommand = define({
197203
percentUsed: (projection.totalTokens / limit) * 100,
198204
status: projection.totalTokens > limit
199205
? 'exceeds'
200-
: projection.totalTokens > limit * 0.8 ? 'warning' : 'ok',
206+
: projection.totalTokens > limit * WARNING_THRESHOLD ? 'warning' : 'ok',
201207
}
202208
: undefined;
203209
})()
@@ -258,7 +264,7 @@ export const blocksCommand = define({
258264
const percentUsed = (projection.totalTokens / limit) * 100;
259265
const status = percentUsed > 100
260266
? pc.red('EXCEEDS LIMIT')
261-
: percentUsed > 80
267+
: percentUsed > WARNING_THRESHOLD * 100
262268
? pc.yellow('WARNING')
263269
: pc.green('OK');
264270

@@ -297,8 +303,8 @@ export const blocksCommand = define({
297303
});
298304

299305
// Detect if we need compact formatting
300-
const terminalWidth = process.stdout.columns || 120;
301-
const useCompactFormat = terminalWidth < 120;
306+
const terminalWidth = process.stdout.columns || DEFAULT_TERMINAL_WIDTH;
307+
const useCompactFormat = terminalWidth < COMPACT_WIDTH_THRESHOLD;
302308

303309
for (const block of blocks) {
304310
if (block.isGap ?? false) {

‎src/five-hour-blocks.internal.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const FIVE_HOURS_MS = 5 * 60 * 60 * 1000;
2+
const DEFAULT_RECENT_DAYS = 3;
23

34
export type LoadedUsageEntry = {
45
timestamp: Date;
@@ -230,7 +231,7 @@ export function projectBlockUsage(block: FiveHourBlock): ProjectedUsage | null {
230231
};
231232
}
232233

233-
export function filterRecentBlocks(blocks: FiveHourBlock[], days: number = 3): FiveHourBlock[] {
234+
export function filterRecentBlocks(blocks: FiveHourBlock[], days: number = DEFAULT_RECENT_DAYS): FiveHourBlock[] {
234235
const now = new Date();
235236
const cutoffTime = new Date(now.getTime() - days * 24 * 60 * 60 * 1000);
236237

0 commit comments

Comments
 (0)