fix(config): validate AnkiConnect and field grouping settings (#257)

This commit is contained in:
2026-09-20 22:48:54 -07:00
committed by GitHub
parent 05425cc5db
commit 917d52dd94
11 changed files with 253 additions and 89 deletions
@@ -0,0 +1,53 @@
import { DEFAULT_CONFIG } from '../../definitions';
import type { ResolveContext } from '../context';
import { asBoolean, isObject } from '../shared';
import { applyModernValue } from './modern-value';
type FieldGroupingConfigKey = 'isKiku' | 'isSenren';
export function applyFieldGroupingConfigResolution(
context: ResolveContext,
ankiConnect: Record<string, unknown>,
key: FieldGroupingConfigKey,
): void {
const source = ankiConnect[key];
if (!isObject(source)) {
if (source !== undefined) {
context.warn(
`ankiConnect.${key}`,
source,
DEFAULT_CONFIG.ankiConnect[key],
'Expected object.',
);
}
return;
}
for (const booleanKey of ['enabled', 'deleteDuplicateInAuto'] as const) {
applyModernValue(
context,
source,
booleanKey,
`ankiConnect.${key}.${booleanKey}`,
asBoolean,
DEFAULT_CONFIG.ankiConnect[key][booleanKey],
(value) => {
context.resolved.ankiConnect[key][booleanKey] = value;
},
'Expected boolean.',
);
}
applyModernValue(
context,
source,
'fieldGrouping',
`ankiConnect.${key}.fieldGrouping`,
(value) => (value === 'auto' || value === 'manual' || value === 'disabled' ? value : undefined),
DEFAULT_CONFIG.ankiConnect[key].fieldGrouping,
(value) => {
context.resolved.ankiConnect[key].fieldGrouping = value;
},
'Expected auto, manual, or disabled.',
);
}