lundegaard / lundegaard/validarium
`validateMany` should return `null` when all validations pass
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 28
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
validateMany currently returns an array of results ([null]), even if all subvalidations successfully pass. null should be returned directly to be consistent with validate and allow nesting of validate and validateMany calls.
validate({
foo: [isRequired]
})({
foo: 'bar'
}); // === null
validateMany({
foo: [isRequired]
})([{
foo: 'bar'
}]) // === [null], expected to be null
validate({
arr: [
validateMany({
foo: [isRequired]
})
]
})({
arr: [{
foo: 'bar'
}]
}) // === {arr: [null]}, expected to be null
Of course when at least one validation fails, the structure should be kept as is to know which index is wrong.
Proposed fix:
const fixedValidateMany = validations => o(when(all(isNil), always(null)), validateMany(validations));
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the validateMany entry point and compare its successful-result behavior with validate. Add coverage for all validations passing, including nesting validateMany inside validate, while preserving the indexed structure when any validation fails; done means the all-pass result is null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100