@@ -35,7 +35,7 @@ export default createRule<[], MessageID>({
35
35
create ( context ) {
36
36
const { ctx, listeners } = useComponentCollector ( context ) ;
37
37
const detectConstruction = constructionDetector ( context ) ;
38
- const possibleValueConstructions = new Map < TSESTreeFunction , ERConstruction > ( ) ;
38
+ const possibleValueConstructions = new Map < TSESTreeFunction , ERConstruction [ ] > ( ) ;
39
39
40
40
return {
41
41
...listeners ,
@@ -55,30 +55,34 @@ export default createRule<[], MessageID>({
55
55
const valueExpression = valueNode . expression ;
56
56
const constructionDetail = detectConstruction ( valueExpression ) ;
57
57
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
+ ) ;
59
66
} ,
60
67
"Program:exit" ( node ) {
61
68
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
+ } ) ;
68
85
}
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
- } ) ;
82
86
}
83
87
} ,
84
88
} ;
0 commit comments