Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better unknown handling configuration #2743

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

imjoshin
Copy link

@imjoshin imjoshin commented Feb 16, 2022

Fixes #2739

Status: Draft
This is still a draft as I haven't been able to dedicate the time required to fix up the tests. I'm open to someone else helping out and/or providing guidance. 😄

This PR aims to have better handling of unknown keys. Within the validate configuration, instead of just a boolean, allowUnknown supports clearer definitions with backwards compatibility:

type AllowMode = boolean | 'allowed' | 'forbidden' | 'warn';
...

allowUnknown?: AllowMode | {
    mode: AllowMode,
    type?: string,
};

These means we can either allow unknown keys with allowed or true, reject with forbidden or false, or warn with warn. If warn or forbidden are set, we can set what type the warning or error object are by setting the type property.

@@ -508,6 +508,47 @@ describe('Validator', () => {
}
});
});

it('reports warnings with nested options', () => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll definitely want more tests here to cover root level unknown as well as allowUnknown: 'forbidden'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for recursive warnings
1 participant