mirror of
https://github.com/elastic/kibana.git
synced 2025-06-29 03:24:45 -04:00
Updates files outside of x-pack to be triple-licensed under Elastic License 2.0, AGPL 3.0, or SSPL 1.0.
76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
/*
|
|
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
|
* License v3.0 only", or the "Server Side Public License, v 1".
|
|
*/
|
|
|
|
const babelEslint = require('@babel/eslint-parser');
|
|
|
|
const { assert, normalizeWhitespace, init } = require('../lib');
|
|
|
|
module.exports = {
|
|
meta: {
|
|
fixable: 'code',
|
|
schema: [
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
licenses: {
|
|
type: 'array',
|
|
items: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
},
|
|
additionalProperties: false,
|
|
},
|
|
],
|
|
},
|
|
create: (context) => {
|
|
return {
|
|
Program(program) {
|
|
const licenses = init(context, program, () => {
|
|
const options = context.options[0] || {};
|
|
const licenses = options.licenses;
|
|
|
|
assert(!!licenses, '"licenses" option is required');
|
|
|
|
return licenses.map((license, i) => {
|
|
const parsed = babelEslint.parse(license, { requireConfigFile: false });
|
|
|
|
assert(
|
|
!parsed.body.length,
|
|
`"licenses[${i}]" option must only include a single comment`
|
|
);
|
|
assert(
|
|
parsed.comments.length === 1,
|
|
`"licenses[${i}]" option must only include a single comment`
|
|
);
|
|
|
|
return normalizeWhitespace(parsed.comments[0].value);
|
|
});
|
|
});
|
|
|
|
if (!licenses || !licenses.length) return;
|
|
|
|
const sourceCode = context.getSourceCode();
|
|
|
|
sourceCode
|
|
.getAllComments()
|
|
.filter((node) => licenses.includes(normalizeWhitespace(node.value)))
|
|
.forEach((node) => {
|
|
context.report({
|
|
node,
|
|
message: 'This license header is not allowed in this file.',
|
|
fix(fixer) {
|
|
return fixer.remove(node);
|
|
},
|
|
});
|
|
});
|
|
},
|
|
};
|
|
},
|
|
};
|