kibana/packages/kbn-eslint-plugin-eslint/lib.js

37 lines
908 B
JavaScript
Raw Normal View History

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
2018-04-20 21:13:37 +02:00
exports.assert = function assert(truth, message) {
if (truth) {
return;
}
const error = new Error(message);
error.failedAssertion = true;
throw error;
};
exports.normalizeWhitespace = function normalizeWhitespace(string) {
return string.replace(/\s+/g, ' ');
};
2020-05-22 09:08:58 +02:00
exports.init = function (context, program, initStep) {
2018-04-20 21:13:37 +02:00
try {
return initStep();
} catch (error) {
if (error.failedAssertion) {
context.report({
node: program,
message: error.message,
2018-04-20 21:13:37 +02:00
});
} else {
throw error;
}
}
};