Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions .changeset/orange-foxes-shine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"layne": patch
---

fix(semgrep): capture end.line so multi-line findings span the full annotation range

Semgrep emits both `start.line` and `end.line` in its JSON output, but
the adapter only read `start.line` and left `startLine`/`endLine` unset.
Every Semgrep annotation therefore collapsed to a single line even for
rules that match multi-line constructs (e.g. multi-line function calls,
object literals, imports). Added `end?: { line: number }` to the raw
result interface and populate `startLine`/`endLine` in `toFinding`.
Falls back to `startLine` when `end` is absent.
25 changes: 25 additions & 0 deletions src/__tests__/adapters/semgrep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,29 @@ describe('runSemgrep()', () => {
const jsonIdx = args.indexOf('--json');
expect(jsonIdx).toBe(scanIdx + 1);
});

describe('startLine / endLine from Semgrep end.line', () => {
it('sets startLine and endLine from start.line and end.line on a single-line finding', async () => {
stubStdout(semgrepOutput([SEMGREP_RESULT]));
const [f] = await runSemgrep({ workspacePath: '/tmp/ws', changedFiles: CHANGED_FILES });
expect(f.startLine).toBe(10);
expect(f.endLine).toBe(10);
});

it('sets startLine and endLine from start.line and end.line on a multi-line finding', async () => {
const multiLine = { ...SEMGREP_RESULT, start: { line: 10, col: 1 }, end: { line: 14, col: 1 } };
stubStdout(semgrepOutput([multiLine]));
const [f] = await runSemgrep({ workspacePath: '/tmp/ws', changedFiles: CHANGED_FILES });
expect(f.startLine).toBe(10);
expect(f.endLine).toBe(14);
});

it('falls back endLine to startLine when end is missing from Semgrep output', async () => {
const noEnd = { check_id: SEMGREP_RESULT.check_id, path: SEMGREP_RESULT.path, start: { line: 7 }, extra: SEMGREP_RESULT.extra };
stubStdout(semgrepOutput([noEnd]));
const [f] = await runSemgrep({ workspacePath: '/tmp/ws', changedFiles: CHANGED_FILES });
expect(f.startLine).toBe(7);
expect(f.endLine).toBe(7);
});
});
});
17 changes: 11 additions & 6 deletions src/adapters/semgrep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface SemgrepRawResult {
check_id: string;
path: string;
start?: { line: number };
end?: { line: number };
extra?: { severity?: string; message?: string };
}

Expand All @@ -69,12 +70,16 @@ const SEVERITY_MAP: Record<string, Severity> = {
};

function toFinding(result: SemgrepRawResult, workspacePath: string): SemgrepFinding {
const startLine = result.start?.line ?? 1;
const endLine = result.end?.line ?? startLine;
return {
file: stripPrefix(result.path, workspacePath),
line: result.start?.line ?? 1,
severity: SEVERITY_MAP[result.extra?.severity ?? ''] ?? 'low',
message: result.extra?.message ?? 'Semgrep finding',
ruleId: result.check_id,
tool: 'semgrep',
file: stripPrefix(result.path, workspacePath),
line: startLine,
startLine,
endLine,
severity: SEVERITY_MAP[result.extra?.severity ?? ''] ?? 'low',
message: result.extra?.message ?? 'Semgrep finding',
ruleId: result.check_id,
tool: 'semgrep',
};
}
Loading