Skip to content

Commit d91a0af

Browse files
committed
remove casting from no-unused-message-ids
1 parent ead0948 commit d91a0af

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

lib/rules/no-unused-message-ids.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const rule: Rule.RuleModule = {
5656
contextIdentifiers = getContextIdentifiers(scopeManager, ast);
5757
},
5858

59-
'Program:exit'(ast) {
59+
'Program:exit'() {
6060
if (hasSeenUnknownMessageId || !hasSeenViolationReport) {
6161
/*
6262
Bail out when the rule is likely to have false positives.
@@ -107,21 +107,21 @@ const rule: Rule.RuleModule = {
107107
const values =
108108
messageId.type === 'Literal'
109109
? [messageId]
110-
: findPossibleVariableValues(
111-
messageId as Identifier,
112-
scopeManager,
113-
);
110+
: messageId.type === 'Identifier'
111+
? findPossibleVariableValues(messageId, scopeManager)
112+
: [];
114113
if (
115114
values.length === 0 ||
116115
values.some((val) => val.type !== 'Literal')
117116
) {
118117
// When a dynamic messageId is used and we can't detect its value, disable the rule to avoid false positives.
119118
hasSeenUnknownMessageId = true;
120119
}
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));
125125
}
126126
}
127127
},
@@ -143,15 +143,18 @@ const rule: Rule.RuleModule = {
143143
if (
144144
values.length === 0 ||
145145
values.some((val) => val.type !== 'Literal') ||
146-
isVariableFromParameter(node.value as Identifier, scopeManager)
146+
(node.value.type === 'Identifier' &&
147+
isVariableFromParameter(node.value, scopeManager))
147148
) {
148149
// When a dynamic messageId is used and we can't detect its value, disable the rule to avoid false positives.
149150
hasSeenUnknownMessageId = true;
150151
}
151152

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));
155158
}
156159
},
157160
};

0 commit comments

Comments
 (0)