react/scripts/eslint-rules/no-to-warn-dev-within-to-throw.js
Michaël De Boey b394c38e88
feat(eslint-plugin-react-internal): support ESLint 8.x (#22249)
Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2021-09-06 20:42:40 +01:00

42 lines
980 B
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/
'use strict';
module.exports = {
meta: {
schema: [],
},
create(context) {
return {
Identifier(node) {
if (node.name === 'toWarnDev' || node.name === 'toErrorDev') {
let current = node;
while (current.parent) {
if (current.type === 'CallExpression') {
if (
current &&
current.callee &&
current.callee.property &&
current.callee.property.name === 'toThrow'
) {
context.report(
node,
node.name + '() matcher should not be nested'
);
}
}
current = current.parent;
}
}
},
};
},
};