Skip to content

Commit

Permalink
refactor(no-container): rename function
Browse files Browse the repository at this point in the history
and change its scope
  • Loading branch information
thebinaryfelix committed Jun 20, 2020
1 parent 78fdfe7 commit 9812cf4
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions lib/rules/no-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,36 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({

create(context, [options]) {
const { renderFunctions } = options;
let hasPropertyContainer = false;
let containerName: string = null;
let renderWrapperName: string = null;
const destructuredContainerPropNames: string[] = [];
let renderWrapperName: string = null;
let containerName: string = null;
let containerCallsMethod = false;

function showErrorIfChainedContainerMethod(
innerNode: TSESTree.MemberExpression
) {
if (isMemberExpression(innerNode)) {
if (isIdentifier(innerNode.object)) {
const isContainerName = innerNode.object.name === containerName;
const isRenderWrapper = innerNode.object.name === renderWrapperName;

containerCallsMethod =
isIdentifier(innerNode.property) &&
innerNode.property.name === 'container' &&
isRenderWrapper;

if (isContainerName || containerCallsMethod) {
context.report({
node: innerNode,
messageId: 'noContainer',
});
}
}
showErrorIfChainedContainerMethod(
innerNode.object as TSESTree.MemberExpression
);
}
}

return {
VariableDeclarator(node) {
Expand Down Expand Up @@ -78,34 +104,8 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({
},

CallExpression(node: TSESTree.CallExpression) {
function showErrorForChainedContainerMethod(
innerNode: TSESTree.MemberExpression
) {
if (isMemberExpression(innerNode)) {
if (isIdentifier(innerNode.object)) {
const isContainerName = innerNode.object.name === containerName;
const isRenderWrapper =
innerNode.object.name === renderWrapperName;

hasPropertyContainer =
isIdentifier(innerNode.property) &&
innerNode.property.name === 'container' &&
isRenderWrapper;

if (isContainerName || hasPropertyContainer) {
context.report({
node: innerNode,
messageId: 'noContainer',
});
}
}
showErrorForChainedContainerMethod(
innerNode.object as TSESTree.MemberExpression
);
}
}
if (isMemberExpression(node.callee)) {
showErrorForChainedContainerMethod(node.callee);
showErrorIfChainedContainerMethod(node.callee);
} else if (isIdentifier(node.callee)) {
destructuredContainerPropNames.includes(node.callee.name) &&
context.report({
Expand Down

0 comments on commit 9812cf4

Please sign in to comment.