File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
apps/oxlint/src-js/plugins Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,10 @@ interface DiagnosticReport {
6262// Diagnostics array. Reused for every file.
6363export 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 }
You can’t perform that action at this time.
0 commit comments