@@ -43,10 +43,36 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({
4343
4444 create ( context , [ options ] ) {
4545 const { renderFunctions } = options ;
46- let hasPropertyContainer = false ;
47- let containerName : string = null ;
48- let renderWrapperName : string = null ;
4946 const destructuredContainerPropNames : string [ ] = [ ] ;
47+ let renderWrapperName : string = null ;
48+ let containerName : string = null ;
49+ let containerCallsMethod = false ;
50+
51+ function showErrorIfChainedContainerMethod (
52+ innerNode : TSESTree . MemberExpression
53+ ) {
54+ if ( isMemberExpression ( innerNode ) ) {
55+ if ( isIdentifier ( innerNode . object ) ) {
56+ const isContainerName = innerNode . object . name === containerName ;
57+ const isRenderWrapper = innerNode . object . name === renderWrapperName ;
58+
59+ containerCallsMethod =
60+ isIdentifier ( innerNode . property ) &&
61+ innerNode . property . name === 'container' &&
62+ isRenderWrapper ;
63+
64+ if ( isContainerName || containerCallsMethod ) {
65+ context . report ( {
66+ node : innerNode ,
67+ messageId : 'noContainer' ,
68+ } ) ;
69+ }
70+ }
71+ showErrorIfChainedContainerMethod (
72+ innerNode . object as TSESTree . MemberExpression
73+ ) ;
74+ }
75+ }
5076
5177 return {
5278 VariableDeclarator ( node ) {
@@ -78,34 +104,8 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({
78104 } ,
79105
80106 CallExpression ( node : TSESTree . CallExpression ) {
81- function showErrorForChainedContainerMethod (
82- innerNode : TSESTree . MemberExpression
83- ) {
84- if ( isMemberExpression ( innerNode ) ) {
85- if ( isIdentifier ( innerNode . object ) ) {
86- const isContainerName = innerNode . object . name === containerName ;
87- const isRenderWrapper =
88- innerNode . object . name === renderWrapperName ;
89-
90- hasPropertyContainer =
91- isIdentifier ( innerNode . property ) &&
92- innerNode . property . name === 'container' &&
93- isRenderWrapper ;
94-
95- if ( isContainerName || hasPropertyContainer ) {
96- context . report ( {
97- node : innerNode ,
98- messageId : 'noContainer' ,
99- } ) ;
100- }
101- }
102- showErrorForChainedContainerMethod (
103- innerNode . object as TSESTree . MemberExpression
104- ) ;
105- }
106- }
107107 if ( isMemberExpression ( node . callee ) ) {
108- showErrorForChainedContainerMethod ( node . callee ) ;
108+ showErrorIfChainedContainerMethod ( node . callee ) ;
109109 } else if ( isIdentifier ( node . callee ) ) {
110110 destructuredContainerPropNames . includes ( node . callee . name ) &&
111111 context . report ( {
0 commit comments