core/parsers/tool.phpcs.parser.ts

core/parsers/tool.phpcs.parser.ts is a file in GovLab Quality. 22 lines of code and 2 definitions.

import { boolField, numberField, recordsAt, stringField } from "#core/selectors/record.selector";
import type { Finding } from "#types/finding.types";
import { POSITION } from "#configuration/constants/tool.constants";
import { objectEntriesAt } from "#core/parsers/record.parser";
import { toolFinding } from "#core/factories/finding.factory";

const TOOL = "phpcs";

export const parsePhpcsOutput = function parsePhpcsOutput(stdout: string, ecosystem: string): Finding[] {
    return objectEntriesAt(stdout || "{}", "files").flatMap(([filePath, file]) =>
        recordsAt(file, "messages").map((message) =>
            toolFinding({
                column: numberField(message, "column", POSITION),
                ecosystem,
                file: filePath,
                fixable: boolField(message, "fixable"),
                line: numberField(message, "line", POSITION),
                message: stringField(message, "message"),
                ruleId: stringField(message, "source", TOOL),
                tool: TOOL,
            }),
        ),
    );
};