From 1aa240948860af7f42482b3223c49c84f0b09304 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 3 Dec 2025 13:28:35 +0000 Subject: [PATCH] perf(linter/plugins): do not remove `messageId` field from `DiagnosticReport` before sending to Rust (#16442) As @camc314 pointed out in https://github.com/oxc-project/oxc/pull/16296#pullrequestreview-3524629951: It's probably cheaper to leave the `messageId` field present in the JSON sent over to Rust and let `serde` handle skipping it, than to loop through all the diagnostics on JS side to remove it. `RuleTester` should be moved into a separate NPM package (#16018), at which point we can do a different build for that package, and not have `messageId` stored in `DiagnosticReport` in the first place in the main build. So then this issue will become moot. --- apps/oxlint/src-js/plugins/lint.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/oxlint/src-js/plugins/lint.ts b/apps/oxlint/src-js/plugins/lint.ts index acf164e085202..fad5306da9961 100644 --- a/apps/oxlint/src-js/plugins/lint.ts +++ b/apps/oxlint/src-js/plugins/lint.ts @@ -22,8 +22,6 @@ import { walkProgram } from '../generated/walk.js'; // @ts-expect-error we need to generate `.d.ts` file for this module import { walkProgram } from "../generated/walk.js"; -import type { SetOptional } from "type-fest"; -import type { DiagnosticReport } from "../plugins/report.ts"; import type { AfterHook, BufferWithArrays } from "./types.ts"; // Buffers cache. @@ -63,11 +61,8 @@ export function lintFile( try { lintFileImpl(filePath, bufferId, buffer, ruleIds, optionsIds, settingsJSON); - // Remove `messageId` field from diagnostics. It's not needed on Rust side. - for (let i = 0, len = diagnostics.length; i < len; i++) { - (diagnostics[i] as SetOptional).messageId = undefined; - } - + // Note: `messageId` field of `DiagnosticReport` is not needed on Rust side, but we assume it's cheaper to leave it + // in place and let `serde` skip over it on Rust side, than to iterate over all diagnostics and remove it here. return JSON.stringify({ Success: diagnostics }); } catch (err) { return JSON.stringify({ Failure: getErrorMessage(err) });