Sha256: ec3ebd8da2030365c1fcdeb4450bdf76150035c5e6cf6705ad0e97a81c368282

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

/**
 * Formats an array of schema validation errors.
 * @param errors An array of error messages to format.
 * @returns Formatted error message
 * Based on https://github.com/eslint/eslint/blob/master/lib/shared/config-validator.js#L237-L261
 */
export function formatErrors(errors) {
    return errors
        .map((error) => {
        if (error.keyword === 'additionalProperties' &&
            'additionalProperty' in error.params) {
            const formattedPropertyPath = error.instancePath.length
                ? `${error.instancePath.slice(1)}.${error.params.additionalProperty}`
                : error.params.additionalProperty;
            return `Unexpected top-level property "${formattedPropertyPath}"`;
        }
        if (error.keyword === 'type') {
            const formattedField = error.instancePath.slice(1);
            if (!formattedField) {
                return `Config has the wrong type - ${error.message}`;
            }
            return `Property "${formattedField}" has the wrong type - ${error.message}`;
        }
        const field = (error.instancePath[0] === '.'
            ? error.instancePath.slice(1)
            : error.instancePath) || 'Config';
        if (error.keyword === 'typeof') {
            return `"${field}" should be a ${error.schema}. Value: ${JSON.stringify(error.data)}`;
        }
        return `"${field}" ${error.message}. Value: ${JSON.stringify(error.data)}`;
    })
        .map((message) => `\t- ${message}.\n`)
        .join('');
}
//# sourceMappingURL=formatErrors.js.map

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pcp-server-ruby-sdk-0.0.6 node_modules/@commitlint/config-validator/lib/formatErrors.js
pcp-server-ruby-sdk-0.1.0 node_modules/@commitlint/config-validator/lib/formatErrors.js