Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/engineImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ function runOxlint(
try {
const parsed = JSON.parse((result.stdout ?? "").trim()) as OxlintOutput;
return { diagnostics: parsed.diagnostics ?? [] };
} catch {
// Failed to parse: this is a real error
const errorMsg = result.stderr || `Exit code ${result.status}`;
return { diagnostics: [], error: `Failed to parse oxlint output: ${errorMsg.slice(0, 500)}` };
} catch (parseErr) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ LOW RISK

Suggestion: The 'parseErr' variable is declared but never used in the catch block. You can simplify this by using an optional catch binding.

Suggested change
} catch (parseErr) {
} catch {

// Failed to parse JSON output
const stderr = result.stderr?.slice(0, 200) || "";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚪ LOW RISK

Suggestion: Trimming 'result.stderr' ensures that the fallback message containing the exit code is used if the stderr output is empty or only contains whitespace.

Suggested change
const stderr = result.stderr?.slice(0, 200) || "";
const stderr = result.stderr?.trim().slice(0, 200) || "";

const reason = stderr || `oxlint exited with code ${result.status}`;
return { diagnostics: [], error: `Failed to parse oxlint output: ${reason}` };
}
}

Expand Down Expand Up @@ -204,6 +205,11 @@ export async function engineImpl(rc: CodacyRc | undefined): Promise<void> {
}

for (const diag of diagnostics) {
if (!diag.code) {
process.stderr.write(`[codacy-oxlint] Warning: Skipping issue in ${diag.filename}:${getLine(diag)} - missing rule code\n`);
continue;
}

const issue: CodacyIssue = {
filename: diag.filename.startsWith(SOURCE_DIR)
? diag.filename.slice(SOURCE_DIR.length + 1)
Expand Down