add settings configuration parser #78

Merged
jakob.scheid merged 20 commits from feature/settings-config-parser into main 2026-05-29 14:03:15 +02:00
Showing only changes of commit 4ef6008976 - Show all commits
@@ -57,21 +57,23 @@ function validateEntry(entry, path) {
assertString(entry.name, `${path}.name`);
assertString(entry.i18n, `${path}.i18n`);
if (entry.default !== undefined) {
if (entry.type === 'bool' && typeof entry.default !== 'boolean') {
throw new Error(`[settings] "${path}.default" must be a boolean`);
}
if (entry.type === 'number' && typeof entry.default !== 'number') {
throw new Error(`[settings] "${path}.default" must be a number`);
}
if (entry.type === 'string' && typeof entry.default !== 'string') {
throw new Error(`[settings] "${path}.default" must be a string`);
}
if (entry.type === 'selection') {
validateSelectionOptions(entry.options, path);
if (typeof entry.allowMultiple !== 'boolean') {
throw new Error(`[settings] "${path}.allowMultiple" must be a boolean`);
}
if (entry.default === undefined) {
jakob.scheid marked this conversation as resolved Outdated
Outdated
Review

Not every setting does need a default value. I suggest omitting this check.

Not every setting does need a default value. I suggest omitting this check.
throw new Error(`[settings] "${path}.default" is required`);
}
if (entry.type === 'bool' && typeof entry.default !== 'boolean') {
throw new Error(`[settings] "${path}.default" must be a boolean`);
}
if (entry.type === 'number' && typeof entry.default !== 'number') {
throw new Error(`[settings] "${path}.default" must be a number`);
}
if (entry.type === 'string' && typeof entry.default !== 'string') {
throw new Error(`[settings] "${path}.default" must be a string`);
}
if (entry.type === 'selection') {
validateSelectionOptions(entry.options, path);
if (typeof entry.allowMultiple !== 'boolean') {
jakob.scheid marked this conversation as resolved Outdated
Outdated
Review

I think it should have a default value (false) that is used if it is not specified.

I think it should have a default value (`false`) that is used if it is not specified.
throw new Error(`[settings] "${path}.allowMultiple" must be a boolean`);
}
}
}