Skip to content

Commit

Permalink
Refactor validateConfig method to simplify returns
Browse files Browse the repository at this point in the history
  • Loading branch information
domoscargin committed Sep 6, 2023
1 parent 4febd00 commit cc5c232
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/govuk-frontend/src/govuk/govuk-frontend-component.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ export class GOVUKFrontendComponent {
*/
validateConfig(schema, config) {
if (schema.anyOf) {
// Check if at least one of the conditions in anyOf is met
for (const condition of schema.anyOf) {
return schema.anyOf.some((condition) => {
const requiredProps = condition.required
if (requiredProps.every((prop) => prop in config && config[prop])) {
return true
}
}
return false
return requiredProps.every((prop) => prop in config && config[prop])
})
}
return true
}
Expand Down

0 comments on commit cc5c232

Please sign in to comment.