@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
59 lines (58 loc) • 1.62 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getValidatedConfig = void 0;
var _ajv = _interopRequireDefault(require("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
};
var getValidatedConfig = exports.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.default({
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;
};