mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
factor common code into display_underlined
This commit is contained in:
committed by
=Michael Hohn
parent
f5bb156c8c
commit
90758f769f
@@ -37,14 +37,7 @@ for runi in S.indices(sarif_struct, 'runs'):
|
|||||||
if args.list_source:
|
if args.list_source:
|
||||||
lines = S.load_lines(args.list_source, artifact['uri'], l1, l2)
|
lines = S.load_lines(args.list_source, artifact['uri'], l1, l2)
|
||||||
for line, line_num in zip(lines, range(l1, l2+1)):
|
for line, line_num in zip(lines, range(l1, l2+1)):
|
||||||
# Display the line
|
S.display_underlined(l1, c1, l2, c2, line, line_num)
|
||||||
S.msg("%s" % (line))
|
|
||||||
S.msg("\n")
|
|
||||||
# Print the underline
|
|
||||||
underline = S.underline_for_result(l1, c1, l2, c2, line, line_num)
|
|
||||||
S.msg(underline)
|
|
||||||
# Next result
|
|
||||||
S.msg("\n")
|
|
||||||
if args.related_locations:
|
if args.related_locations:
|
||||||
# Full path: S.get(sarif_struct, 'runs', runi, 'results', resi, 'relatedLocations')
|
# Full path: S.get(sarif_struct, 'runs', runi, 'results', resi, 'relatedLocations')
|
||||||
relatedLocations = results.get('relatedLocations', None)
|
relatedLocations = results.get('relatedLocations', None)
|
||||||
@@ -60,12 +53,5 @@ for runi in S.indices(sarif_struct, 'runs'):
|
|||||||
if args.list_source:
|
if args.list_source:
|
||||||
lines = S.load_lines(args.list_source, artifact['uri'], l1, l2)
|
lines = S.load_lines(args.list_source, artifact['uri'], l1, l2)
|
||||||
for line, line_num in zip(lines, range(l1, l2+1)):
|
for line, line_num in zip(lines, range(l1, l2+1)):
|
||||||
# Display the line
|
S.display_underlined(l1, c1, l2, c2, line, line_num)
|
||||||
S.msg("%s" % (line))
|
|
||||||
S.msg("\n")
|
|
||||||
# Print the underline
|
|
||||||
underline = S.underline_for_result(l1, c1, l2, c2, line, line_num)
|
|
||||||
S.msg(underline)
|
|
||||||
# Next result
|
|
||||||
S.msg("\n")
|
|
||||||
S.msg("\n")
|
S.msg("\n")
|
||||||
|
|||||||
@@ -6,6 +6,22 @@ MIN_PYTHON = (3, 7)
|
|||||||
if sys.version_info < MIN_PYTHON:
|
if sys.version_info < MIN_PYTHON:
|
||||||
sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
|
sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON)
|
||||||
|
|
||||||
|
def display_underlined(l1, c1, l2, c2, line, line_num):
|
||||||
|
""" Display the given line followed by a second line with underscores at the locations.
|
||||||
|
|
||||||
|
l1, c1, l2, c2: the line/column range
|
||||||
|
line: the line of text
|
||||||
|
line_num: the line number for the text, used with the line/column range
|
||||||
|
"""
|
||||||
|
# Display the line
|
||||||
|
msg("%s" % (line))
|
||||||
|
msg("\n")
|
||||||
|
# Print the underline
|
||||||
|
underline = underline_for_result(l1, c1, l2, c2, line, line_num)
|
||||||
|
msg(underline)
|
||||||
|
# Next result
|
||||||
|
msg("\n")
|
||||||
|
|
||||||
def underline_for_result(first_line, first_column, last_line, last_column, line, line_num):
|
def underline_for_result(first_line, first_column, last_line, last_column, line, line_num):
|
||||||
"""Provide the underline for a result line.
|
"""Provide the underline for a result line.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user