Skip to content

Commit 4b6b8c3

Browse files
committed
fix line number highlighting
1 parent 4f4aaef commit 4b6b8c3

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

cycode/cli/apps/scan/commit_range_scanner.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,13 @@ def _scan_commit_range_documents(
126126
progress_bar.update(ScanProgressBarSection.SCAN)
127127
progress_bar.set_section_length(ScanProgressBarSection.GENERATE_REPORT, 1)
128128

129+
documents_to_scan = to_documents_to_scan
130+
if scan_type == consts.SAST_SCAN_TYPE:
131+
# actually for SAST from_documents_to_scan is full files and to_documents_to_scan is diff files
132+
documents_to_scan = from_documents_to_scan
133+
129134
local_scan_result = create_local_scan_result(
130-
scan_result, to_documents_to_scan, scan_command_type, scan_type, severity_threshold
135+
scan_result, documents_to_scan, scan_command_type, scan_type, severity_threshold
131136
)
132137
set_issue_detected_by_scan_results(ctx, [local_scan_result])
133138

cycode/cli/printers/utils/code_snippet_syntax.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ def get_detection_line(scan_type: str, detection: 'Detection') -> int:
2525
)
2626

2727

28+
def _get_syntax_highlighted_code(code: str, lexer: str, start_line: int, detection_line: int) -> Syntax:
29+
return Syntax(
30+
theme=_SYNTAX_HIGHLIGHT_THEME,
31+
code=code,
32+
lexer=lexer,
33+
line_numbers=True,
34+
word_wrap=True,
35+
dedent=True,
36+
tab_size=2,
37+
start_line=start_line + 1,
38+
highlight_lines={detection_line + 1},
39+
)
40+
41+
2842
def _get_code_snippet_syntax_from_file(
2943
scan_type: str,
3044
detection: 'Detection',
@@ -58,18 +72,11 @@ def _get_code_snippet_syntax_from_file(
5872
code_lines_to_render.append(line_content)
5973

6074
code_to_render = '\n'.join(code_lines_to_render)
61-
return Syntax(
62-
theme=_SYNTAX_HIGHLIGHT_THEME,
75+
return _get_syntax_highlighted_code(
6376
code=code_to_render,
6477
lexer=Syntax.guess_lexer(document.path, code=code_to_render),
65-
line_numbers=True,
66-
word_wrap=True,
67-
dedent=True,
68-
tab_size=2,
69-
start_line=start_line_index + 1,
70-
highlight_lines={
71-
detection_line + 1,
72-
},
78+
start_line=start_line_index,
79+
detection_line=detection_line,
7380
)
7481

7582

@@ -87,15 +94,11 @@ def _get_code_snippet_syntax_from_git_diff(
8794
violation = line_content[detection_position_in_line : detection_position_in_line + violation_length]
8895
line_content = line_content.replace(violation, obfuscate_text(violation))
8996

90-
return Syntax(
91-
theme=_SYNTAX_HIGHLIGHT_THEME,
97+
return _get_syntax_highlighted_code(
9298
code=line_content,
9399
lexer='diff',
94-
line_numbers=True,
95100
start_line=detection_line,
96-
dedent=True,
97-
tab_size=2,
98-
highlight_lines={detection_line + 1},
101+
detection_line=detection_line,
99102
)
100103

101104

0 commit comments

Comments
 (0)