ketanSaxena / schema-validator

Schema validation utility for YAML/JSON files against a pre defined schema
https://ketantechracers.github.io/schema-validator
MIT License
36 stars 17 forks source link

CLI: return a nonzero status when validation fails #17

Closed lwille closed 3 years ago

lwille commented 3 years ago

This tool is great, but so far int merely prints errors and warnings, which makes it difficult to evaluate the validation status e.g. by a CI script or pre-commit hook.

A naïve implementation might just evaluate the list of errors and warnings and exit the process with a non-zero status:

    const errorsAndWarnings = validateSchema(targetObj, options)
    if (errorsAndWarnings?.length > 0) {
      process.exit(1)
    }
ketanSaxena commented 3 years ago

@lwille Looks like a useful improvement. But would like to have it added as an optional param that can be passed if we want to exit process on errors/warnings. That way the changes in package would be backward compatible.