@@ -35,7 +35,7 @@ export default createRule<[], MessageID>({
3535 create ( context ) {
3636 const { ctx, listeners } = useComponentCollector ( context ) ;
3737 const detectConstruction = constructionDetector ( context ) ;
38- const possibleValueConstructions = new Map < TSESTreeFunction , ERConstruction > ( ) ;
38+ const possibleValueConstructions = new Map < TSESTreeFunction , ERConstruction [ ] > ( ) ;
3939
4040 return {
4141 ...listeners ,
@@ -55,30 +55,34 @@ export default createRule<[], MessageID>({
5555 const valueExpression = valueNode . expression ;
5656 const constructionDetail = detectConstruction ( valueExpression ) ;
5757 if ( constructionDetail . _tag === "None" ) return ;
58- O . map ( ctx . getCurrentFunction ( ) , ( [ currentFn ] ) => possibleValueConstructions . set ( currentFn , constructionDetail ) ) ;
58+ O . map (
59+ ctx . getCurrentFunction ( ) ,
60+ ( [ currentFn ] ) =>
61+ possibleValueConstructions . set ( currentFn , [
62+ ...possibleValueConstructions . get ( currentFn ) ?? [ ] ,
63+ constructionDetail ,
64+ ] ) ,
65+ ) ;
5966 } ,
6067 "Program:exit" ( node ) {
6168 const components = Array . from ( ctx . getAllComponents ( node ) . values ( ) ) ;
62- for ( const [ fn , detail ] of possibleValueConstructions . entries ( ) ) {
63- if (
64- ! components . some ( ( component ) => component . node === fn )
65- || detail . _tag === "None"
66- ) {
67- continue ;
69+ for ( const { node : component } of components ) {
70+ const constructions = possibleValueConstructions . get ( component ) ;
71+ if ( ! constructions ) continue ;
72+ for ( const construction of constructions ) {
73+ if ( construction . _tag === "None" ) continue ;
74+ const { _tag, node : constructionNode } = construction ;
75+ const messageId = _tag . startsWith ( "Function" )
76+ ? "NO_CONSTRUCTED_CONTEXT_VALUE_WITH_FUNCTION"
77+ : "NO_CONSTRUCTED_CONTEXT_VALUE_WITH_IDENTIFIER" ;
78+ context . report ( {
79+ node : constructionNode ,
80+ messageId,
81+ data : {
82+ type : constructionNode . type ,
83+ } ,
84+ } ) ;
6885 }
69-
70- const messageId = detail . _tag . startsWith ( "Function" )
71- ? "NO_CONSTRUCTED_CONTEXT_VALUE_WITH_FUNCTION"
72- : "NO_CONSTRUCTED_CONTEXT_VALUE_WITH_IDENTIFIER" ;
73- const { _tag, node } = detail ;
74-
75- context . report ( {
76- data : {
77- type : _tag . replaceAll ( "_" , "" ) . toLowerCase ( ) ,
78- } ,
79- messageId,
80- node,
81- } ) ;
8286 }
8387 } ,
8488 } ;
0 commit comments