Skip to content

Commit 464a49b

Browse files
committed
perf(linter/plugins): avoid private methods
1 parent 95a15bf commit 464a49b

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

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

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class Context {
162162
let message: string;
163163
if (hasOwn(diagnostic, 'messageId')) {
164164
const diagWithMessageId = diagnostic as DiagnosticWithMessageId;
165-
message = this.#resolveMessage(diagWithMessageId.messageId, diagWithMessageId.data, internal);
165+
message = resolveMessage(diagWithMessageId.messageId, diagWithMessageId.data, internal);
166166
} else {
167167
message = diagnostic.message;
168168
if (typeof message !== 'string') {
@@ -212,47 +212,6 @@ export class Context {
212212
});
213213
}
214214

215-
/**
216-
* Resolve a messageId to its message string, with optional data interpolation.
217-
* @param messageId - The message ID to resolve
218-
* @param data - Optional data for placeholder interpolation
219-
* @param internal - Internal context containing messages
220-
* @returns Resolved message string
221-
* @throws {Error} If messageId is not found in messages
222-
*/
223-
#resolveMessage(
224-
messageId: string,
225-
data: Record<string, string | number> | undefined,
226-
internal: InternalContext,
227-
): string {
228-
const { messages } = internal;
229-
230-
if (!messages) {
231-
throw new Error(`Cannot use messageId '${messageId}' - rule does not define any messages in meta.messages`);
232-
}
233-
234-
if (!hasOwn(messages, messageId)) {
235-
throw new Error(
236-
`Unknown messageId '${messageId}'. Available messages: ${
237-
Object.keys(messages).map((msg) => `'${msg}'`).join(', ')
238-
}`,
239-
);
240-
}
241-
242-
let message = messages[messageId];
243-
244-
// Interpolate placeholders {{key}} with data values
245-
if (data) {
246-
message = message.replace(/\{\{([^}]+)\}\}/g, (match, key) => {
247-
key = key.trim();
248-
const value = data[key];
249-
return value !== undefined ? String(value) : match;
250-
});
251-
}
252-
253-
return message;
254-
}
255-
256215
static {
257216
setupContextForFile = (context, ruleIndex, filePath) => {
258217
// TODO: Support `options`
@@ -268,3 +227,44 @@ export class Context {
268227
};
269228
}
270229
}
230+
231+
/**
232+
* Resolve a message ID to its message string, with optional data interpolation.
233+
* @param messageId - The message ID to resolve
234+
* @param data - Optional data for placeholder interpolation
235+
* @param internal - Internal context containing messages
236+
* @returns Resolved message string
237+
* @throws {Error} If `messageId` is not found in `messages`
238+
*/
239+
function resolveMessage(
240+
messageId: string,
241+
data: Record<string, string | number> | undefined,
242+
internal: InternalContext,
243+
): string {
244+
const { messages } = internal;
245+
246+
if (!messages) {
247+
throw new Error(`Cannot use messageId '${messageId}' - rule does not define any messages in meta.messages`);
248+
}
249+
250+
if (!hasOwn(messages, messageId)) {
251+
throw new Error(
252+
`Unknown messageId '${messageId}'. Available messages: ${
253+
Object.keys(messages).map((msg) => `'${msg}'`).join(', ')
254+
}`,
255+
);
256+
}
257+
258+
let message = messages[messageId];
259+
260+
// Interpolate placeholders {{key}} with data values
261+
if (data) {
262+
message = message.replace(/\{\{([^}]+)\}\}/g, (match, key) => {
263+
key = key.trim();
264+
const value = data[key];
265+
return value !== undefined ? String(value) : match;
266+
});
267+
}
268+
269+
return message;
270+
}

0 commit comments

Comments
 (0)