Skip to content

Commit cf249f5

Browse files
committed
fix(linter/plugins): fix message interpolation (#16300)
Use the same RegExp as ESLint does.
1 parent f5bb8e4 commit cf249f5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

apps/oxlint/src-js/plugins/report.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ interface DiagnosticReport {
6262
// Diagnostics array. Reused for every file.
6363
export const diagnostics: DiagnosticReport[] = [];
6464

65+
// Regex for message placeholders.
66+
// https://github.com/eslint/eslint/blob/772c9ee9b65b6ad0be3e46462a7f93c37578cfa8/lib/linter/interpolate.js#L16-L18
67+
const PLACEHOLDER_REGEX = /\{\{([^{}]+)\}\}/gu;
68+
6569
/**
6670
* Report error.
6771
* @param diagnostic - Diagnostic object
@@ -78,10 +82,12 @@ export function report(diagnostic: Diagnostic, ruleDetails: RuleDetails): void {
7882
if (hasOwn(diagnostic, "data")) {
7983
const { data } = diagnostic;
8084
if (data != null) {
81-
message = message.replace(/\{\{([^}]+)\}\}/g, (match, key) => {
85+
message = message.replace(PLACEHOLDER_REGEX, (match, key) => {
8286
key = key.trim();
8387
const value = data[key];
84-
return value !== undefined ? String(value) : match;
88+
// TS type def for `string.replace` callback is `(substring: string, ...args: any[]) => string`,
89+
// but actually returning other types e.g. `number` or `boolean` is fine
90+
return value !== undefined ? (value as string) : match;
8591
});
8692
}
8793
}

0 commit comments

Comments
 (0)