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.
72 lines
2.1 KiB
JavaScript
72 lines
2.1 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 tsEstree = require('@typescript-eslint/typescript-estree');
|
|
const esTypes = tsEstree.AST_NODE_TYPES;
|
|
|
|
/** @typedef {import("eslint").Rule.RuleModule} Rule */
|
|
/** @typedef {import("@typescript-eslint/typescript-estree").TSESTree.Node} Node */
|
|
/** @typedef {import("@typescript-eslint/typescript-estree").TSESTree.CallExpression} CallExpression */
|
|
/** @typedef {import("@typescript-eslint/typescript-estree").TSESTree.CallExpression} VariableDeclarator */
|
|
|
|
const ERROR_MSG = 'Unexpected unsafeConsole statement.';
|
|
|
|
/**
|
|
* @param {CallExpression} node
|
|
*/
|
|
const isUnsafeConsoleCall = (node) => {
|
|
return (
|
|
node.callee.type === esTypes.MemberExpression &&
|
|
node.callee.property.type === esTypes.Identifier &&
|
|
node.callee.object.name === 'unsafeConsole' &&
|
|
node.callee.property.name
|
|
);
|
|
};
|
|
|
|
/**
|
|
* @param {VariableDeclarator} node
|
|
*/
|
|
const isUnsafeConsoleObjectPatternDeclarator = (node) => {
|
|
return (
|
|
node.id.type === esTypes.ObjectPattern &&
|
|
node.init &&
|
|
node.init.type === esTypes.Identifier &&
|
|
node.init.name === 'unsafeConsole'
|
|
);
|
|
};
|
|
|
|
/** @type {Rule} */
|
|
module.exports = {
|
|
meta: {
|
|
fixable: 'code',
|
|
schema: [],
|
|
},
|
|
create: (context) => ({
|
|
CallExpression(_) {
|
|
const node = /** @type {CallExpression} */ (_);
|
|
|
|
if (isUnsafeConsoleCall(node)) {
|
|
context.report({
|
|
message: ERROR_MSG,
|
|
loc: node.callee.loc,
|
|
});
|
|
}
|
|
},
|
|
VariableDeclarator(_) {
|
|
const node = /** @type {VariableDeclarator} */ (_);
|
|
|
|
if (isUnsafeConsoleObjectPatternDeclarator(node)) {
|
|
context.report({
|
|
message: ERROR_MSG,
|
|
loc: node.init.loc,
|
|
});
|
|
}
|
|
},
|
|
}),
|
|
};
|