Skip to content

Commit 321cc84

Browse files
committed
feat: enhance configuration quality to match EnvSync-LE/String-LE standards
- Add validation functions and type guards (isValidNotificationLevel, isValidOutputFormat, isValidTimezone) - Add sophisticated error handling with categorization and recovery options - Improve configuration structure with proper validation and fallbacks - Add backward compatibility for legacy settings (notificationsLevel vs notificationLevel) - Enhance performance settings with proper bounds checking - Add comprehensive error handling utilities with user-friendly messages
1 parent 9271c39 commit 321cc84

File tree

2 files changed

+269
-523
lines changed

2 files changed

+269
-523
lines changed

src/config/config.ts

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,62 @@ import type { Configuration } from '../types'
44
export function getConfiguration(): Configuration {
55
const config = vscode.workspace.getConfiguration('dates-le')
66

7+
// Backward-compat: support both `notificationLevel` (preferred) and legacy `notificationsLevel`
8+
const notifRaw = config.get('notificationLevel', config.get('notificationsLevel', 'silent')) as unknown as string
9+
const notificationsLevel = isValidNotificationLevel(notifRaw) ? notifRaw : 'silent'
10+
11+
const outputFormatRaw = config.get('outputFormat', 'iso')
12+
const outputFormat = isValidOutputFormat(outputFormatRaw) ? outputFormatRaw : 'iso'
13+
14+
const timezoneRaw = config.get('timezone', 'UTC')
15+
const timezone = isValidTimezone(timezoneRaw) ? timezoneRaw : 'UTC'
16+
717
return Object.freeze({
8-
copyToClipboardEnabled: config.get<boolean>('copyToClipboardEnabled', false),
9-
dedupeEnabled: config.get<boolean>('dedupeEnabled', false),
10-
notificationsLevel: config.get<'all' | 'important' | 'silent'>('notificationsLevel', 'silent'),
11-
postProcessOpenInNewFile: config.get<boolean>('postProcess.openInNewFile', false),
12-
openResultsSideBySide: config.get<boolean>('openResultsSideBySide', false),
13-
safetyEnabled: config.get<boolean>('safety.enabled', true),
14-
safetyFileSizeWarnBytes: config.get<number>('safety.fileSizeWarnBytes', 1000000),
15-
safetyLargeOutputLinesThreshold: config.get<number>('safety.largeOutputLinesThreshold', 50000),
16-
safetyManyDocumentsThreshold: config.get<number>('safety.manyDocumentsThreshold', 8),
17-
showParseErrors: config.get<boolean>('showParseErrors', false),
18-
statusBarEnabled: config.get<boolean>('statusBar.enabled', true),
19-
telemetryEnabled: config.get<boolean>('telemetryEnabled', false),
20-
analysisEnabled: config.get<boolean>('analysis.enabled', true),
21-
analysisIncludePatterns: config.get<boolean>('analysis.includePatterns', true),
22-
analysisIncludeRanges: config.get<boolean>('analysis.includeRanges', true),
23-
analysisIncludeAnomalies: config.get<boolean>('analysis.includeAnomalies', true),
24-
outputFormat: config.get<'iso' | 'rfc2822' | 'unix' | 'utc' | 'local' | 'original'>('outputFormat', 'iso'),
25-
timezone: config.get<string>('timezone', 'UTC'),
26-
performanceEnabled: config.get<boolean>('performance.enabled', true),
27-
performanceMaxDuration: config.get<number>('performance.maxDuration', 5000),
28-
performanceMaxMemoryUsage: config.get<number>('performance.maxMemoryUsage', 104857600),
29-
performanceMaxCpuUsage: config.get<number>('performance.maxCpuUsage', 1000000),
30-
performanceMinThroughput: config.get<number>('performance.minThroughput', 1000),
31-
performanceMaxCacheSize: config.get<number>('performance.maxCacheSize', 1000),
18+
copyToClipboardEnabled: Boolean(config.get('copyToClipboardEnabled', false)),
19+
dedupeEnabled: Boolean(config.get('dedupeEnabled', false)),
20+
notificationsLevel,
21+
postProcessOpenInNewFile: Boolean(config.get('postProcess.openInNewFile', false)),
22+
openResultsSideBySide: Boolean(config.get('openResultsSideBySide', false)),
23+
safetyEnabled: Boolean(config.get('safety.enabled', true)),
24+
safetyFileSizeWarnBytes: Math.max(1000, Number(config.get('safety.fileSizeWarnBytes', 1000000))),
25+
safetyLargeOutputLinesThreshold: Math.max(100, Number(config.get('safety.largeOutputLinesThreshold', 50000))),
26+
safetyManyDocumentsThreshold: Math.max(1, Number(config.get('safety.manyDocumentsThreshold', 8))),
27+
showParseErrors: Boolean(config.get('showParseErrors', false)),
28+
statusBarEnabled: Boolean(config.get('statusBar.enabled', true)),
29+
telemetryEnabled: Boolean(config.get('telemetryEnabled', false)),
30+
analysisEnabled: Boolean(config.get('analysis.enabled', true)),
31+
analysisIncludePatterns: Boolean(config.get('analysis.includePatterns', true)),
32+
analysisIncludeRanges: Boolean(config.get('analysis.includeRanges', true)),
33+
analysisIncludeAnomalies: Boolean(config.get('analysis.includeAnomalies', true)),
34+
outputFormat,
35+
timezone,
36+
performanceEnabled: Boolean(config.get('performance.enabled', true)),
37+
performanceMaxDuration: Math.max(1000, Number(config.get('performance.maxDuration', 5000))),
38+
performanceMaxMemoryUsage: Math.max(1048576, Number(config.get('performance.maxMemoryUsage', 104857600))),
39+
performanceMaxCpuUsage: Math.max(100000, Number(config.get('performance.maxCpuUsage', 1000000))),
40+
performanceMinThroughput: Math.max(100, Number(config.get('performance.minThroughput', 1000))),
41+
performanceMaxCacheSize: Math.max(100, Number(config.get('performance.maxCacheSize', 1000))),
3242
})
3343
}
44+
45+
export type NotificationLevel = 'all' | 'important' | 'silent'
46+
export type OutputFormat = 'iso' | 'rfc2822' | 'unix' | 'utc' | 'local' | 'original'
47+
48+
export function isValidNotificationLevel(v: unknown): v is NotificationLevel {
49+
return v === 'all' || v === 'important' || v === 'silent'
50+
}
51+
52+
export function isValidOutputFormat(v: unknown): v is OutputFormat {
53+
return (
54+
v === 'iso' ||
55+
v === 'rfc2822' ||
56+
v === 'unix' ||
57+
v === 'utc' ||
58+
v === 'local' ||
59+
v === 'original'
60+
)
61+
}
62+
63+
export function isValidTimezone(v: unknown): v is string {
64+
return typeof v === 'string' && v.length > 0 && v.length <= 50
65+
}

0 commit comments

Comments
 (0)