Skip to content

Commit b82902b

Browse files
Use word boundary for formatMessage in i18n pre-filter regex !! (elastic#268098)
## Summary Follow-up to elastic#265954 ([review comment](elastic#265954 (comment))). Changes `.formatMessage(` to `\bformatMessage(` in the `I18N_CALL_PATTERN` regex so the pre-filter also catches destructured standalone `formatMessage()` calls (e.g. `const { formatMessage } = intl; formatMessage(...)`), matching the same word-boundary pattern already used for `\btranslate(`. The dot-prefix worked today because no code in the repo destructures `formatMessage`, but `\b` is strictly more defensive — false positives (extra files processed) are harmless, while false negatives (missing translations) are not. Adds a unit test for the destructured `formatMessage` pattern. ## Test plan - `node scripts/jest src/dev/i18n_tools/constants.test.ts` — all 12 tests pass - CI passes (i18n check step) Made with [Cursor](https://cursor.com) Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a35ceae commit b82902b

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

src/dev/i18n_tools/constants.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('I18N_CALL_PATTERN', () => {
1616
["i18n.translate('id', { defaultMessage: 'msg' })"],
1717
["I18n.translate('id', { defaultMessage: 'msg' })"],
1818
["intl.formatMessage({ id: 'id', defaultMessage: 'msg' })"],
19+
["const { formatMessage } = intl;\nformatMessage({ id: 'id', defaultMessage: 'msg' })"],
1920
['defineMessages({ id: { defaultMessage: "msg" } })'],
2021
["<FormattedMessage id='id' defaultMessage='msg' />"],
2122
["const { translate } = i18n;\ntranslate('id', { defaultMessage: 'msg' })"],

src/dev/i18n_tools/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ export const I18N_RC = '.i18nrc.json';
1717
* early, plus usage-pattern fallbacks for edge cases like re-exported i18n helpers.
1818
*/
1919
export const I18N_CALL_PATTERN =
20-
/@kbn\/i18n|\btranslate\(|FormattedMessage|defineMessages|\.formatMessage\(/;
20+
/@kbn\/i18n|\btranslate\(|FormattedMessage|defineMessages|\bformatMessage\(/;

0 commit comments

Comments
 (0)