How to use the @fimbul/ymir.Finding.compare function in @fimbul/ymir

To help you get started, we’ve selected a few @fimbul/ymir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fimbullinter / wotan / packages / wotan / src / baseline.ts View on Github external
export function createBaseline(summary: FileSummary): string {
    if (summary.findings.length === 0)
        return summary.content;

    const findings = summary.findings.slice().sort(Finding.compare);
    const lines: string[] = [];
    let lineStart = 0;
    let findingPosition = 0;
    let pendingFindings: Finding[] = [];
    for (const line of summary.content.split(/\n/g)) {
        lines.push(line);
        const nextLineStart = lineStart + line.length + 1;
        const lineLength = line.length - (line.endsWith('\r') ? 1 : 0);
        const pending: Finding[] = [];
        for (const finding of pendingFindings)
            lines.push(formatFinding(finding, lineStart, lineLength, nextLineStart, pending));
        pendingFindings = pending;

        for (; findingPosition < findings.length && findings[findingPosition].start.position < nextLineStart; ++findingPosition)
            lines.push(formatFinding(findings[findingPosition], lineStart, lineLength, nextLineStart, pendingFindings));