UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

52 lines 1.36 kB
import Ajv from 'ajv'; var deprecatedSchema = { type: 'object', patternProperties: { '.+': { type: 'array', items: { type: 'object', properties: { moduleSpecifier: { type: 'string' }, namedSpecifiers: { type: 'array', items: { type: 'string' } }, actionableVersion: { type: 'string' } }, required: ['moduleSpecifier'], additionalProperites: false } } }, allowMatchingProperties: true }; export var getValidatedConfig = function getValidatedConfig(originalDeprecatedConfig) { var parsedDeprecatedConfig = {}; try { parsedDeprecatedConfig = JSON.parse(originalDeprecatedConfig); } catch (e) { var error = e; throw new Error("Failed to parse JSON string: ".concat(error.message)); } var ajv = new Ajv({ allErrors: true }); var validate = ajv.compile(deprecatedSchema); var valid = validate(parsedDeprecatedConfig); if (!valid) { var errors = validate.errors; if (errors && errors.length) { throw new Error("Deprecated APIs config is invalid: ".concat(errors)); } else { throw new Error('Failed to validate deprecated APIs config with unknown error.'); } } return parsedDeprecatedConfig; };