pi-lens
Version:
Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo
37 lines (36 loc) • 947 B
JavaScript
/**
* Shared utilities for runners
*/
import * as fs from "node:fs";
/**
* Read file content, returning undefined if it can't be read
*/
export function readFileContent(filePath) {
try {
return fs.readFileSync(filePath, "utf-8");
}
catch {
return undefined;
}
}
/**
* Parse common tool output line into a diagnostic
* Format: file:line:col message (category)
*/
export function parseToolLine(line, toolName, filePath) {
const match = line.match(/^(.+?):(\d+):(\d+)\s+(.+?)\s*\((.+?)\)/);
if (!match)
return null;
return {
id: `${toolName}-${match[2]}-${match[5]}`,
message: `${match[5]}: ${match[4]}`,
filePath,
line: parseInt(match[2], 10),
column: parseInt(match[3], 10),
severity: line.includes("error") ? "error" : "warning",
semantic: "warning",
tool: toolName,
rule: match[5],
fixable: false,
};
}