Skip to content

Commit

Permalink
feat: ignore unknown config options
Browse files Browse the repository at this point in the history
  • Loading branch information
Myllaume committed Jan 8, 2025
1 parent d81abb4 commit e2a6767
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/models/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class Config {
...opts,
};

const { error } = optionsSchema.validate(opts);
const { error, value } = optionsSchema.validate(opts, { stripUnknown: true });
if (error) {
const details = (error?.details || [])
.flatMap((detail) => [detail.message, detail.context.message])
Expand All @@ -349,7 +349,7 @@ class Config {
throw new Error(`Config schema validation failed: ${details}`);
}

return new Config(opts);
return new Config(value);
}

/**
Expand Down Expand Up @@ -384,7 +384,7 @@ class Config {
...data,
};

const { error } = optionsSchema.validate(opts);
const { error, value } = optionsSchema.validate(opts, { stripUnknown: true });
if (error) {
const details = (error?.details || [])
.flatMap((detail) => [detail.message, detail.context.message])
Expand All @@ -393,7 +393,7 @@ class Config {
throw new Error(`Config file ${configFilePath} contains errors :\n${details}`);
}

return new Config(opts);
return new Config(value);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions core/models/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,19 @@ css_custom: styles.css
const config = Config.get('../config.yml');
expect(config.canCssCustom()).toBe(true);
});

it('should ignore unknown options', () => {
const configContent = `
${minimalConfigContent}
unknown: true
`;

mockReadConfigFile.mockImplementationOnce(() => configContent);
const config = Config.get('../config.yml');
expect(config.opts).not.toEqual(
expect.objectContaining({
unknown: true,
}),
);
});
});

0 comments on commit e2a6767

Please sign in to comment.