@@ -56,7 +56,7 @@ const rule: Rule.RuleModule = {
56
56
contextIdentifiers = getContextIdentifiers ( scopeManager , ast ) ;
57
57
} ,
58
58
59
- 'Program:exit' ( ast ) {
59
+ 'Program:exit' ( ) {
60
60
if ( hasSeenUnknownMessageId || ! hasSeenViolationReport ) {
61
61
/*
62
62
Bail out when the rule is likely to have false positives.
@@ -107,21 +107,21 @@ const rule: Rule.RuleModule = {
107
107
const values =
108
108
messageId . type === 'Literal'
109
109
? [ messageId ]
110
- : findPossibleVariableValues (
111
- messageId as Identifier ,
112
- scopeManager ,
113
- ) ;
110
+ : messageId . type === 'Identifier'
111
+ ? findPossibleVariableValues ( messageId , scopeManager )
112
+ : [ ] ;
114
113
if (
115
114
values . length === 0 ||
116
115
values . some ( ( val ) => val . type !== 'Literal' )
117
116
) {
118
117
// When a dynamic messageId is used and we can't detect its value, disable the rule to avoid false positives.
119
118
hasSeenUnknownMessageId = true ;
120
119
}
121
- values . forEach (
122
- ( val ) =>
123
- 'value' in val && messageIdsUsed . add ( val . value as string ) ,
124
- ) ;
120
+ values
121
+ . filter ( ( value ) => value . type === 'Literal' )
122
+ . map ( ( value ) => value . value )
123
+ . filter ( ( value ) => typeof value === 'string' )
124
+ . forEach ( ( value ) => messageIdsUsed . add ( value ) ) ;
125
125
}
126
126
}
127
127
} ,
@@ -143,15 +143,18 @@ const rule: Rule.RuleModule = {
143
143
if (
144
144
values . length === 0 ||
145
145
values . some ( ( val ) => val . type !== 'Literal' ) ||
146
- isVariableFromParameter ( node . value as Identifier , scopeManager )
146
+ ( node . value . type === 'Identifier' &&
147
+ isVariableFromParameter ( node . value , scopeManager ) )
147
148
) {
148
149
// When a dynamic messageId is used and we can't detect its value, disable the rule to avoid false positives.
149
150
hasSeenUnknownMessageId = true ;
150
151
}
151
152
152
- values . forEach (
153
- ( val ) => 'value' in val && messageIdsUsed . add ( val . value as string ) ,
154
- ) ;
153
+ values
154
+ . filter ( ( val ) => val . type === 'Literal' )
155
+ . map ( ( val ) => val . value )
156
+ . filter ( ( val ) => typeof val === 'string' )
157
+ . forEach ( ( val ) => messageIdsUsed . add ( val ) ) ;
155
158
}
156
159
} ,
157
160
} ;
0 commit comments